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

@@ -51,6 +51,8 @@ import { registerUploadRoutes } from './uploads.js';
import { admitFile } from './p2p-admit.js';
import { P2P } from './p2p-config.js';
import * as p2pDb from './p2p-db.js';
import { registerP2pRoutes } from './p2p-routes.js';
import { sha256Range } from './hash.js';
import * as innertube from './innertube.js';
import QRCode from 'qrcode';
import { createYtdlpPool } from './ytdlp-pool.js';
@@ -1949,6 +1951,18 @@ const uploads = registerUploadRoutes(app, {
});
const isUpload = (id) => uploads.isUploadId(id);
// ============================================================================
// Peer-to-peer sharing — devices + holdings (docs/p2p-architecture.md)
// ============================================================================
async function fileForCid(cid) {
const row = await p2pDb.findMediaByCid(cid);
if (!row) return null;
const path = `${MEDIA_DIR}/${row.video_id}.${row.gen}.mp4`;
const f = Bun.file(path);
return (await f.exists()) ? { path, size: f.size } : null;
}
const p2p = registerP2pRoutes(app, { cfg: P2P, p2pDb, fileForCid, sha256Range });
// ============================================================================
// GET /sw.js — serve the service worker with BUILD_TAG injected
//