mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-01 02:12:26 +00:00
feat(edit): clean up superseded thumbnail on edit (orphan removal)
Previously editing a video deleted the old hosted video + its .torrent when the
URL changed, but intentionally left the old thumbnail orphaned in the bucket.
Now that the Edit modal can replace a thumbnail (and we have a clear "thumbnail
changed" signal), also delete the superseded thumbnail: build an orphan list with
the old video ({url}) and/or old thumbnail ({thumbnail}) and pass both to
deleteVideoStorage. Each guarded on old & new being non-empty and different, so we
never delete an object the new note still references. Best-effort; never blocks
the edit.
Tests (collectVideoStorageKeys): a {url} orphan yields the video key + sibling
.torrent; a {thumbnail} orphan yields the thumbnail key; both collect together;
objects under a different publicBaseUrl are never collected (bucket-switch safety).
Also documents the pre-existing uploadModal-reset.test.mjs flake in KNOWN_ISSUES
(reproduced on 1b11cb1b; not from this work).
Build + full lint green; full unit suite green except the documented pre-existing
flake.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
1 parent
c8a63c57c6
commit
3aef97f08a
3 files changed
+81
-7
No files matched your search
@@ -92,18 +92,31 @@ export default class EditModalController {
|
||||
pubkey,
|
||||
});
|
||||
|
||||
// Best-effort: if the hosted video URL was genuinely replaced, the old
|
||||
// R2/S3 object (and its .torrent) is now orphaned — remove it. We require
|
||||
// both URLs to be non-empty and different so we never delete an object
|
||||
// that's still referenced (e.g. via a magnet web-seed when the URL was
|
||||
// merely cleared). Thumbnails are intentionally left alone here to avoid
|
||||
// deleting one the new note still points at. Never blocks the edit.
|
||||
// Best-effort: when the hosted video URL and/or thumbnail were genuinely
|
||||
// replaced, the old R2/S3 objects are now orphaned — remove them. For each,
|
||||
// we require both old and new values to be non-empty and different so we
|
||||
// never delete an object the new note still references (e.g. the URL was
|
||||
// merely cleared, or the thumbnail was left unchanged). The video entry
|
||||
// also takes its sibling .torrent. Never blocks the edit.
|
||||
try {
|
||||
const orphans = [];
|
||||
|
||||
const oldUrl = detail.video?.url || "";
|
||||
const newUrl = updatedData?.url || "";
|
||||
if (updatedData?.urlEdited && oldUrl && newUrl && oldUrl !== newUrl) {
|
||||
// collectVideoStorageKeys derives the video key + its .torrent.
|
||||
orphans.push({ url: oldUrl });
|
||||
}
|
||||
|
||||
const oldThumb = detail.video?.thumbnail || "";
|
||||
const newThumb = updatedData?.thumbnail || "";
|
||||
if (oldThumb && newThumb && oldThumb !== newThumb) {
|
||||
orphans.push({ thumbnail: oldThumb });
|
||||
}
|
||||
|
||||
if (orphans.length) {
|
||||
const cleanup = await r2Service.deleteVideoStorage({
|
||||
videos: [{ url: oldUrl }],
|
||||
videos: orphans,
|
||||
pubkey,
|
||||
});
|
||||
if (cleanup?.deleted?.length) {
|
||||
|
||||
Reference in new issue
Block a user