mirror of
https://github.com/d0zingcat/nextjs-notion-starter-kit.git
synced 2026-05-13 15:09:47 +00:00
56 lines
1.2 KiB
TypeScript
56 lines
1.2 KiB
TypeScript
import { type PageProps } from './types'
|
|
|
|
export async function pageAcl({
|
|
site,
|
|
recordMap,
|
|
pageId
|
|
}: PageProps): Promise<PageProps | undefined> {
|
|
if (!site) {
|
|
return {
|
|
error: {
|
|
statusCode: 404,
|
|
message: 'Unable to resolve notion site'
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!recordMap) {
|
|
return {
|
|
error: {
|
|
statusCode: 404,
|
|
message: `Unable to resolve page for domain "${site.domain}". Notion page "${pageId}" not found.`
|
|
}
|
|
}
|
|
}
|
|
|
|
const keys = Object.keys(recordMap.block)
|
|
const rootKey = keys[0]
|
|
|
|
if (!rootKey) {
|
|
return {
|
|
error: {
|
|
statusCode: 404,
|
|
message: `Unable to resolve page for domain "${site.domain}". Notion page "${pageId}" invalid data.`
|
|
}
|
|
}
|
|
}
|
|
|
|
const rootValue = recordMap.block[rootKey]?.value
|
|
const rootSpaceId = rootValue?.space_id
|
|
|
|
if (
|
|
rootSpaceId &&
|
|
site.rootNotionSpaceId &&
|
|
rootSpaceId !== site.rootNotionSpaceId
|
|
) {
|
|
if (process.env.NODE_ENV) {
|
|
return {
|
|
error: {
|
|
statusCode: 404,
|
|
message: `Notion page "${pageId}" doesn't belong to the Notion workspace owned by "${site.domain}".`
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|