Skip to content

Commit

Permalink
feat!: add VIP provider mode
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Sep 2, 2024
1 parent 978095b commit 7a7183c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
4 changes: 3 additions & 1 deletion components/static/Detail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ const formData = reactive({

const getPostData = async () => {
const resText = await fetchPostMeta(id, providerMode)
formData.post = JsonUtil.safeParse<Post>(resText, {} as Post)
const currentPost = JsonUtil.safeParse<Post>(resText, {} as Post)
logger.info("currentPost=>", currentPost)
formData.post = currentPost
formData.shareEnabled = !ObjectUtil.isEmptyObject(formData.post)
// logger.info("post=>", formData.post)
// logger.info(`shareEnabled=>${formData.shareEnabled}`)
Expand Down
28 changes: 26 additions & 2 deletions composables/useAuthModeFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,31 @@ export const useAuthModeFetch = () => {
* @param id - 文档 ID
*/
const fetchProviderPostMeta = async (id: string): Promise<string> => {
return "{}"
const apiBase = env.public.providerUrl
const url = "/api/share/getDoc"
const reqUrl = `${apiBase}${url}`
const params = {
fdId: id,
}
let resText = "{}"
try {
const res = await fetch(reqUrl, {
headers: {
"Content-Type": "application/json",
},
method: "POST",
body: JSON.stringify(params),
})
const resJson = await res.json()
if (resJson.code === 0) {
resText = JSON.stringify(resJson.data)
} else {
ElMessage.error("文档获取失败,错误信息如下=>" + resJson.msg)
}
} catch (e) {
logger.error(`fetch provider config ${reqUrl}`, e)
}
return resText
}

/**
Expand Down Expand Up @@ -92,7 +116,7 @@ export const useAuthModeFetch = () => {
logger.info(`fetch config text ${filename} in normal mode`)
resText = await fetchPublicText(filename)
}
logger.info("resText=>", resText)
logger.debug("resText=>", { resText: resText })
return resText
}

Expand Down
2 changes: 1 addition & 1 deletion composables/useStaticShare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const useStaticShare = () => {
const pubicAssetsFolder = `/data/public/siyuan-blog/${pageId}`

// 保存图片附件
await downloadAssetsToPublic(post.editorDom, pubicAssetsFolder)
await downloadAssetsToPublic(post.editorDom ?? "", pubicAssetsFolder)
logger.info("assets downloaded success")

// 只暴露有限的属性
Expand Down

0 comments on commit 7a7183c

Please sign in to comment.