Fix bugs found in the audit
- People tiles resolve a bare photo filename to /uploads, via personPhoto - api.ts keeps the Accept header when a request sets its own headers - Feedback hashes IPs with auth.js's salt and client IP helper - Drop the better-sqlite3 fallback (not installed); require Node 22.13+ Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
9d8de0176e
commit
693dd84b6e
6 changed files with 15 additions and 56 deletions
|
|
@ -2,15 +2,12 @@
|
|||
DATABASE
|
||||
|
||||
One SQLite file, opened once at boot and held for the life of
|
||||
the process. Node's own sqlite module is used when it's there
|
||||
(Node 24+), better-sqlite3 otherwise. Their APIs overlap enough
|
||||
that everything below works against either, as long as you:
|
||||
the process, through Node's own node:sqlite (Node 22.13+).
|
||||
House rules:
|
||||
|
||||
• use positional ? parameters, never named ones
|
||||
• pass 0/1 for booleans, never true/false
|
||||
• use tx() rather than db.transaction()
|
||||
|
||||
Those three rules are the whole compatibility story.
|
||||
• use tx(): node:sqlite has no db.transaction()
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { readdirSync, readFileSync } from "node:fs";
|
||||
|
|
@ -20,18 +17,6 @@ import { fileURLToPath } from "node:url";
|
|||
const HERE = dirname(fileURLToPath(import.meta.url));
|
||||
const MIGRATIONS_DIR = join(HERE, "migrations");
|
||||
|
||||
/* ── Driver selection ──────────────────────────────────────── */
|
||||
|
||||
async function loadDriver() {
|
||||
try {
|
||||
const { DatabaseSync } = await import("node:sqlite");
|
||||
return { Driver: DatabaseSync, name: "node:sqlite" };
|
||||
} catch {
|
||||
const { default: BetterSqlite3 } = await import("better-sqlite3");
|
||||
return { Driver: BetterSqlite3, name: "better-sqlite3" };
|
||||
}
|
||||
}
|
||||
|
||||
/* ── Open ──────────────────────────────────────────────────────
|
||||
WAL readers never block the writer, which matters the
|
||||
moment a feedback POST lands mid page-load
|
||||
|
|
@ -42,15 +27,15 @@ async function loadDriver() {
|
|||
───────────────────────────────────────────────────────────── */
|
||||
|
||||
export async function openDatabase(path) {
|
||||
const { Driver, name } = await loadDriver();
|
||||
const db = new Driver(path);
|
||||
const { DatabaseSync } = await import("node:sqlite");
|
||||
const db = new DatabaseSync(path);
|
||||
|
||||
db.exec("PRAGMA journal_mode = WAL");
|
||||
db.exec("PRAGMA foreign_keys = ON");
|
||||
db.exec("PRAGMA synchronous = NORMAL");
|
||||
db.exec("PRAGMA busy_timeout = 5000");
|
||||
|
||||
db.driverName = name;
|
||||
db.driverName = "node:sqlite";
|
||||
return db;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue