From 945df12a6ecf89b02d3aa2cdba6119f152a247a7 Mon Sep 17 00:00:00 2001 From: terwer Date: Wed, 9 Aug 2023 18:45:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8F=91=E5=B8=83=E9=A6=96=E4=B8=AA?= =?UTF-8?q?=E7=A8=B3=E5=AE=9A=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/adaptors/api/base/CommonblogConfig.ts | 1 + src/adaptors/api/hexo/hexoConfig.ts | 4 +- src/adaptors/api/notion/notionConfig.ts | 1 + src/adaptors/api/yuque/yuqueConfig.ts | 1 + src/adaptors/index.ts | 90 ++++++++++++++- src/adaptors/web/base/CommonWebConfig.ts | 23 +++- src/adaptors/web/csdn/csdnConfig.ts | 6 +- src/adaptors/web/csdn/useCsdnWeb.ts | 6 +- src/adaptors/web/jianshu/JianshuConfig.ts | 6 +- src/adaptors/web/jianshu/useJianshuWeb.ts | 6 +- src/adaptors/web/juejin/JuejinConfig.ts | 6 +- src/adaptors/web/juejin/useJuejinWeb.ts | 6 +- src/adaptors/web/wechat/WechatConfig.ts | 6 +- src/adaptors/web/wechat/useWechatWeb.ts | 6 +- src/adaptors/web/zhihu/useZhihuWeb.ts | 9 +- src/adaptors/web/zhihu/zhihuConfig.ts | 12 +- src/adaptors/web/zhihu/zhihuPlaceholder.ts | 30 +++++ src/adaptors/web/zhihu/zhihuWebAdaptor.ts | 2 +- src/components/set/PublishSetting.vue | 105 +++++++++++------- .../singleplatform/SingleSettingIndex.vue | 4 +- .../singleplatform/base/CommonBlogSetting.vue | 29 ++++- .../{web => base}/CookieSetting.vue | 2 +- .../base/impl/CustomWebSetting.vue | 41 +++++++ .../commonblog/NotionSetting.vue | 3 - .../commonblog/YuqueSetting.vue | 3 - .../singleplatform/github/HexoSetting.vue | 3 - .../metaweblog/CnblogsSetting.vue | 4 - .../metaweblog/OthermetaSetting.vue | 3 - .../metaweblog/TypechoSetting.vue | 4 - .../metaweblog/WordpressSetting.vue | 4 - .../singleplatform/web/ZhihuSetting.vue | 50 +++++++++ src/composables/useSiyuanApi.ts | 3 +- 32 files changed, 388 insertions(+), 91 deletions(-) create mode 100644 src/adaptors/web/zhihu/zhihuPlaceholder.ts rename src/components/set/publish/singleplatform/{web => base}/CookieSetting.vue (99%) create mode 100644 src/components/set/publish/singleplatform/base/impl/CustomWebSetting.vue create mode 100644 src/components/set/publish/singleplatform/web/ZhihuSetting.vue diff --git a/src/adaptors/api/base/CommonblogConfig.ts b/src/adaptors/api/base/CommonblogConfig.ts index 2881830f..c848defd 100644 --- a/src/adaptors/api/base/CommonblogConfig.ts +++ b/src/adaptors/api/base/CommonblogConfig.ts @@ -151,5 +151,6 @@ export class CommonblogConfig extends BlogConfig { this.middlewareUrl = middlewareUrl this.usernameEnabled = false this.allowPreviewUrlChange = true + this.showTokenTip = false } } diff --git a/src/adaptors/api/hexo/hexoConfig.ts b/src/adaptors/api/hexo/hexoConfig.ts index c924f070..542c6060 100644 --- a/src/adaptors/api/hexo/hexoConfig.ts +++ b/src/adaptors/api/hexo/hexoConfig.ts @@ -46,8 +46,8 @@ class HexoConfig extends CommonGithubConfig { this.showTokenTip = true this.defaultPath = "source/_posts" this.previewUrl = "/[user]/[repo]/blob/[branch]/[docpath]" - // this.previewPostUrl = "/post/[postid].html" - // this.mdFilenameRule = "[slug].md" + this.previewPostUrl = "/post/[postid].html" + this.mdFilenameRule = "[slug].md" this.pageType = PageTypeEnum.Markdown this.passwordType = PasswordType.PasswordType_Token this.allowPreviewUrlChange = false diff --git a/src/adaptors/api/notion/notionConfig.ts b/src/adaptors/api/notion/notionConfig.ts index 5de4ad10..42c878b6 100644 --- a/src/adaptors/api/notion/notionConfig.ts +++ b/src/adaptors/api/notion/notionConfig.ts @@ -34,6 +34,7 @@ class NotionConfig extends CommonblogConfig { super("https://www.notion.so/", "https://api.notion.com/v1", "", password, middlewareUrl) this.tokenSettingUrl = "https://www.notion.so/my-integrations" + this.showTokenTip = true this.previewUrl = "/[postid]" this.pageType = PageTypeEnum.Markdown this.passwordType = PasswordType.PasswordType_Token diff --git a/src/adaptors/api/yuque/yuqueConfig.ts b/src/adaptors/api/yuque/yuqueConfig.ts index 0d8fbb4f..6c5112a6 100644 --- a/src/adaptors/api/yuque/yuqueConfig.ts +++ b/src/adaptors/api/yuque/yuqueConfig.ts @@ -34,6 +34,7 @@ class YuqueConfig extends CommonblogConfig { super("https://www.yuque.com/", "https://www.yuque.com/api/v2", username, password, middlewareUrl) this.tokenSettingUrl = "https://www.yuque.com/settings/tokens" + this.showTokenTip = true this.previewUrl = "/[notebook]/[postid]" this.pageType = PageTypeEnum.Markdown this.usernameEnabled = true diff --git a/src/adaptors/index.ts b/src/adaptors/index.ts index 29a4dcdd..94464eec 100644 --- a/src/adaptors/index.ts +++ b/src/adaptors/index.ts @@ -23,7 +23,7 @@ * questions. */ -import { BlogAdaptor, WebAdaptor } from "zhi-blog-api" +import { BlogAdaptor, BlogConfig, WebAdaptor } from "zhi-blog-api" import { getSubPlatformTypeByKey, SubPlatformType } from "~/src/platforms/dynamicConfig.ts" import { useCnblogsApi } from "~/src/adaptors/api/cnblogs/useCnblogsApi.ts" import { createAppLogger } from "~/src/utils/appLogger.ts" @@ -31,10 +31,6 @@ import { useWordpressApi } from "~/src/adaptors/api/wordpress/useWordpressApi.ts import { useTypechoApi } from "~/src/adaptors/api/typecho/useTypechoApi.ts" import { useYuqueApi } from "~/src/adaptors/api/yuque/useYuqueApi.ts" import { useZhihuWeb } from "~/src/adaptors/web/zhihu/useZhihuWeb.ts" -import { useCsdnWeb } from "~/src/adaptors/web/csdn/useCsdnWeb.ts" -import { useJianshuWeb } from "~/src/adaptors/web/jianshu/useJianshuWeb.ts" -import { useJuejinWeb } from "~/src/adaptors/web/juejin/useJuejinWeb.ts" -import { useWechatWeb } from "~/src/adaptors/web/wechat/useWechatWeb.ts" import { useSiyuanApi } from "~/src/composables/useSiyuanApi.ts" import { useMetaweblogApi } from "~/src/adaptors/api/metaweblog/useMetaweblogApi.ts" import { useNotionApi } from "~/src/adaptors/api/notion/useNotionApi.ts" @@ -50,6 +46,90 @@ import { useHexoApi } from "~/src/adaptors/api/hexo/useHexoApi.ts" class Adaptors { private static logger = createAppLogger("adaptors") + /** + * 根据平台key查找配置 + * + * @param key + */ + public static async getCfg(key: string): Promise { + let conf = null + const type: SubPlatformType = getSubPlatformTypeByKey(key) + + switch (type) { + case SubPlatformType.Common_Yuque: { + const { cfg } = await useYuqueApi(key) + conf = cfg + break + } + case SubPlatformType.Common_Notion: { + const { cfg } = await useNotionApi(key) + conf = cfg + break + } + case SubPlatformType.Github_Hexo: { + const { cfg } = await useHexoApi(key) + conf = cfg + break + } + case SubPlatformType.Metaweblog_Metaweblog: { + const { cfg } = await useMetaweblogApi(key) + conf = cfg + break + } + case SubPlatformType.Metaweblog_Cnblogs: { + const { cfg } = await useCnblogsApi(key) + conf = cfg + break + } + case SubPlatformType.Metaweblog_Typecho: { + const { cfg } = await useTypechoApi(key) + conf = cfg + break + } + case SubPlatformType.Wordpress_Wordpress: { + const { cfg } = await useWordpressApi(key) + conf = cfg + break + } + case SubPlatformType.Custom_Zhihu: { + const { cfg } = await useZhihuWeb(key) + conf = cfg + break + } + // case SubPlatformType.Custom_CSDN: { + // const { cfg } = await useCsdnWeb(key) + // conf = cfg + // break + // } + // case SubPlatformType.Custom_Jianshu: { + // const { cfg } = await useJianshuWeb(key) + // conf = cfg + // break + // } + // case SubPlatformType.Custom_Juejin: { + // const { cfg } = await useJuejinWeb(key) + // conf = cfg + // break + // } + // case SubPlatformType.Custom_Wechat: { + // const { cfg } = await useWechatWeb(key) + // conf = cfg + // break + // } + case SubPlatformType.System_Siyuan: { + const { cfg } = useSiyuanApi() + conf = cfg + break + } + default: { + conf = {} + break + } + } + this.logger.debug(`get conf from key ${key}=>`, conf) + return conf + } + /** * 根据平台key查找适配器 * diff --git a/src/adaptors/web/base/CommonWebConfig.ts b/src/adaptors/web/base/CommonWebConfig.ts index 9b71429e..4cf921eb 100644 --- a/src/adaptors/web/base/CommonWebConfig.ts +++ b/src/adaptors/web/base/CommonWebConfig.ts @@ -23,9 +23,28 @@ * questions. */ -import { WebConfig } from "zhi-blog-api" +import { PageTypeEnum, WebConfig } from "zhi-blog-api" +import { MetaweblogPlaceholder } from "~/src/adaptors/api/base/metaweblog/MetaweblogPlaceholder.ts" /** * 网页授权配置 */ -export class CommonWebConfig extends WebConfig {} +export class CommonWebConfig extends WebConfig { + constructor(home: string, apiUrl: string, username: string, password: string, middlewareUrl?: string) { + super(password, middlewareUrl) + + this.home = home + this.apiUrl = apiUrl + this.username = username + + this.password = password + this.apiStatus = false + this.blogid = "" + this.blogName = "" + this.posidKey = "" + this.previewUrl = "" + this.pageType = PageTypeEnum.Markdown + this.placeholder = new MetaweblogPlaceholder() + this.middlewareUrl = middlewareUrl + } +} diff --git a/src/adaptors/web/csdn/csdnConfig.ts b/src/adaptors/web/csdn/csdnConfig.ts index 007caaf1..cb797113 100644 --- a/src/adaptors/web/csdn/csdnConfig.ts +++ b/src/adaptors/web/csdn/csdnConfig.ts @@ -28,4 +28,8 @@ import { CommonWebConfig } from "~/src/adaptors/web/base/CommonWebConfig.ts" /** * CSDN配置 */ -export class CsdnConfig extends CommonWebConfig {} +export class CsdnConfig extends CommonWebConfig { + constructor(username: string, password: string, middlewareUrl?: string) { + super("", "", username, password, middlewareUrl) + } +} diff --git a/src/adaptors/web/csdn/useCsdnWeb.ts b/src/adaptors/web/csdn/useCsdnWeb.ts index 584a7753..39e7bf91 100644 --- a/src/adaptors/web/csdn/useCsdnWeb.ts +++ b/src/adaptors/web/csdn/useCsdnWeb.ts @@ -56,8 +56,12 @@ const useCsdnWeb = async (key?: string, newCfg?: CsdnConfig) => { // 如果配置为空,则使用默认的环境变量值,并记录日志 if (ObjectUtil.isEmptyObject(cfg)) { // 从环境变量获取Csdn的cookie + const middlewareUrl = Utils.emptyOrDefault( + process.env.VITE_MIDDLEWARE_URL, + "https://api.terwer.space/api/middleware" + ) const csdnCookie = Utils.emptyOrDefault(process.env.VITE_CSDN_AUTH_TOKEN, "") - cfg = new CsdnConfig(csdnCookie) + cfg = new CsdnConfig("", csdnCookie, middlewareUrl) logger.debug("Configuration is empty, using default environment variables.") } else { logger.info("Using configuration from settings...") diff --git a/src/adaptors/web/jianshu/JianshuConfig.ts b/src/adaptors/web/jianshu/JianshuConfig.ts index 6f410992..2d1f1db7 100644 --- a/src/adaptors/web/jianshu/JianshuConfig.ts +++ b/src/adaptors/web/jianshu/JianshuConfig.ts @@ -28,4 +28,8 @@ import { CommonWebConfig } from "~/src/adaptors/web/base/CommonWebConfig.ts" /** * 简书配置 */ -export class JianshuConfig extends CommonWebConfig {} +export class JianshuConfig extends CommonWebConfig { + constructor(username: string, password: string, middlewareUrl?: string) { + super("", "", username, password, middlewareUrl) + } +} diff --git a/src/adaptors/web/jianshu/useJianshuWeb.ts b/src/adaptors/web/jianshu/useJianshuWeb.ts index f564b545..8363704d 100644 --- a/src/adaptors/web/jianshu/useJianshuWeb.ts +++ b/src/adaptors/web/jianshu/useJianshuWeb.ts @@ -55,9 +55,13 @@ const useJianshuWeb = async (key?: string, newCfg?: JianshuConfig) => { cfg = JsonUtil.safeParse(setting[key], {} as JianshuConfig) // 如果配置为空,则使用默认的环境变量值,并记录日志 if (ObjectUtil.isEmptyObject(cfg)) { + const middlewareUrl = Utils.emptyOrDefault( + process.env.VITE_MIDDLEWARE_URL, + "https://api.terwer.space/api/middleware" + ) // 从环境变量获取Jianshu的cookie const jianshuCookie = Utils.emptyOrDefault(process.env.VITE_JIANSHU_AUTH_TOKEN, "") - cfg = new JianshuConfig(jianshuCookie) + cfg = new JianshuConfig("", jianshuCookie, middlewareUrl) logger.debug("Configuration is empty, using default environment variables.") } else { logger.info("Using configuration from settings...") diff --git a/src/adaptors/web/juejin/JuejinConfig.ts b/src/adaptors/web/juejin/JuejinConfig.ts index 81a6ac6c..807d25a9 100644 --- a/src/adaptors/web/juejin/JuejinConfig.ts +++ b/src/adaptors/web/juejin/JuejinConfig.ts @@ -28,4 +28,8 @@ import { CommonWebConfig } from "~/src/adaptors/web/base/CommonWebConfig.ts" /** * 掘金配置 */ -export class JuejinConfig extends CommonWebConfig {} +export class JuejinConfig extends CommonWebConfig { + constructor(username: string, password: string, middlewareUrl?: string) { + super("", "", username, password, middlewareUrl) + } +} diff --git a/src/adaptors/web/juejin/useJuejinWeb.ts b/src/adaptors/web/juejin/useJuejinWeb.ts index d426dcec..0cbb8cb2 100644 --- a/src/adaptors/web/juejin/useJuejinWeb.ts +++ b/src/adaptors/web/juejin/useJuejinWeb.ts @@ -55,9 +55,13 @@ const useJuejinWeb = async (key?: string, newCfg?: JuejinConfig) => { cfg = JsonUtil.safeParse(setting[key], {} as JuejinConfig) // 如果配置为空,则使用默认的环境变量值,并记录日志 if (ObjectUtil.isEmptyObject(cfg)) { + const middlewareUrl = Utils.emptyOrDefault( + process.env.VITE_MIDDLEWARE_URL, + "https://api.terwer.space/api/middleware" + ) // 从环境变量获取Juejin的cookie const juejinCookie = Utils.emptyOrDefault(process.env.VITE_JUEJIN_AUTH_TOKEN, "") - cfg = new JuejinConfig(juejinCookie) + cfg = new JuejinConfig("", juejinCookie, middlewareUrl) logger.debug("Configuration is empty, using default environment variables.") } else { logger.info("Using configuration from settings...") diff --git a/src/adaptors/web/wechat/WechatConfig.ts b/src/adaptors/web/wechat/WechatConfig.ts index ff4475a3..bc84e81b 100644 --- a/src/adaptors/web/wechat/WechatConfig.ts +++ b/src/adaptors/web/wechat/WechatConfig.ts @@ -28,4 +28,8 @@ import { CommonWebConfig } from "~/src/adaptors/web/base/CommonWebConfig.ts" /** * 微信公众号配置 */ -export class WechatConfig extends CommonWebConfig {} +export class WechatConfig extends CommonWebConfig { + constructor(username: string, password: string, middlewareUrl?: string) { + super("", "", username, password, middlewareUrl) + } +} diff --git a/src/adaptors/web/wechat/useWechatWeb.ts b/src/adaptors/web/wechat/useWechatWeb.ts index 797729c6..426ff623 100644 --- a/src/adaptors/web/wechat/useWechatWeb.ts +++ b/src/adaptors/web/wechat/useWechatWeb.ts @@ -55,9 +55,13 @@ const useWechatWeb = async (key?: string, newCfg?: WechatConfig) => { cfg = JsonUtil.safeParse(setting[key], {} as WechatConfig) // 如果配置为空,则使用默认的环境变量值,并记录日志 if (ObjectUtil.isEmptyObject(cfg)) { + const middlewareUrl = Utils.emptyOrDefault( + process.env.VITE_MIDDLEWARE_URL, + "https://api.terwer.space/api/middleware" + ) // 从环境变量获取Wechat的cookie const wechatCookie = Utils.emptyOrDefault(process.env.VITE_WECHAT_AUTH_TOKEN, "") - cfg = new WechatConfig(wechatCookie) + cfg = new WechatConfig("", wechatCookie, middlewareUrl) logger.debug("Configuration is empty, using default environment variables.") } else { logger.info("Using configuration from settings...") diff --git a/src/adaptors/web/zhihu/useZhihuWeb.ts b/src/adaptors/web/zhihu/useZhihuWeb.ts index 906714f2..7aa62f1a 100644 --- a/src/adaptors/web/zhihu/useZhihuWeb.ts +++ b/src/adaptors/web/zhihu/useZhihuWeb.ts @@ -55,9 +55,13 @@ const useZhihuWeb = async (key?: string, newCfg?: ZhihuConfig) => { cfg = JsonUtil.safeParse(setting[key], {} as ZhihuConfig) // 如果配置为空,则使用默认的环境变量值,并记录日志 if (ObjectUtil.isEmptyObject(cfg)) { + const middlewareUrl = Utils.emptyOrDefault( + process.env.VITE_MIDDLEWARE_URL, + "https://api.terwer.space/api/middleware" + ) // 从环境变量获取Zhihu的cookie const zhihuCookie = Utils.emptyOrDefault(process.env.VITE_ZHIHU_AUTH_TOKEN, "") - cfg = new ZhihuConfig(zhihuCookie) + cfg = new ZhihuConfig("", zhihuCookie, middlewareUrl) logger.debug("Configuration is empty, using default environment variables.") } else { logger.info("Using configuration from settings...") @@ -66,7 +70,7 @@ const useZhihuWeb = async (key?: string, newCfg?: ZhihuConfig) => { process.env.VITE_MIDDLEWARE_URL, "https://api.terwer.space/api/middleware" ) - if(StrUtil.isEmptyString(cfg.middlewareUrl)){ + if (StrUtil.isEmptyString(cfg.middlewareUrl)) { cfg.middlewareUrl = middlewareUrl } // 初始化posidKey @@ -78,6 +82,7 @@ const useZhihuWeb = async (key?: string, newCfg?: ZhihuConfig) => { const webApi = new ZhihuWebAdaptor(appInstance, cfg) return { + cfg, webApi, } } diff --git a/src/adaptors/web/zhihu/zhihuConfig.ts b/src/adaptors/web/zhihu/zhihuConfig.ts index e2af1dc6..d02dbedb 100644 --- a/src/adaptors/web/zhihu/zhihuConfig.ts +++ b/src/adaptors/web/zhihu/zhihuConfig.ts @@ -24,8 +24,18 @@ */ import { CommonWebConfig } from "~/src/adaptors/web/base/CommonWebConfig.ts" +import { PageTypeEnum, PasswordType } from "zhi-blog-api" /** * 知乎配置 */ -export class ZhihuConfig extends CommonWebConfig {} +export class ZhihuConfig extends CommonWebConfig { + constructor(username: string, password: string, middlewareUrl?: string) { + super("https://zhuanlan.zhihu.com", "https://zhuanlan.zhihu.com/api", username, password, middlewareUrl) + this.previewUrl = "/p/[postid]" + this.pageType = PageTypeEnum.Html + this.passwordType = PasswordType.PasswordType_Cookie + this.knowledgeSpaceTitle = "专栏" + this.enableKnowledgeSpace = true + } +} diff --git a/src/adaptors/web/zhihu/zhihuPlaceholder.ts b/src/adaptors/web/zhihu/zhihuPlaceholder.ts new file mode 100644 index 00000000..3b768556 --- /dev/null +++ b/src/adaptors/web/zhihu/zhihuPlaceholder.ts @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023, Terwer . All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Terwer designates this + * particular file as subject to the "Classpath" exception as provided + * by Terwer in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com + * or visit www.terwer.space if you need additional information or have any + * questions. + */ + +import { CommonWebPlaceholder } from "~/src/adaptors/web/base/CommonWebPlaceholder.ts" + +class ZhihuPlaceholder extends CommonWebPlaceholder {} + +export { ZhihuPlaceholder } diff --git a/src/adaptors/web/zhihu/zhihuWebAdaptor.ts b/src/adaptors/web/zhihu/zhihuWebAdaptor.ts index 2c28e2d8..4db82259 100644 --- a/src/adaptors/web/zhihu/zhihuWebAdaptor.ts +++ b/src/adaptors/web/zhihu/zhihuWebAdaptor.ts @@ -59,7 +59,7 @@ class ZhihuWebAdaptor extends BaseWebApi { uid: res.uid, title: res.name, avatar: res.avatar_url, - supportTypes: ["markdown"], + supportTypes: ["html"], type: "zhihu", displayName: "知乎", home: "https://www.zhihu.com/settings/account", diff --git a/src/components/set/PublishSetting.vue b/src/components/set/PublishSetting.vue index a7917ad1..62cc5476 100644 --- a/src/components/set/PublishSetting.vue +++ b/src/components/set/PublishSetting.vue @@ -35,7 +35,8 @@ import { AuthMode, deletePlatformByKey, DynamicConfig, - DynamicJsonCfg, getDynPostidKey, + DynamicJsonCfg, + getDynPostidKey, PlatformType, replacePlatformByKey, setDynamicJsonCfg, @@ -51,7 +52,8 @@ import { Utils } from "~/src/utils/utils.ts" import { AppInstance } from "~/src/appInstance.ts" import { ElectronCookie, WebConfig } from "zhi-blog-api" import { useSiyuanDevice } from "~/src/composables/useSiyuanDevice.ts" -import CookieSetting from "~/src/components/set/publish/singleplatform/web/CookieSetting.vue" +import CookieSetting from "~/src/components/set/publish/singleplatform/base/CookieSetting.vue" +import { CommonWebConfig } from "~/src/adaptors/web/base/CommonWebConfig.ts" const logger = createAppLogger("publish-setting") @@ -142,22 +144,22 @@ const handlePlatformEnabled = async (cfg: DynamicConfig) => { } const handleSinglePlatformSetting = async (cfg: DynamicConfig) => { - if (cfg.authMode === AuthMode.API) { - const key = cfg.platformKey - await router.push({ - path: `/setting/platform/single/${key}`, - query: { - showBack: "true", - }, - }) + const key = cfg.platformKey + await router.push({ + path: `/setting/platform/single/${key}`, + query: { + showBack: "true", + }, + }) +} + +const handleSinglePlatformWebAuth = async (cfg: DynamicConfig) => { + if (isInSiyuanWidget()) { + await _handleOpenBrowserAuth(cfg) + } else if (isInChromeExtension()) { + _handleChromeExtensionAuth(cfg) } else { - if (isInSiyuanWidget()) { - await _handleOpenBrowserAuth(cfg) - } else if (isInChromeExtension()) { - _handleChromeExtensionAuth(cfg) - } else { - await _handleSetCookieAuth(cfg) - } + await _handleSetCookieAuth(cfg) } } @@ -251,7 +253,7 @@ const handleValidateWebAuth = async (cfg: DynamicConfig) => { } } -const _handleValidateOpenBrowserAuth = (cfg: DynamicConfig) => { +const _handleValidateOpenBrowserAuth = (dynCfg: DynamicConfig) => { // 设置将要读取的域名 const cookieCb = async (dynCfg: DynamicConfig, cookies: ElectronCookie[]) => { // ElMessage.info("验证中,请关注状态,没有授权表示不可用,已授权表示该平台可正常使用...") @@ -260,13 +262,14 @@ const _handleValidateOpenBrowserAuth = (cfg: DynamicConfig) => { try { const appInstance = new AppInstance() - const apiAdaptor = await Adaptors.getAdaptor(dynCfg.platformKey) + const cfg = (await Adaptors.getCfg(dynCfg.platformKey)) as CommonWebConfig + const apiAdaptor = await Adaptors.getAdaptor(dynCfg.platformKey, cfg) const api = Utils.webApi(appInstance, apiAdaptor) // 构造对应平台的cookie const cookieStr = await api.buildCookie(cookies) // 更新cookie - const newSettingCfg = JsonUtil.safeParse(formData.setting[dynCfg.platformKey], {} as WebConfig) + const newSettingCfg = cfg newSettingCfg.password = cookieStr formData.setting[dynCfg.platformKey] = newSettingCfg // 更新cookie @@ -305,45 +308,47 @@ const _handleValidateOpenBrowserAuth = (cfg: DynamicConfig) => { formData.webAuthLoadingMap[dynCfg.platformKey] = false } - openBrowserWindow(cfg.authUrl, cfg, cookieCb) + openBrowserWindow(dynCfg.authUrl, dynCfg, cookieCb) } -const _handleValidateChromeExtensionAuth = async (cfg: DynamicConfig) => { - formData.webAuthLoadingMap[cfg.platformKey] = true +const _handleValidateChromeExtensionAuth = async (dynCfg: DynamicConfig) => { + formData.webAuthLoadingMap[dynCfg.platformKey] = true try { const appInstance = new AppInstance() - const apiAdaptor = await Adaptors.getAdaptor(cfg.platformKey) + // 这里会有配置初始化 + const cfg = (await Adaptors.getCfg(dynCfg.platformKey)) as CommonWebConfig + const apiAdaptor = await Adaptors.getAdaptor(dynCfg.platformKey, cfg) const api = Utils.webApi(appInstance, apiAdaptor) const metadata = await api.getMetaData() // logger.debug("chrome extension get meta data=>", metadata) if (metadata.flag) { - cfg.isAuth = true - const newSettingCfg2 = JsonUtil.safeParse(formData.setting[cfg.platformKey], {} as WebConfig) - newSettingCfg2.metadata = metadata - // newSettingCfg2 - formData.setting[cfg.platformKey] = newSettingCfg2 + dynCfg.isAuth = true + const newSettingCfg = cfg + newSettingCfg.metadata = metadata + // settingConf + formData.setting[dynCfg.platformKey] = newSettingCfg // 更新metadata await updateSetting(formData.setting) logger.info("已更新最新的metadata") ElMessage.success("验证成功,该平台可正常使用") } else { - cfg.isAuth = false + dynCfg.isAuth = false ElMessage.error("验证失败,该平台将不可用") } } catch (e) { - cfg.isAuth = false + dynCfg.isAuth = false ElMessage.error(t("main.opt.failure") + "=>" + e) logger.error(e) } - formData.dynamicConfigArray = replacePlatformByKey(formData.dynamicConfigArray, cfg.platformKey, cfg) + formData.dynamicConfigArray = replacePlatformByKey(formData.dynamicConfigArray, dynCfg.platformKey, dynCfg) // 替换删除后的平台配置 const dynJsonCfg = setDynamicJsonCfg(formData.dynamicConfigArray) formData.setting[DYNAMIC_CONFIG_KEY] = dynJsonCfg // 更新状态 await updateSetting(formData.setting) - formData.webAuthLoadingMap[cfg.platformKey] = false + formData.webAuthLoadingMap[dynCfg.platformKey] = false } const _handleValidateCookieAuth = async (cfg: DynamicConfig) => { @@ -525,20 +530,40 @@ onMounted(async () => { inactive-text="未启用" @change="handlePlatformEnabled(platform)" > + + + + + 设置 + + + - {{ platform.authMode === AuthMode.API ? "设置" : platform.isAuth ? "再次授权" : "授权" }} + 设置 + + + + + + + {{ platform.isAuth ? "再次授权" : "授权" }} + - + + diff --git a/src/components/set/publish/singleplatform/base/CommonBlogSetting.vue b/src/components/set/publish/singleplatform/base/CommonBlogSetting.vue index a1bec5ff..9deb53bc 100644 --- a/src/components/set/publish/singleplatform/base/CommonBlogSetting.vue +++ b/src/components/set/publish/singleplatform/base/CommonBlogSetting.vue @@ -270,7 +270,7 @@ onMounted(async () => { { > - + - {{ t("setting.common.token.gen") }}:{{ props.cfg.tokenSettingUrl }} + + + + + @@ -365,4 +385,7 @@ onMounted(async () => { .top-tip margin 10px 0 padding-left 0 +.inline-tip + margin 0 + padding-left 0 diff --git a/src/components/set/publish/singleplatform/web/CookieSetting.vue b/src/components/set/publish/singleplatform/base/CookieSetting.vue similarity index 99% rename from src/components/set/publish/singleplatform/web/CookieSetting.vue rename to src/components/set/publish/singleplatform/base/CookieSetting.vue index 459cf827..4246becf 100644 --- a/src/components/set/publish/singleplatform/web/CookieSetting.vue +++ b/src/components/set/publish/singleplatform/base/CookieSetting.vue @@ -102,7 +102,7 @@ const submitForm = async (formEl) => { type="error" :closable="false" /> - + + + + diff --git a/src/components/set/publish/singleplatform/commonblog/NotionSetting.vue b/src/components/set/publish/singleplatform/commonblog/NotionSetting.vue index 83d0fccf..262b2624 100644 --- a/src/components/set/publish/singleplatform/commonblog/NotionSetting.vue +++ b/src/components/set/publish/singleplatform/commonblog/NotionSetting.vue @@ -46,9 +46,6 @@ notionPlaceholder.passwordPlaceholder = t("setting.notion.password.tip") notionPlaceholder.apiUrlPlaceholder = t("setting.notion.apiurl.tip") notionPlaceholder.previewUrlPlaceholder = t("setting.notion.previewUrl.tip") notionCfg.placeholder = notionPlaceholder -// 正式版发布之后删除下面配置 -notionCfg.knowledgeSpaceTitle = "根页面" -notionCfg.enableKnowledgeSpace = true