NotionAPI调整

This commit is contained in:
tangly1024
2021-10-18 17:09:35 +08:00
parent 7480cef805
commit c25fd702d1
9 changed files with 86 additions and 74 deletions

View File

@@ -2,14 +2,22 @@ import BLOG from '@/blog.config'
import { NotionAPI } from 'notion-client'
import { getDataFromCache, setDataToCache } from '@/lib/cache/cache_manager'
export async function getPostBlocks (id) {
export async function getPostBlocks (id, from) {
let pageBlock = await getDataFromCache('page_block_' + id)
if (pageBlock) {
return pageBlock
}
const authToken = BLOG.notionAccessToken || null
const api = new NotionAPI({ authToken })
pageBlock = await api.getPage(id)
try {
console.log(id, '向Notion请求数据:', from)
pageBlock = await api.getPage(id)
console.log(id, '请求成功:', from)
} catch (error) {
console.error(id, '请求失败:', from, error)
return null
}
if (pageBlock) {
await setDataToCache('page_block_' + id, pageBlock)
}