Skip to content

Commit

Permalink
fix: #765 修复Halo 平台无法设置发布时间的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Oct 11, 2023
1 parent 1b2608d commit acc6dc9
Showing 1 changed file with 12 additions and 12 deletions.
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

0 comments on commit acc6dc9

Please sign in to comment.