Replace saved copies that fail to play, reject truncated saves, and re-check the device cache when the app returns to the foreground

This commit is contained in:
Jonathan Sykes
2026-09-18 10:11:20 +08:00
parent 64f45a102d
commit a20dd0a3a6
3 changed files with 141 additions and 7 deletions

View File

@@ -75,6 +75,12 @@ self.onmessage = async (e) => {
} finally {
access.close();
}
// A connection that ends early can close the body cleanly; never commit
// a truncated file, it would be badged "cached" yet fail to play.
const expected = Number(res.headers.get('content-length'));
if (expected > 0 && offset !== expected) {
throw new Error(`download cut short (${offset} of ${expected} bytes)`);
}
// Finalize: .part → permanent name. Prefer the native rename, but treat
// ANY move() failure as "unavailable" and fall back to a chunked copy —