Skip to content

Commit

Permalink
Merge pull request #783 from terwer/feature/hotfix
Browse files Browse the repository at this point in the history
fix: #754 修复旧挂件发布过的文章无法更新的问题
  • Loading branch information
terwer committed Oct 11, 2023
2 parents fa751e0 + 3b12563 commit bfd7ea1
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 43 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ Publish articles from siyuan-note to platforms such as Yuque, Notion, Cnblogs, W

Support features such as fast publishing, image bed management, platform expansion, smart labels, etc.

🎉 Exciting News: New tool version `1.16.0` is out!
> Latest Feature Release: 🎉 New Publish Tool version `1.17.0` is out! 🚀
- `1.16.0` focuses on enhancing support for **formulas** and **tables** on Zhihu. Additionally, GitHub now allows custom author homepage configuration.
- `1.15.1` addresses minor issues like fixing publishing errors on Juejin, handling anomalies during article deletion, and resolving tag duplication during article editing.
- Introducing support for the Halo platform! After upgrading to `1.15.0+`, you can seamlessly publish content to Halo2 sites.
- In `1.15.0`, fixes were made for misinterpretation of YAML in certain scenarios and publishing errors on platforms when tags were empty.
- Oh, by the way, starting from version `1.14.0`, the author secretly developed an import feature. You can swiftly import built-in platforms using the `Settings` -> `Publish Settings` -> `Import Predefined Platforms` feature 😄.
**This might be the most worthwhile update since the National Day. 😄**

- In `1.17.0`, the following significant changes have been made:
- Optimization and support for AI effects.
- Persistence of preference settings, eliminating concerns about preference configuration being invalidated due to restarts or other situations.
- Resolved the issue where Halo publication times were not taking effect.
- Fixed the problem of articles previously published with old widgets not being updatable.
- Ah, by the way, since version `1.14.0`, the author secretly developed an import feature. You can swiftly import built-in platforms using the `Settings` -> `Publish Settings` -> `Import Predefined Platforms` feature. 😄

> Platform Limitations:
- **WeChat Official Accounts**: Publishing Tool now supports posting articles to the WeChat Official Accounts draft box in version `1.13.0` and beyond. However, due to limitations on the WeChat platform in Electron, normal login operations are not possible. Therefore, you will need to visit `https://mp.weixin.qq.com/` yourself, complete the login, copy the cookie, and then paste it into the configuration options.
Expand Down
13 changes: 8 additions & 5 deletions README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@

将思源笔记的文章发布到语雀、Notion、Cnblogs、WordPress、Typecho、Hexo、知乎 等平台,支持极速发布、图床管理、平台扩展、智能标签等特色功能。

> 最近的新特性版本:🎉 发布工具新版本 `1.16.0` 发布
> 最近的新特性版本:🎉 发布工具新版本 `1.17.0` 发布
**这可能是国庆之后您最值得升级的一个版本。😄**

- `1.16.0` 主要对知乎平台进行**公式****表格**支持。另外,对于GitHub,也支持配置自定义作者主页了。
- `1.15.1` 小版本修复掘金平台发布错误的问题,部分场景下文章删除异常问题,以及文章编辑时候标签重复问题。
- 新增 Halo 平台,升级到 `1.15.0+` 之后可发布到 Halo2 站点。
- `1.15.0` 修复了 yaml 部分场景误解析、标签为空的时候部分平台发布错误的问题。
- `1.17.0` 主要有以下重要变更:
- 对AI效果进行了优化支持。
- 偏好设置进行持久化,再也不用担心重启或者其他情况导致的偏好配置失效的问题了。
- 修复了 Halo 发布时间未生效问题。
- 修复了旧挂件发布过的文章无法更新的问题。
- 咳咳,另外,在 `1.14.0` 版本之后,作者还悄悄开发了导入功能。您可以使用 `设置` -> `发布设置` -> `导入预定义平台` 功能快速导入内置平台😄

> 平台限制说明
Expand Down
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
24 changes: 12 additions & 12 deletions src/adaptors/api/halo/HaloApiAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,8 @@ import { Attachment, CategoryInfo, MediaObject, Post, UserBlog } from "zhi-blog-
import { AliasTranslator, JsonUtil, ObjectUtil, StrUtil } from "zhi-common"
import { Base64 } from "js-base64"
import sypIdUtil from "~/src/utils/sypIdUtil.ts"
import {
Category,
CategoryList,
ListedPost,
ListedPostList,
Policy,
PostRequest,
Tag,
TagList,
} from "@halo-dev/api-client"
import { PostRequest } from "@halo-dev/api-client"
import { HaloPostMeta } from "~/src/adaptors/api/halo/HaloPostMeta.ts"
import HaloUtils from "~/src/adaptors/api/halo/haloUtils.ts"

/**
* Halo API 适配器
Expand Down Expand Up @@ -137,6 +127,9 @@ class HaloApiAdaptor extends BaseBlogApi {
throw e
}

// 发布时间
params.post.spec.publishTime = post.dateCreated.toISOString()

// 草稿
const res = await this.haloRequest("/apis/api.console.halo.run/v1alpha1/posts", params, "POST")
this.logger.debug("halo newPost res =>", res)
Expand Down Expand Up @@ -197,12 +190,19 @@ class HaloApiAdaptor extends BaseBlogApi {
params.post.spec.tags = tagNames
}

// 发布时间
params.post.spec.publishTime = post.dateCreated.toISOString()

// 更新文章信息
await this.haloRequest(`/apis/content.halo.run/v1alpha1/posts/${name}`, params.post, "PUT")
await this.haloRequest(`/apis/api.console.halo.run/v1alpha1/posts/${name}/content`, params.content, "PUT")

// 重新发布
await this.haloRequest(`/apis/api.console.halo.run/v1alpha1/posts/${params.post.metadata.name}/publish`, {}, "PUT")
await this.haloRequest(
`/apis/api.console.halo.run/v1alpha1/posts/${params.post.metadata.name}/publish`,
{},
"PUT"
)
this.logger.debug("halo 文章发布完成")
} catch (e) {
this.logger.error("Halo文章更新失败", e)
Expand Down
4 changes: 2 additions & 2 deletions src/stores/common/jsonStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import { JsonUtil } from "zhi-common"
* https://github.com/vueuse/vueuse/blob/main/packages/core/ssr-handlers.ts#L11
*
* @author terwer
* @version 1.7.0
* @since 1.7.0
* @version 1.17.0
* @since 1.17.0
*/
class JsonStorage implements StorageLike {
private readonly logger: any
Expand Down
14 changes: 7 additions & 7 deletions src/stores/common/useCommonLocalStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@
* or visit www.terwer.space if you need additional information or have any
* questions.
*/
import type {MaybeRefOrGetter, RemovableRef} from "@vueuse/shared"
import type {StorageLike, UseStorageOptions} from "@vueuse/core"
import {defaultWindow, useStorage} from "@vueuse/core"
import type { MaybeRefOrGetter, RemovableRef } from "@vueuse/shared"
import type { StorageLike, UseStorageOptions } from "@vueuse/core"
import { defaultWindow, useStorage } from "@vueuse/core"
import JsonStorage from "~/src/stores/common/jsonStorage.ts"
import {createAppLogger} from "~/src/utils/appLogger.ts"
import {useSiyuanDevice} from "~/src/composables/useSiyuanDevice.ts"
import { createAppLogger } from "~/src/utils/appLogger.ts"
import { useSiyuanDevice } from "~/src/composables/useSiyuanDevice.ts"

const logger = createAppLogger("use-common-local-storage")

/**
* 通用响应式的 LocalStorage.
* 通用响应式的 LocalStorage
*
* @see https://vueuse.org/useCommonLocalStorage
* @see https://vueuse.org/useLocalStorage
* @param filePath json文件存储位置,可选,浏览器环境忽略此参数
* @param key key
* @param initialValue 初始值
Expand Down

0 comments on commit bfd7ea1

Please sign in to comment.