Skip to content

Commit 8240b81

Browse files
hotfix(notion): normalize slug/bare notionDocId to dashed UUID
loadCachedPageChunkV2 400s on slug-prefixed or dash-less notionDocIds; normalize to a dashed UUID (as notion-client getPage does) so those pages load too. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 71e99f5 commit 8240b81

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

‎apps/web/lib/notion.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,18 @@ function isForbidden(err: any): boolean {
120120
return status === 403 || /403/.test(err?.message || "");
121121
}
122122

123-
async function loadPageViaCachedChunk(notion: NotionAPI, pageId: string): Promise<any> {
123+
// notionDocIds come in several shapes: bare 32-char hex, dashed UUID, or slug-prefixed
124+
// ("Some-Title-<32hex>"). loadCachedPageChunkV2 wants a dashed UUID and 400s otherwise,
125+
// so normalize to that (notion-client's getPage does the equivalent via parsePageId).
126+
function normalizePageId(pageId: string): string {
127+
const hex = pageId.replace(/[^0-9a-fA-F]/g, "");
128+
if (hex.length < 32) return pageId;
129+
const id = hex.slice(-32).toLowerCase();
130+
return `${id.slice(0, 8)}-${id.slice(8, 12)}-${id.slice(12, 16)}-${id.slice(16, 20)}-${id.slice(20)}`;
131+
}
132+
133+
async function loadPageViaCachedChunk(notion: NotionAPI, rawPageId: string): Promise<any> {
134+
const pageId = normalizePageId(rawPageId);
124135
// notion-client's typed `fetch` reuses auth (token_v2 cookie) and error handling.
125136
const res: any = await notion.fetch({
126137
endpoint: "loadCachedPageChunkV2",

0 commit comments

Comments
 (0)