Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 34 additions & 29 deletions app/[docs_id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>;
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<MarkdownSection[]> = mdContent.then((text) =>
splitMarkdown(text)
);

const initialChatHistories = await getChat(docs_id);
const initialChatHistories = getChat(docs_id);

return (
<ChatHistoryProvider initialChatHistories={initialChatHistories}>
<ChatHistoryProvider initialChatHistories={await initialChatHistories}>
<PageContent
documentContent={mdContent}
splitMdContent={splitMdContent}
documentContent={await mdContent}
splitMdContent={await splitMdContent}
docs_id={docs_id}
/>
</ChatHistoryProvider>
Expand Down
6 changes: 6 additions & 0 deletions app/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) =>
Expand Down