Skip to content

Commit

Permalink
feat: 修复别名问题
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Aug 7, 2023
1 parent 25be93a commit 4634b7d
Show file tree
Hide file tree
Showing 8 changed files with 246 additions and 230 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@
"vue-router": "^4.2.4",
"xmlbuilder2": "^3.1.1",
"zhi-blog-api": "^1.20.11",
"zhi-common": "^1.13.3",
"zhi-common": "^1.13.4",
"zhi-device": "^2.3.0",
"zhi-fetch-middleware": "^0.2.16",
"zhi-github-middleware": "^0.1.17",
"zhi-fetch-middleware": "^0.2.17",
"zhi-github-middleware": "^0.1.18",
"zhi-lib-base": "^0.4.4",
"zhi-notion-markdown": "^0.1.2",
"zhi-siyuan-api": "^2.0.10",
"zhi-xmlrpc-middleware": "^0.4.11"
"zhi-siyuan-api": "^2.0.11",
"zhi-xmlrpc-middleware": "^0.4.12"
}
}
49 changes: 25 additions & 24 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 10 additions & 9 deletions src/adaptors/api/base/github/CommonGithubApiAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,17 @@ class CommonGithubApiAdaptor extends BaseBlogApi {

public async newPost(post: Post, publish?: boolean): Promise<string> {
this.logger.debug("start newPost =>", { post: toRaw(post) })
const cfg = this.cfg as CommonGithubConfig

const filename = post.wp_slug
const docPath = `/xxx/${filename}.md`
throw new Error("newPost 开发中...")
// const docPath = `${post.wp_slug}`
// const res = await this.githubClient.publishGithubPage(docPath, post.description)
//
// if (!res?.content?.path) {
// throw new Error("Github 调用API异常")
// }
// return res.content.path
const defaultPath = post.cate_slugs?.[0] ?? cfg.blogid
const docPath = `${defaultPath}/${filename}.md`
const res = await this.githubClient.publishGithubPage(docPath, post.description)

if (!res?.content?.path) {
throw new Error("Github 调用API异常")
}
return res.content.path
}

async editPost(postid: string, post: Post, publish?: boolean): Promise<boolean> {
Expand Down
36 changes: 26 additions & 10 deletions src/components/publish/BatchPublishIndex.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ import PublishPlatform from "~/src/components/publish/form/PublishPlatform.vue"
import { markRaw, onMounted, reactive } from "vue"
import { usePublish } from "~/src/composables/usePublish.ts"
import { useSiyuanApi } from "~/src/composables/useSiyuanApi.ts"
import { Post } from "zhi-blog-api"
import { useVueI18n } from "~/src/composables/useVueI18n.ts"
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"
import { usePublishConfig } from "~/src/composables/usePublishConfig.ts"
import { Post } from "zhi-blog-api"
import { IPublishCfg } from "~/src/types/IPublishCfg.ts"
const logger = createAppLogger("publisher-index")
Expand All @@ -50,8 +52,9 @@ const props = defineProps({
// uses
const { t } = useVueI18n()
const { doSinglePublish, doSingleDelete, assignAttrs } = usePublish()
const { doSinglePublish, doSingleDelete } = usePublish()
const { blogApi } = useSiyuanApi()
const { getPublishCfg } = usePublishConfig()
// datas
const sysKeys = pre.systemCfg.map((item) => {
Expand All @@ -63,11 +66,14 @@ const formData = reactive({
isDeleteLoading: false,
showProcessResult: false,
siyuanPost: {} as Post,
errCount: 0,
successBatchResults: <any[]>[],
failBatchResults: <any[]>[],
// 单个平台信息
siyuanPost: {} as Post,
publishCfg: {} as IPublishCfg,
dynList: <string[]>[],
actionEnable: true,
})
Expand All @@ -83,7 +89,12 @@ const handlePublish = async () => {
formData.failBatchResults = []
formData.successBatchResults = []
for (const key of formData.dynList) {
const batchResult = await doSinglePublish(key, id, formData.siyuanPost)
// 思源笔记原始文章数据
const siyuanPost = await blogApi.getPost(id)
// 初始化属性
const publishCfg = await getPublishCfg(key)
formData.publishCfg = publishCfg
const batchResult = await doSinglePublish(key, id, publishCfg, siyuanPost)
if (batchResult.status) {
formData.successBatchResults.push(batchResult)
} else {
Expand Down Expand Up @@ -141,7 +152,10 @@ const doDelete = async () => {
logger.info(`[${key}] 系统内置平台,不可删除,跳过`)
continue
}
const batchResult = await doSingleDelete(key, id)
// 初始化属性
const publishCfg = await getPublishCfg(key)
formData.publishCfg = publishCfg
const batchResult = await doSingleDelete(key, id, publishCfg)
if (!batchResult.status) {
formData.failBatchResults.push(batchResult)
formData.errCount++
Expand Down Expand Up @@ -172,11 +186,9 @@ const handleRefresh = () => {
}
onMounted(async () => {
logger.info("获取到的ID为=>", id)
// 思源笔记原始文章数据
formData.siyuanPost = await blogApi.getPost(id)
// 初始化属性
formData.siyuanPost = await assignAttrs(formData.siyuanPost)
const siyuanPost = await blogApi.getPost(id)
formData.siyuanPost = siyuanPost
})
</script>

Expand All @@ -197,7 +209,11 @@ onMounted(async () => {
</div>
<div v-for="errRet in formData.failBatchResults">
[{{ errRet.key }}] {{ StrUtil.isEmptyString(errRet.name) ? "" : `[${errRet.name}]` }} {{ errRet.errMsg }}
<a href="javascript:void(0)" @click="doSingleDelete(errRet.key, props.id)">强制解除关联</a>
<a
href="javascript:void(0)"
@click="doSingleDelete(errRet.key, props.id, formData.publishCfg as IPublishCfg)"
>强制解除关联</a
>
</div>
<div v-if="formData.successBatchResults.length > 0" class="success-result success-tips">
已分发成功的结果如下:
Expand Down
39 changes: 27 additions & 12 deletions src/components/publish/SinglePublishDoPublish.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import { ElMessage, ElMessageBox } from "element-plus"
import { Delete } from "@element-plus/icons-vue"
import { BrowserUtil } from "zhi-device"
import { StrUtil } from "zhi-common"
import { usePublishConfig } from "~/src/composables/usePublishConfig.ts"
import { IPublishCfg } from "~/src/types/IPublishCfg.ts"
const logger = createAppLogger("single-publish-do-publish")
Expand All @@ -49,6 +51,7 @@ const { query } = useRoute()
const { kernelApi } = useSiyuanApi()
const { doSinglePublish, doSingleDelete } = usePublish()
const router = useRouter()
const { getPublishCfg } = usePublishConfig()
// datas
const params = reactive(route.params)
Expand All @@ -57,15 +60,19 @@ const id = params.id as string
const formData = reactive({
isInit: false,
method: query.method as MethodEnum,
isPublishLoading: false,
isDeleteLoading: false,
publishCfg: {} as IPublishCfg,
siyuanPost: {} as Post,
platformPost: {} as Post,
mergedPost: {} as Post,
singleFormData: {} as any,
postPreviewUrl: "",
changeTips: {
title: "",
},
Expand All @@ -79,7 +86,7 @@ const handlePublish = async () => {
formData.actionEnable = false
logger.info("单个常规发布开始")
const processResult = await doSinglePublish(key, id, formData.mergedPost)
const processResult = await doSinglePublish(key, id, formData.publishCfg as IPublishCfg, formData.mergedPost)
logger.info("normal publish processResult =>", processResult)
logger.info("单个常规发布结束")
Expand Down Expand Up @@ -135,7 +142,7 @@ const doDelete = async () => {
formData.isDeleteLoading = true
formData.actionEnable = false
const processResult = await doSingleDelete(key, id)
const processResult = await doSingleDelete(key, id, formData.publishCfg as IPublishCfg)
if (processResult.status) {
// 刷新页面
const platformName = getPlatformName()
Expand All @@ -162,12 +169,12 @@ const doDelete = async () => {
}
const getPlatformName = () => {
const dynCfg = formData.singleFormData?.dynCfg as DynamicConfig
const dynCfg = formData.publishCfg?.dynCfg as DynamicConfig
return dynCfg?.platformName || ""
}
const getBlogName = () => {
const cfg = formData.singleFormData?.cfg as any
const cfg = formData.publishCfg?.cfg as any
return cfg?.blogName || ""
}
Expand Down Expand Up @@ -197,16 +204,24 @@ const refreshChangeTips = () => {
const initPage = async () => {
try {
formData.singleFormData = await doInitPage(key, id, formData.method)
// 初始化属性
formData.publishCfg = await getPublishCfg(key)
const { siyuanPost, platformPost, mergedPost, postPreviewUrl } = await doInitPage(
key,
id,
formData.method,
formData.publishCfg as IPublishCfg
)
// 文章元数据
formData.siyuanPost = formData.singleFormData.siyuanPost
formData.platformPost = formData.singleFormData.platformPost
formData.mergedPost = formData.singleFormData.mergedPost
formData.siyuanPost = siyuanPost
formData.platformPost = platformPost
formData.mergedPost = mergedPost
formData.postPreviewUrl = postPreviewUrl
// 刷新比对提示
refreshChangeTips()
logger.debug("formData.platformPost=>", formData.platformPost)
} catch (e) {
const errMsg = t("main.opt.failure") + "=>" + e
logger.error(errMsg)
Expand Down Expand Up @@ -306,8 +321,8 @@ onMounted(async () => {
</el-button>
<a
v-if="formData.method === MethodEnum.METHOD_EDIT"
:href="formData.singleFormData.previewUrl"
:title="formData.singleFormData.previewUrl"
:href="formData.postPreviewUrl"
:title="formData.postPreviewUrl"
target="_blank"
>{{ t("main.publish.see.preview") }}</a
>
Expand Down
Loading

0 comments on commit 4634b7d

Please sign in to comment.