From 8467c04432e5498bb74632b9d98421b5902f060c Mon Sep 17 00:00:00 2001 From: na-trium-144 <100704180+na-trium-144@users.noreply.github.com> Date: Sun, 26 Oct 2025 22:51:51 +0900 Subject: [PATCH] =?UTF-8?q?fetch=E4=B8=A6=E5=88=97=E5=8C=96=20&=20better-a?= =?UTF-8?q?uth=E3=81=AE=E3=82=AD=E3=83=A3=E3=83=83=E3=82=B7=E3=83=A5?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/[docs_id]/page.tsx | 63 +++++++++++++++++++++++------------------- app/lib/auth.ts | 6 ++++ 2 files changed, 40 insertions(+), 29 deletions(-) diff --git a/app/[docs_id]/page.tsx b/app/[docs_id]/page.tsx index 7cf15dc..cf41646 100644 --- a/app/[docs_id]/page.tsx +++ b/app/[docs_id]/page.tsx @@ -15,43 +15,48 @@ export default async function Page({ }) { const { docs_id } = await params; - let mdContent: string; - try { - if (process.env.NODE_ENV === "development") { - mdContent = await readFile( - join(process.cwd(), "public", "docs", `${docs_id}.md`), - "utf-8" - ); - } else { - const cfAssets = getCloudflareContext().env.ASSETS; - const mdRes = await cfAssets!.fetch( - `https://assets.local/docs/${docs_id}.md` - ); - if (mdRes.ok) { - mdContent = await mdRes.text(); - } else { + let mdContent: Promise; + if (process.env.NODE_ENV === "development") { + mdContent = readFile( + join(process.cwd(), "public", "docs", `${docs_id}.md`), + "utf-8" + ).catch((e) => { + console.error(e); + notFound(); + }); + } else { + const cfAssets = getCloudflareContext().env.ASSETS; + mdContent = cfAssets! + .fetch(`https://assets.local/docs/${docs_id}.md`) + .then(async (res) => { + if (!res.ok) { + notFound(); + } + return res.text(); + }) + .catch((e) => { + console.error(e); notFound(); - } - } - } catch (error) { - console.error(error); - notFound(); + }); } - - mdContent = mdContent.replaceAll( - "{process.env.PYODIDE_PYTHON_VERSION}", - String(pyodideLock.info.python) + mdContent = mdContent.then((text) => + text.replaceAll( + "{process.env.PYODIDE_PYTHON_VERSION}", + String(pyodideLock.info.python) + ) ); - const splitMdContent: MarkdownSection[] = splitMarkdown(mdContent); + const splitMdContent: Promise = mdContent.then((text) => + splitMarkdown(text) + ); - const initialChatHistories = await getChat(docs_id); + const initialChatHistories = getChat(docs_id); return ( - + diff --git a/app/lib/auth.ts b/app/lib/auth.ts index 2bee1c7..479606f 100644 --- a/app/lib/auth.ts +++ b/app/lib/auth.ts @@ -20,6 +20,12 @@ export async function getAuthServer( database: drizzleAdapter(drizzle, { provider: "pg", }), + session: { + cookieCache: { + enabled: true, + maxAge: 5 * 60, + }, + }, plugins: [ anonymous({ onLinkAccount: ({ anonymousUser, newUser }) =>