Register devices and report verified holdings to the server

This commit is contained in:
Claude
2026-09-30 07:38:47 +00:00
parent 76e0d2f72d
commit c629ff5836
13 changed files with 513 additions and 2 deletions

View File

@@ -63,6 +63,7 @@ export async function initP2pSchema() {
// media_cache.sha256 — the cid of the current <id>.<gen>.mp4 (plan 009).
try { await db.execute('ALTER TABLE media_cache ADD COLUMN sha256 TEXT'); }
catch (e) { if (!/duplicate column/i.test(String(e.message))) throw e; }
await db.execute('CREATE INDEX IF NOT EXISTS idx_media_sha256 ON media_cache (sha256)');
}
const rowsOf = (r) => r.rows.map((row) => {
@@ -258,3 +259,12 @@ export async function listMediaEvictionOrder({ now, keepMinViews, keepDays, keep
|| (a.last_access - b.last_access));
return rows;
}
// The server's own ready copy whose mp4 has this content id (or null).
export async function findMediaByCid(cid) {
const r = await db.execute({
sql: "SELECT video_id, gen FROM media_cache WHERE sha256 = ? AND status = 'ready' LIMIT 1",
args: [cid],
});
return rowsOf(r)[0] || null;
}