mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-19 15:09:36 +00:00
feat&fix(支持私有页面的数据访问): 使用react-notion-x要求的方式进行NotionAPI的配置
(cherry picked from commit d5ae329e2c3a1e18b5fd5fc3507791be9da9b4ed)
This commit is contained in:
@@ -541,7 +541,8 @@ const BLOG = {
|
|||||||
process.env.NEXT_PUBLIC_DESCRIPTION || '这是一个由NotionNext生成的站点', // 站点描述,被notion中的页面描述覆盖
|
process.env.NEXT_PUBLIC_DESCRIPTION || '这是一个由NotionNext生成的站点', // 站点描述,被notion中的页面描述覆盖
|
||||||
|
|
||||||
// 开发相关
|
// 开发相关
|
||||||
NOTION_ACCESS_TOKEN: process.env.NOTION_ACCESS_TOKEN || '', // Useful if you prefer not to make your database public
|
NOTION_ACTIVE_USER: process.env.NOTION_ACTIVE_USER || '',
|
||||||
|
NOTION_TOKEN_V2: process.env.NOTION_TOKEN_V2 || '', // Useful if you prefer not to make your database public
|
||||||
DEBUG: process.env.NEXT_PUBLIC_DEBUG || false, // 是否显示调试按钮
|
DEBUG: process.env.NEXT_PUBLIC_DEBUG || false, // 是否显示调试按钮
|
||||||
ENABLE_CACHE:
|
ENABLE_CACHE:
|
||||||
process.env.ENABLE_CACHE ||
|
process.env.ENABLE_CACHE ||
|
||||||
|
|||||||
10
lib/notion/getNotionAPI.js
Normal file
10
lib/notion/getNotionAPI.js
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { NotionAPI } from 'notion-client'
|
||||||
|
import BLOG from '@/blog.config'
|
||||||
|
|
||||||
|
export default function getNotionAPI() {
|
||||||
|
return new NotionAPI({
|
||||||
|
activeUser: BLOG.NOTION_ACTIVE_USER || null,
|
||||||
|
authToken: BLOG.NOTION_TOKEN_V2 || null,
|
||||||
|
userTimeZone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
} from '../utils'
|
} from '../utils'
|
||||||
import { extractLangPrefix } from '../utils/pageId'
|
import { extractLangPrefix } from '../utils/pageId'
|
||||||
import { mapImgUrl } from './mapImage'
|
import { mapImgUrl } from './mapImage'
|
||||||
|
import getNotionAPI from '@/lib/notion/getNotionAPI'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取页面元素成员属性
|
* 获取页面元素成员属性
|
||||||
@@ -56,7 +57,7 @@ export default async function getPageProperties(
|
|||||||
case 'person': {
|
case 'person': {
|
||||||
const rawUsers = val.flat()
|
const rawUsers = val.flat()
|
||||||
const users = []
|
const users = []
|
||||||
const api = new NotionAPI({ authToken })
|
const api = getNotionAPI()
|
||||||
|
|
||||||
for (let i = 0; i < rawUsers.length; i++) {
|
for (let i = 0; i < rawUsers.length; i++) {
|
||||||
if (rawUsers[i][0][1]) {
|
if (rawUsers[i][0][1]) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import BLOG from '@/blog.config'
|
|||||||
import { getDataFromCache, setDataToCache } from '@/lib/cache/cache_manager'
|
import { getDataFromCache, setDataToCache } from '@/lib/cache/cache_manager'
|
||||||
import { NotionAPI } from 'notion-client'
|
import { NotionAPI } from 'notion-client'
|
||||||
import { deepClone, delay } from '../utils'
|
import { deepClone, delay } from '../utils'
|
||||||
|
import getNotionAPI from '@/lib/notion/getNotionAPI'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取文章内容
|
* 获取文章内容
|
||||||
@@ -42,11 +43,7 @@ export async function getPageWithRetry(id, from, retryAttempts = 3) {
|
|||||||
retryAttempts < 3 ? `剩余重试次数:${retryAttempts}` : ''
|
retryAttempts < 3 ? `剩余重试次数:${retryAttempts}` : ''
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
const authToken = BLOG.NOTION_ACCESS_TOKEN || null
|
const api = getNotionAPI()
|
||||||
const api = new NotionAPI({
|
|
||||||
authToken,
|
|
||||||
userTimeZone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
||||||
})
|
|
||||||
const start = new Date().getTime()
|
const start = new Date().getTime()
|
||||||
const pageData = await api.getPage(id)
|
const pageData = await api.getPage(id)
|
||||||
const end = new Date().getTime()
|
const end = new Date().getTime()
|
||||||
@@ -166,11 +163,7 @@ export const fetchInBatches = async (ids, batchSize = 100) => {
|
|||||||
ids = [ids]
|
ids = [ids]
|
||||||
}
|
}
|
||||||
|
|
||||||
const authToken = BLOG.NOTION_ACCESS_TOKEN || null
|
const api = getNotionAPI()
|
||||||
const api = new NotionAPI({
|
|
||||||
authToken,
|
|
||||||
userTimeZone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
||||||
})
|
|
||||||
|
|
||||||
let fetchedBlocks = {}
|
let fetchedBlocks = {}
|
||||||
for (let i = 0; i < ids.length; i += batchSize) {
|
for (let i = 0; i < ids.length; i += batchSize) {
|
||||||
|
|||||||
Reference in New Issue
Block a user