Skip to content

Commit

Permalink
fix: #754 修复旧挂件发布过的文章无法更新的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Oct 11, 2023
1 parent de10a34 commit 3b12563
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 11 deletions.
29 changes: 24 additions & 5 deletions src/adaptors/api/base/github/commonGithubApiAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { DateUtil, HtmlUtil, StrUtil, YamlUtil } from "zhi-common"
import { toRaw } from "vue"
import { Base64 } from "js-base64"
import { CommonGitlabConfig } from "~/src/adaptors/api/base/gitlab/commonGitlabConfig.ts"
import sypIdUtil from "~/src/utils/sypIdUtil.ts";
import sypIdUtil from "~/src/utils/sypIdUtil.ts"

/**
* Github API 适配器
Expand Down Expand Up @@ -93,12 +93,31 @@ class CommonGithubApiAdaptor extends BaseBlogApi {
this.logger.info("将要最终发送到以下目录 =>", docPath)

// 开始发布
const res = await this.githubClient.publishGithubPage(docPath, post.description)
let finalRes: any
try {
const res = await this.githubClient.publishGithubPage(docPath, post.description)

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

finalRes = res
} catch (e) {
// 失败之后尝试删除旧数据再发一次
try {
await this.deletePost(docPath)
} catch (e) {
this.logger.warn("尝试删除失败,忽略", e)
}
const res2 = await this.githubClient.publishGithubPage(docPath, post.description)
if (!res2?.content?.path) {
throw new Error("重发依旧失败,Github 调用API异常")
}

finalRes = res2
}
return res.content.path

return finalRes.content.path
}

public async getPost(postid: string, useSlug?: boolean): Promise<Post> {
Expand Down
30 changes: 24 additions & 6 deletions src/adaptors/api/base/gitlab/commonGitlabApiAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { StrUtil, YamlUtil } from "zhi-common"
import { toRaw } from "vue"
import { Base64 } from "js-base64"
import { isDev } from "~/src/utils/constants.ts"
import sypIdUtil from "~/src/utils/sypIdUtil.ts";
import sypIdUtil from "~/src/utils/sypIdUtil.ts"

/**
* Gitlab API 适配器
Expand Down Expand Up @@ -95,13 +95,31 @@ class CommonGitlabApiAdaptor extends BaseBlogApi {
this.logger.info("将要最终发送到以下目录 =>", docPath)

// 开始发布
const res = await this.gitlabClient.createRepositoryFile(docPath, post.description)
this.logger.debug("gitlab newPost finished =>", res)
let finalRes: any
try {
const res = await this.gitlabClient.createRepositoryFile(docPath, post.description)
this.logger.debug("gitlab newPost finished =>", res)
if (!res?.file_path) {
throw new Error("Gitlab 调用API异常 =>" + res?.message)
}

if (!res?.file_path) {
throw new Error("Gitlab 调用API异常 =>" + res?.message)
finalRes = res
} catch (e) {
// 失败之后尝试删除旧数据再发一次
try {
await this.deletePost(docPath)
} catch (e) {
this.logger.warn("尝试删除失败,忽略", e)
}
const res2 = await this.gitlabClient.createRepositoryFile(docPath, post.description)
if (!res2?.file_path) {
throw new Error("重发依旧失败,Gitlab 调用API异常 =>" + res2?.message)
}

finalRes = res2
}
return res.file_path

return finalRes.file_path
}

public async getPost(postid: string, useSlug?: boolean): Promise<Post> {
Expand Down

0 comments on commit 3b12563

Please sign in to comment.