feat(media): media put resumes across runs, and a file already up gives its link again
A run already survives a dropped connection by retrying. This covers what one run cannot survive: Ctrl-C, a laptop that sleeps, a relay that is gone for longer than the retries wait. Each file being put has a job under $XDG_CONFIG_HOME/shade/media-pending/, keyed by server, path, size, mtime and options. The job holds: - the sealed copy; - job.json (0600: the seal result with the file key, the read token, and the meta including subtitle grants); - a lock with the pid of the run working on it. A lock left by a dead run is taken over. Running the same command again resumes with the same media id, so the relay already has most of the file. Once the relay has stored it, the copy goes and the grant stays. Putting the file again gives the same link while the relay still serves it, so a season's put run again after it stopped re-sends only what is missing. Jobs untouched for 30 days are removed. Verified with real processes, a 300 MiB file and a file-store relay: - Run 1 was SIGKILLed after 8 of 19 pieces. - Run 2 resumed at 42% and finished. - Run 3 printed "already on the relay, same link". - `media get` returned the file byte-identical, and the library has one item. tests/put-jobs.test.ts (4). media 118, cli 15. All 27 packages type-check. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -125,6 +125,16 @@ in the bucket, so:
|
||||
- An upload counts against the owner's quota from its start. One with no new piece
|
||||
for 24 hours is dropped by the sweep.
|
||||
|
||||
**Across runs, too.** Ctrl-C, a laptop that sleeps, or a relay gone for longer than
|
||||
the retries wait: run the same `shade media put` again and it goes on with the same
|
||||
media id. Each file being put has a job under `$XDG_CONFIG_HOME/shade/media-pending/`
|
||||
(keyed by server, path, size, mtime and options) holding the sealed copy and what a
|
||||
rerun needs (`job.json`, 0600: it holds the file key, like the library). Once the
|
||||
relay has the file, the copy is removed and the grant is kept: putting the same file
|
||||
again gives the same link while the relay still serves it. So running a season's put
|
||||
again after it stopped at episode 7 sends only episodes 7 to 10. Jobs untouched for
|
||||
30 days are removed.
|
||||
|
||||
A file of at most one piece still goes up as one `PUT /v1/media/:id`. The full exchange
|
||||
is described in `packages/shade-media/src/upload.ts`.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user