mirror of
https://github.com/d0zingcat/nextjs-notion-starter-kit.git
synced 2026-06-08 07:26:54 +00:00
feat: initial webapp structure from notion2site
This commit is contained in:
55
lib/acl.ts
Normal file
55
lib/acl.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { PageProps } from './types'
|
||||
|
||||
export async function pageAcl({
|
||||
site,
|
||||
recordMap,
|
||||
pageId
|
||||
}: PageProps): Promise<PageProps> {
|
||||
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}".`
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user