Skip to content

Commit

Permalink
feat: #1076 #1077 优化发布配置、平台导入、插件商店使用体验 - 支持平台 Jvue
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Mar 11, 2024
1 parent da8408c commit c98f11f
Show file tree
Hide file tree
Showing 14 changed files with 337 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/插件开发.md
Expand Up @@ -10,7 +10,7 @@
- Custom
- System

## 新增大类的时候需要维护
## 新增大类的时候需要维护(内部维护)
- DynamicJsonCfg
- getSubtypeList
- setDynamicJsonCfg
Expand Down
52 changes: 52 additions & 0 deletions src/adaptors/api/jvue/jvueApiAdaptor.ts
@@ -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 }
62 changes: 62 additions & 0 deletions src/adaptors/api/jvue/jvueConfig.ts
@@ -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 }
33 changes: 33 additions & 0 deletions src/adaptors/api/jvue/jvuePlaceHolder.ts
@@ -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 }
101 changes: 101 additions & 0 deletions src/adaptors/api/jvue/useJvueApi.ts
@@ -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,
}
}
2 changes: 1 addition & 1 deletion src/adaptors/api/typecho/typechoPlaceholder.ts
Expand Up @@ -26,7 +26,7 @@
import { MetaweblogPlaceholder } from "~/src/adaptors/api/base/metaweblog/metaweblogPlaceholder.ts"

/**
* WordPress 操作提示
* Typecho 操作提示
*/
class TypechoPlaceholder extends MetaweblogPlaceholder {}

Expand Down
11 changes: 11 additions & 0 deletions src/adaptors/index.ts
Expand Up @@ -52,6 +52,7 @@ import { useGitlabvuepress2Api } from "~/src/adaptors/api/gitlab-vuepress2/useGi
import { useGitlabvitepressApi } from "~/src/adaptors/api/gitlab-vitepress/useGitlabvitepressApi.ts"
import { useHaloApi } from "~/src/adaptors/api/halo/useHaloApi.ts"
import { useTelegraphApi } from "~/src/adaptors/api/telegraph/useTelegraphApi.ts"
import { useJvueApi } from "~/src/adaptors/api/jvue/useJvueApi.ts"

/**
* 适配器统一入口
Expand Down Expand Up @@ -168,6 +169,11 @@ class Adaptors {
conf = cfg
break
}
case SubPlatformType.Metaweblog_Jvue: {
const { cfg } = await useJvueApi(key, newCfg)
conf = cfg
break
}
case SubPlatformType.Wordpress_Wordpress: {
const { cfg } = await useWordpressApi(key, newCfg)
conf = cfg
Expand Down Expand Up @@ -323,6 +329,11 @@ class Adaptors {
blogAdaptor = blogApi
break
}
case SubPlatformType.Metaweblog_Jvue: {
const { blogApi } = await useJvueApi(key, newCfg)
blogAdaptor = blogApi
break
}
case SubPlatformType.Wordpress_Wordpress: {
const { blogApi } = await useWordpressApi(key, newCfg)
blogAdaptor = blogApi
Expand Down
Expand Up @@ -29,7 +29,7 @@ import { reactive } from "vue"
import { useRoute } from "vue-router"
import { useVueI18n } from "~/src/composables/useVueI18n.ts"
import { getSubPlatformTypeByKey, SubPlatformType } from "~/src/platforms/dynamicConfig.ts"
import TelegraphSetting from "~/src/components/set/publish/singleplatform/commonblog/TelegraphSetting.vue";
import TelegraphSetting from "~/src/components/set/publish/singleplatform/commonblog/TelegraphSetting.vue"
// uses
const { t } = useVueI18n()
Expand Down Expand Up @@ -62,6 +62,7 @@ const subtype = getSubPlatformTypeByKey(apiType)
<othermeta-setting v-else-if="subtype === SubPlatformType.Metaweblog_Metaweblog" :api-type="apiType" />
<cnblogs-setting v-else-if="subtype === SubPlatformType.Metaweblog_Cnblogs" :api-type="apiType" />
<typecho-setting v-else-if="subtype === SubPlatformType.Metaweblog_Typecho" :api-type="apiType" />
<jvue-setting v-else-if="subtype === SubPlatformType.Metaweblog_Jvue" :api-type="apiType" />
<wordpress-setting v-else-if="subtype === SubPlatformType.Wordpress_Wordpress" :api-type="apiType" />
<zhihu-setting v-else-if="subtype === SubPlatformType.Custom_Zhihu" :api-type="apiType" />
<csdn-setting v-else-if="subtype === SubPlatformType.Custom_CSDN" :api-type="apiType" />
Expand Down
@@ -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>
2 changes: 1 addition & 1 deletion src/locales/en_US.ts
Expand Up @@ -430,7 +430,7 @@ export default {
"setting.jvue.username.tip": "Jvue platform login name",
"setting.jvue.password.tip": "Jvue platform password",
"setting.jvue.apiUrl.tip":
"The XMLRPC remote release address of the JVUE platform is usually fixed: https: // <platform address>/xmlrpc",
"The XMLRPC remote release address of the Jvue platform is usually fixed: https: // <platform address>/xmlrpc",
"setting.jvue.previewUrl.tip": "The preview rules of the Jvue platform are usually:/post/[postid] .html",

"setting.conf.home.tip":
Expand Down

0 comments on commit c98f11f

Please sign in to comment.