fix(downloads): include trickplay files in the storage usage total

This commit is contained in:
Gauvain
2026-07-15 00:33:49 +02:00
parent 9b07d39d4d
commit c4a5c05949

View File

@@ -97,6 +97,9 @@ export function getDownloadedItemSize(id: string): number {
export function calculateTotalDownloadedSize(): number { export function calculateTotalDownloadedSize(): number {
const items = getAllDownloadedItems(); const items = getAllDownloadedItems();
return items.reduce((sum, item) => { return items.reduce((sum, item) => {
// Trickplay bytes count too — getDownloadedItemSize models per-item size
// as video + trickplay, the total must match.
const trickplaySize = item.trickPlayData?.size ?? 0;
// Read the live file size on disk so the total reflects actual usage and // Read the live file size on disk so the total reflects actual usage and
// self-heals items whose stored videoFileSize is 0 (old schema, or // self-heals items whose stored videoFileSize is 0 (old schema, or
// `fileInfo.size` was undefined at download time). Fall back to the stored // `fileInfo.size` was undefined at download time). Fall back to the stored
@@ -105,12 +108,12 @@ export function calculateTotalDownloadedSize(): number {
try { try {
const file = new File(filePathToUri(item.videoFilePath)); const file = new File(filePathToUri(item.videoFilePath));
if (file.exists) { if (file.exists) {
return sum + (file.size ?? item.videoFileSize ?? 0); return sum + (file.size ?? item.videoFileSize ?? 0) + trickplaySize;
} }
} catch (error) { } catch (error) {
console.warn("Failed to stat downloaded file for size:", error); console.warn("Failed to stat downloaded file for size:", error);
} }
} }
return sum + (item.videoFileSize ?? 0); return sum + (item.videoFileSize ?? 0) + trickplaySize;
}, 0); }, 0);
} }