Skip to content

Commit

Permalink
feat: 支持 Typecho
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Aug 1, 2023
1 parent 6cb0ddc commit 8068502
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 17 deletions.
65 changes: 51 additions & 14 deletions src/composables/usePublish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,19 @@ const usePublish = () => {
logger.info("api=>", api)

singleFormData.publishProcessStatus = await api.deletePost(postid)

// 删除成功才去移除文章发布信息
if (!StrUtil.isEmptyString(posidKey)) {
const postMeta = singleFormData.setting[id] ?? {}
const updatedPostMeta = { ...postMeta }
if (updatedPostMeta.hasOwnProperty(posidKey)) {
delete updatedPostMeta[posidKey]
}

singleFormData.setting[id] = updatedPostMeta
await updateSetting(singleFormData.setting)
logger.info(`[${key}] [${id}] 文章发布信息已移除`)
}
} catch (e) {
singleFormData.errMsg = t("main.opt.failure") + "=>" + e
logger.error(e)
Expand All @@ -175,31 +188,55 @@ const usePublish = () => {
})
}

// 移除文章发布信息
const posidKey = singleFormData.cfg.posidKey
if (!StrUtil.isEmptyString(posidKey)) {
const postMeta = singleFormData.setting[id] ?? {}
const updatedPostMeta = { ...postMeta }
if (updatedPostMeta.hasOwnProperty(posidKey)) {
delete updatedPostMeta[posidKey]
}

singleFormData.setting[id] = updatedPostMeta
await updateSetting(singleFormData.setting)
logger.info(`[${key}] [${id}] 文章发布信息已移除`)
}

return {
key: key,
status: singleFormData.publishProcessStatus,
errMsg: singleFormData.errMsg,
}
}

const doForceSingleDelete = async (key: string, id: string) => {
try {
// 加载配置
singleFormData.setting = await getSetting()
singleFormData.cfg = JsonUtil.safeParse<any>(singleFormData.setting[key], {} as any)

// 检测是否发布
const posidKey = singleFormData.cfg.posidKey
if (StrUtil.isEmptyString(posidKey)) {
throw new Error("配置错误,posidKey不能为空,请检查配置")
}
if (!StrUtil.isEmptyString(posidKey)) {
const postMeta = singleFormData.setting[id] ?? {}
const updatedPostMeta = { ...postMeta }
if (updatedPostMeta.hasOwnProperty(posidKey)) {
delete updatedPostMeta[posidKey]
}

singleFormData.setting[id] = updatedPostMeta
await updateSetting(singleFormData.setting)

await kernelApi.pushMsg({
msg: t("main.opt.ok"),
timeout: 2000,
})
logger.info(`[${key}] [${id}] 文章发布信息已强制移除`)
}
} catch (e) {
logger.error(e)
// ElMessage.error(singleFormData.errMsg)
await kernelApi.pushErrMsg({
msg: t("main.opt.failure") + "=>" + e,
timeout: 7000,
})
}
}

return {
singleFormData,
doSinglePublish,
doSingleDelete,
doForceSingleDelete,
}
}

Expand Down
17 changes: 14 additions & 3 deletions src/workers/quickPublish.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@ const params = reactive(route.params)
const key = params.key as string
const id = params.id as string
const formData = reactive({
processResult: {} as any,
})
onMounted(async () => {
singleFormData.isPublishLoading = true
setTimeout(async () => {
logger.info("单个快速发布开始")
// 思源笔记原始文章数据
const doc = await blogApi.getPost(id)
await doSinglePublish(key, id, doc)
formData.processResult = await doSinglePublish(key, id, doc)
logger.info("单个快速发布结束")
singleFormData.isPublishLoading = false
}, 200)
Expand All @@ -70,10 +74,17 @@ onMounted(async () => {
发布中,请稍后...:
</div>
<div v-else-if="singleFormData.publishProcessStatus" class="success-tips">
{{ singleFormData.isAdd ? "发布到" : "更新文章到" }} [博客园] 成功,
{{ singleFormData.isAdd ? "发布到" : "更新文章到" }}
[{{ formData.processResult.key }}]
{{ StrUtil.isEmptyString(formData.processResult.name) ? "" : `[${formData.processResult.name}]` }}
成功,
<a :href="singleFormData.previewUrl" target="_blank">查看文章</a>
</div>
<div v-else class="fail-tips">{{ singleFormData.isAdd ? "发布到" : "更新文章到" }} [博客园] 失败!</div>
<div v-else class="fail-tips">
{{ singleFormData.isAdd ? "发布到" : "更新文章到" }} [{{ formData.processResult.key }}]
{{ StrUtil.isEmptyString(formData.processResult.name) ? "" : `[${formData.processResult.name}]` }}
失败!
</div>
</div>
</div>
</template>
Expand Down

0 comments on commit 8068502

Please sign in to comment.