Compact HE-AAC audio saves: server lane with fdkaac, shrink saved songs from Saved videos

This commit is contained in:
Jonathan Sykes
2026-10-18 17:28:47 +08:00
parent eef9fbf05f
commit b48d36b3dd
12 changed files with 342 additions and 22 deletions

View File

@@ -218,7 +218,7 @@
opts.signal?.addEventListener('abort', abort, { once: true });
worker.onmessage = (e) => {
const m = e.data || {};
if (m.type === 'done') finish({ ok: true, sha256: m.sha256 || null, expectedSha: m.expectedSha || null, size: m.size || 0 });
if (m.type === 'done') finish({ ok: true, sha256: m.sha256 || null, expectedSha: m.expectedSha || null, size: m.size || 0, ext: m.ext || null });
else if (m.type === 'unsupported') finish({ ok: false, fallback: true });
else if (m.type === 'error') finish({ ok: false, error: m.error });
else if (m.type === 'paused') finish({ ok: false, paused: true, received: m.received || 0, error: m.error });
@@ -359,6 +359,21 @@
return items.reduce((s, i) => s + i.size, 0);
},
// Remove this video's other saved files (a different format), keeping
// `keepName` — after a save that replaced e.g. <id>.mp4 with <id>.m4a.
async keepOnly(videoId, keepName) {
try {
const dir = await getRoot();
const drop = [];
for await (const [name, handle] of dir.entries()) {
if (handle.kind !== 'file' || name === keepName || name.endsWith('.part') || name.endsWith('.part.json')) continue;
const dot = name.lastIndexOf('.');
if ((dot > -1 ? name.slice(0, dot) : name) === videoId) drop.push(name);
}
for (const name of drop) await dir.removeEntry(name).catch(() => {});
} catch { /* OPFS not available */ }
},
// Delete one video
async deleteVideo(videoId) {
try {