video.cerulea.blue/appview/db.ts
Charlotte Som 2ce74c6391 initial commit: appview fetchVideo implementation
just need to make:
- viewer (very simple - fetch record, fetchVideo, display <video> tag)
- upload/management (need atcute browser oauth client, write to PDS, etcetc)
2025-05-29 21:02:49 +01:00

38 lines
1.1 KiB
TypeScript

import { Database } from "@db/sqlite";
const conn = new Database("./data/video.db");
conn.exec(`pragma journal_mode = WAL;`);
conn.exec(`
CREATE TABLE IF NOT EXISTS allowlist (
repo TEXT NOT NULL UNIQUE PRIMARY KEY -- did
) STRICT;
`);
conn.exec(`
CREATE TABLE IF NOT EXISTS videos (
id INTEGER NOT NULL PRIMARY KEY,
repo TEXT NOT NULL, -- did
cid TEXT NOT NULL, -- blob cid
fetched_at INTEGER NOT NULL DEFAULT (unixepoch()), -- datetime
filename TEXT NOT NULL
) STRICT;
`);
const selectAllowlist = conn.prepare("SELECT 1 FROM allowlist WHERE repo = ?");
const selectVideo = conn.prepare(
"SELECT filename FROM videos WHERE repo = ? AND cid = ?"
);
const insertVideo = conn.prepare(
"INSERT INTO videos (repo, cid, filename) VALUES (?, ?, ?)"
);
export const db = {
db: conn,
inAllowlist: (did: string) =>
(selectAllowlist.value<[boolean]>(did)?.[0] && true) ?? false,
getVideo: (did: string, cid: string) =>
selectVideo.value<[string]>(did, cid)?.[0],
addVideo: (did: string, cid: string, filename: string) =>
insertVideo.run(did, cid, filename),
};