Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
14 changed files
with
337 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) 2024, 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 { MetaweblogBlogApiAdaptor } from "~/src/adaptors/api/base/metaweblog/metaweblogBlogApiAdaptor.ts" | ||
import { PublisherAppInstance } from "~/src/publisherAppInstance.ts" | ||
import { JvueConfig } from "~/src/adaptors/api/jvue/jvueConfig.ts" | ||
import { createAppLogger } from "~/src/utils/appLogger.ts" | ||
|
||
/** | ||
* Typecho API 适配器 | ||
* | ||
* @author terwer | ||
* @version 0.9.0 | ||
* @since 0.9.0 | ||
*/ | ||
class JvueApiAdaptor extends MetaweblogBlogApiAdaptor { | ||
/** | ||
* 初始化 Typecho API 适配器 | ||
* | ||
* @param appInstance 应用实例 | ||
* @param cfg 配置项 | ||
*/ | ||
constructor(appInstance: PublisherAppInstance, cfg: JvueConfig) { | ||
super(appInstance, cfg) | ||
this.logger = createAppLogger("typecho-api-adaptor") | ||
this.cfg.blogid = "jvue" | ||
} | ||
} | ||
|
||
export { JvueApiAdaptor } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright (c) 2024, 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 { MetaweblogConfig } from "~/src/adaptors/api/base/metaweblog/metaweblogConfig.ts" | ||
import {CategoryTypeEnum, PageTypeEnum} from "zhi-blog-api"; | ||
|
||
/** | ||
* Jvue 配置 | ||
* | ||
* @author terwer | ||
* @since 1.20.0 | ||
*/ | ||
class JvueConfig extends MetaweblogConfig { | ||
/** | ||
* Jvue 配置项 | ||
* | ||
* @param homeAddr 博客地址 | ||
* @param apiUrl 博客api地址 | ||
* @param username 用户名 | ||
* @param password 密码 | ||
* @param middlewareUrl 中间件地址 | ||
*/ | ||
constructor(homeAddr: string, apiUrl: string, username: string, password: string, middlewareUrl?: string) { | ||
super(homeAddr, apiUrl, username, password, middlewareUrl) | ||
|
||
this.home = homeAddr | ||
this.apiUrl = apiUrl | ||
this.previewUrl = "/post/[postid].html" | ||
this.pageType = PageTypeEnum.Markdown | ||
this.showTokenTip = false | ||
this.allowPreviewUrlChange = false | ||
this.tagEnabled = true | ||
this.cateEnabled = true | ||
this.categoryType = CategoryTypeEnum.CategoryType_Multi | ||
this.allowCateChange = true | ||
this.knowledgeSpaceEnabled = false | ||
} | ||
} | ||
|
||
export { JvueConfig } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (c) 2024, 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 { MetaweblogPlaceholder } from "~/src/adaptors/api/base/metaweblog/metaweblogPlaceholder.ts" | ||
|
||
/** | ||
* Jvue 操作提示 | ||
*/ | ||
class JvuePlaceHolder extends MetaweblogPlaceholder {} | ||
|
||
export { JvuePlaceHolder } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright (c) 2024, 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 { JvueConfig } from "~/src/adaptors/api/jvue/jvueConfig.ts" | ||
import { createAppLogger } from "~/src/utils/appLogger.ts" | ||
import { PublisherAppInstance } from "~/src/publisherAppInstance.ts" | ||
import { usePublishSettingStore } from "~/src/stores/usePublishSettingStore.ts" | ||
import { JsonUtil, ObjectUtil, StrUtil } from "zhi-common" | ||
import { Utils } from "~/src/utils/utils.ts" | ||
import { LEGENCY_SHARED_PROXT_MIDDLEWARE } from "~/src/utils/constants.ts" | ||
import { getDynPostidKey } from "~/src/platforms/dynamicConfig.ts" | ||
import { CategoryTypeEnum } from "zhi-blog-api" | ||
import { JvueApiAdaptor } from "~/src/adaptors/api/jvue/jvueApiAdaptor.ts" | ||
|
||
/** | ||
* 使用Jvue API的自定义hook | ||
* | ||
* @param key 配置键值,可选参数 | ||
* @param newCfg 新配置信息 | ||
* @author terwer | ||
* @version 1.20.0 | ||
* @since 1.20.0 | ||
*/ | ||
export const useJvueApi = async (key?: string, newCfg?: JvueConfig) => { | ||
// 创建应用日志记录器 | ||
const logger = createAppLogger("use-jvue-api") | ||
|
||
// 记录开始使用Jvue API | ||
logger.info("Start using Jvue API...") | ||
|
||
// 创建应用实例 | ||
const appInstance = new PublisherAppInstance() | ||
|
||
let cfg: JvueConfig | ||
if (newCfg) { | ||
logger.info("Initialize with the latest newCfg passed in...") | ||
cfg = newCfg | ||
} else { | ||
// 从配置中获取数据 | ||
const { getSetting } = usePublishSettingStore() | ||
const setting = await getSetting() | ||
cfg = JsonUtil.safeParse<JvueConfig>(setting[key], {} as JvueConfig) | ||
// 如果配置为空,则使用默认的环境变量值,并记录日志 | ||
if (ObjectUtil.isEmptyObject(cfg)) { | ||
// 从环境变量获取Jvue API的URL、用户名、认证令牌和中间件URL | ||
const jvueHome = Utils.emptyOrDefault(process.env.VITE_JVUE_HOME, "") | ||
const jvueApiUrl = Utils.emptyOrDefault(process.env.VITE_JVUE_API_URL, "") | ||
const jvueUsername = Utils.emptyOrDefault(process.env.VITE_JVUE_USERNAME, "") | ||
const jvueAuthToken = Utils.emptyOrDefault(process.env.VITE_JVUE_PASSWORD, "") | ||
const middlewareUrl = Utils.emptyOrDefault(process.env.VITE_MIDDLEWARE_URL, LEGENCY_SHARED_PROXT_MIDDLEWARE) | ||
cfg = new JvueConfig(jvueHome, jvueApiUrl, jvueUsername, jvueAuthToken, middlewareUrl) | ||
logger.info("Configuration is empty, using default environment variables.") | ||
} else { | ||
logger.info("Using configuration from settings...") | ||
} | ||
// 初始化posidKey | ||
if (StrUtil.isEmptyString(cfg.posidKey)) { | ||
// 默认值 | ||
cfg.posidKey = getDynPostidKey(key) | ||
} | ||
} | ||
|
||
// 标签 | ||
cfg.tagEnabled = true | ||
// Jvue使用多选分类 | ||
cfg.cateEnabled = true | ||
cfg.categoryType = CategoryTypeEnum.CategoryType_Multi | ||
cfg.allowCateChange = true | ||
cfg.knowledgeSpaceEnabled = false | ||
|
||
// 创建Jvue API适配器 | ||
const blogApi = new JvueApiAdaptor(appInstance, cfg) | ||
logger.info("Jvue API created successfully.", cfg) | ||
|
||
return { | ||
cfg, | ||
blogApi, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/components/set/publish/singleplatform/metaweblog/JvueSetting.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<!-- | ||
- Copyright (c) 2022-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. | ||
--> | ||
|
||
<script lang="ts" setup> | ||
import { useVueI18n } from "~/src/composables/useVueI18n.ts" | ||
import MetaweblogSetting from "~/src/components/set/publish/singleplatform/base/impl/MetaweblogSetting.vue" | ||
import { JvueConfig } from "~/src/adaptors/api/jvue/jvueConfig.ts" | ||
import { useJvueApi } from "~/src/adaptors/api/jvue/useJvueApi.ts" | ||
import { JvuePlaceHolder } from "~/src/adaptors/api/jvue/jvuePlaceHolder.ts" | ||
const props = defineProps({ | ||
apiType: { | ||
type: String, | ||
default: "", | ||
}, | ||
}) | ||
const { t } = useVueI18n() | ||
const { cfg } = await useJvueApi(props.apiType) | ||
const tcCfg = cfg as JvueConfig | ||
const tcPlaceholder = new JvuePlaceHolder() | ||
tcPlaceholder.homePlaceholder = t("setting.jvue.home.tip") | ||
tcPlaceholder.usernamePlaceholder = t("setting.jvue.username.tip") | ||
tcPlaceholder.passwordPlaceholder = t("setting.jvue.password.tip") | ||
tcPlaceholder.apiUrlPlaceholder = t("setting.jvue.apiUrl.tip") | ||
tcPlaceholder.previewUrlPlaceholder = t("setting.jvue.previewUrl.tip") | ||
tcCfg.placeholder = tcPlaceholder | ||
</script> | ||
|
||
<template> | ||
<metaweblog-setting :api-type="props.apiType" :cfg="tcCfg" /> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.