Skip to content

Commit

Permalink
fix: 修复语雀编辑文章可能出错的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Aug 1, 2023
1 parent b9620cb commit 44261c9
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 16 deletions.
7 changes: 6 additions & 1 deletion src/adaptors/api/yuque/adaptor/yuqueApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,12 @@ export class YuqueApi {
throw new Error("请求语雀API异常")
}

return String(result.id)
// 包含了笔记本需要返回标识笔记本的ID,否则更新可能报错
if (repo) {
return `${result.id}_${repo}`
} else {
return `${result.id}`
}
}

/**
Expand Down
15 changes: 10 additions & 5 deletions src/adaptors/api/yuque/adaptor/yuqueApiAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
* questions.
*/

import {BlogApi, CategoryInfo, Post, UserBlog} from "zhi-blog-api"
import {YuqueApi} from "~/src/adaptors/api/yuque/adaptor/yuqueApi.ts"
import {YuqueConfig} from "~/src/adaptors/api/yuque/config/yuqueConfig.ts"
import {createAppLogger} from "~/src/utils/appLogger.ts"
import {StrUtil} from "zhi-common"
import { BlogApi, CategoryInfo, Post, UserBlog } from "zhi-blog-api"
import { YuqueApi } from "~/src/adaptors/api/yuque/adaptor/yuqueApi.ts"
import { YuqueConfig } from "~/src/adaptors/api/yuque/config/yuqueConfig.ts"
import { createAppLogger } from "~/src/utils/appLogger.ts"
import { StrUtil } from "zhi-common"

/**
* Yuque API 适配器
Expand Down Expand Up @@ -89,6 +89,10 @@ class YuqueApiAdaptor extends BlogApi {
if (post.cate_slugs != null && post.cate_slugs.length > 0) {
const repo = post.cate_slugs[0]
return await this.yuqueApi.addDoc(post.title, post.wp_slug, post.description, repo)
} else if (!StrUtil.isEmptyString(this.cfg.blogid)) {
// 确保最新的文章ID都包含了笔记本信息,防止以后文章出错
const repo = this.cfg.blogid
return await this.yuqueApi.addDoc(post.title, post.wp_slug, post.description, repo)
} else {
return await this.yuqueApi.addDoc(post.title, post.wp_slug, post.description)
}
Expand Down Expand Up @@ -151,6 +155,7 @@ class YuqueApiAdaptor extends BlogApi {

/**
* 获取封装的postid
*
* @param postid
* @private postid
*/
Expand Down
31 changes: 23 additions & 8 deletions src/components/publish/PublishIndex.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { ElMessage, ElMessageBox } from "element-plus"
import { StrUtil } from "zhi-common"
import { pre } from "~/src/utils/import/pre.ts"
import { Delete } from "@element-plus/icons-vue"
import { BrowserUtil } from "zhi-device"
const logger = createAppLogger("publisher-index")
Expand Down Expand Up @@ -99,12 +100,18 @@ const handlePublish = async () => {
}
const handleDelete = async () => {
ElMessageBox.confirm(`确认要删除平台 ${formData.dynList.join("")} 下面的文章吗,此平台文章数据也将永久删除 [注意:系统内置平台会忽略,不做删除] ?`, "温馨提示", {
type: "error",
icon: markRaw(Delete),
confirmButtonText: t("main.opt.ok"),
cancelButtonText: t("main.opt.cancel"),
})
ElMessageBox.confirm(
`确认要删除平台 ${formData.dynList.join(
""
)} 下面的文章吗,此平台文章数据也将永久删除 [注意:系统内置平台会忽略,不做删除] ?`,
"温馨提示",
{
type: "error",
icon: markRaw(Delete),
confirmButtonText: t("main.opt.ok"),
cancelButtonText: t("main.opt.cancel"),
}
)
.then(async () => {
await doDelete()
})
Expand Down Expand Up @@ -150,6 +157,10 @@ const syncDynList = (selectedKeys: string[]) => {
formData.dynList = selectedKeys
}
const handleRefresh = () => {
BrowserUtil.reloadPage()
}
onMounted(async () => {
logger.info("获取到的ID为=>", id)
// 思源笔记原始文章数据
Expand All @@ -170,6 +181,7 @@ onMounted(async () => {
>
<div class="error-total-msg">
错误平台个数 [{{ formData.errCount }}] ,选择的总平台数 [{{ formData.dynList.length }}] 。
<a class="refresh-page" @click="handleRefresh">刷新页面</a>
</div>
<div v-for="errRet in formData.failBatchResults">
[{{ errRet.key }}] {{ StrUtil.isEmptyString(errRet.name) ? "" : `[${errRet.name}]` }} {{ errRet.errMsg }}
Expand All @@ -196,7 +208,7 @@ onMounted(async () => {
<el-divider border-style="dashed" />

<!-- 分发平台 -->
<publish-platform @emitSyncDynList="syncDynList" />
<publish-platform :id="id" @emitSyncDynList="syncDynList" />
<el-divider border-style="dashed" />

<!--
Expand Down Expand Up @@ -242,4 +254,7 @@ onMounted(async () => {
color var(--el-color-success)
.fail-tips
color var(--el-color-error)
</style>
.refresh-page
cursor pointer
</style>
20 changes: 18 additions & 2 deletions src/components/publish/form/PublishPlatform.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

<script setup lang="ts">
import { onMounted, reactive } from "vue"
import { JsonUtil } from "zhi-common"
import { DynamicConfig, DynamicJsonCfg } from "~/src/components/set/publish/platform/dynamicConfig.ts"
import { JsonUtil, StrUtil } from "zhi-common"
import { DynamicConfig, DynamicJsonCfg, getDynPostidKey } from "~/src/components/set/publish/platform/dynamicConfig.ts"
import { DYNAMIC_CONFIG_KEY } from "~/src/utils/constants.ts"
import { useSettingStore } from "~/src/stores/useSettingStore.ts"
import { svgIcons } from "../../../utils/svgIcons.ts"
Expand All @@ -35,6 +35,10 @@ import { createAppLogger } from "~/src/utils/appLogger.ts"
const logger = createAppLogger("publish-platform")
const props = defineProps({
id: "" as string,

Check failure on line 39 in src/components/publish/form/PublishPlatform.vue

View workflow job for this annotation

GitHub Actions / ci

No overload matches this call.
})
// uses
const { getSetting } = useSettingStore()
Expand Down Expand Up @@ -78,6 +82,18 @@ onMounted(async () => {
)
// 默认展示通用平台
formData.dynamicConfigArray = enabledConfigs || []
// 检测是否已经发布
formData.dynamicConfigArray.forEach((item) => {
const key = item.platformKey
const posidKey = getDynPostidKey(key)
if (!StrUtil.isEmptyString(posidKey)) {
const postMeta = setting[props.id] ?? {}
const postid = postMeta[posidKey] ?? ""
if (!StrUtil.isEmptyString(postid)) {
handleCheck(key)
}
}
})
})
</script>

Expand Down

0 comments on commit 44261c9

Please sign in to comment.