Files
endorphin-tabularium-docs/apps/docs/src/lib/site-database.ts
T
codex-bot 1250b674b0
Verify and deploy Tabularium / verify-and-deploy (pull_request) Failing after 5m57s
Add AI company research workbench backed by the shared site database
2026-10-30 03:25:38 +08:00

21 lines
721 B
TypeScript

import { chmodSync } from "node:fs";
import { dirname, join } from "node:path";
import { DatabaseSync } from "node:sqlite";
// Keep the historical filename so existing authentication state is preserved.
// Research and authentication use different tables in this same site database.
export function openSiteDatabase() {
const configFile = process.env.AUTH_CONFIG_FILE;
if (!configFile) throw new Error("Authentication is not configured");
const file = join(dirname(configFile), "login-state.sqlite");
const db = new DatabaseSync(file);
try {
chmodSync(file, 0o600);
db.exec("PRAGMA busy_timeout=5000; PRAGMA foreign_keys=ON;");
return db;
} catch (error) {
db.close();
throw error;
}
}