Restore an evicted server copy from an online holder
This commit is contained in:
@@ -3,8 +3,10 @@
|
||||
* (docs/p2p-architecture.md flow 7). The ONLY path by which bytes that did
|
||||
* not come from the server's own fetch can become verified content.
|
||||
*
|
||||
* POST /api/p2p/intake (device) { videoId, cid?, size, title?, channel? }
|
||||
* POST /api/p2p/intake (device) { videoId, cid?, size, title?, channel?, restore? }
|
||||
* → { ok, known:true } cid already verified — nothing to send
|
||||
* (unless restore:true and the server
|
||||
* lost its copy — plan 018)
|
||||
* → { ok, ticket, url, expiresAt } PUT the bytes to url within 30 min
|
||||
* PUT /api/p2p/intake/:ticket (device) raw file body
|
||||
* → { ok, cid, adopted } admitted (+ adopted into the media cache)
|
||||
@@ -30,6 +32,7 @@ const clean = (v, max) => String(v || '').replace(/[\u0000-\u001f\u007f<>]+/g, '
|
||||
export function registerIntakeRoutes(app, deps) {
|
||||
const {
|
||||
cfg, p2pDb, gate, requireDevice, validateMedia, admitFile, adopt = null,
|
||||
serverHasCid = async () => true, // (cid) → does the server still hold these bytes?
|
||||
now = () => Date.now(), log = console,
|
||||
} = deps;
|
||||
const tickets = new Map(); // ticket -> { deviceId, videoId, cid, size, expiresAt, busy }
|
||||
@@ -48,7 +51,8 @@ export function registerIntakeRoutes(app, deps) {
|
||||
if (!(size > 0) || size > cfg.intakeMaxBytes) return c.json({ ok: false, error: 'bad size' }, 413);
|
||||
if (cid) {
|
||||
const known = await p2pDb.getContent(cid);
|
||||
if (known && known.status === 'verified') return c.json({ ok: true, known: true });
|
||||
const restore = body.restore === true && known && known.status === 'verified' && !(await serverHasCid(cid));
|
||||
if (known && known.status === 'verified' && !restore) return c.json({ ok: true, known: true });
|
||||
if (known && known.status === 'revoked') return c.json({ ok: false, error: 'revoked' }, 410);
|
||||
}
|
||||
sweep();
|
||||
|
||||
Reference in New Issue
Block a user