feat(dl): add download progress tracking and reporting

This commit is contained in:
2025-10-03 10:29:34 -04:00
parent 90053b67c5
commit 14a5b50942
2 changed files with 42 additions and 4 deletions

View File

@@ -77,9 +77,37 @@ export async function downloadTrack(
const totalSize = parseInt(response.headers.get('content-length') || '0');
const isCrypted = downloadURL.includes('/mobile/') || downloadURL.includes('/media/');
// Get the response as array buffer
const arrayBuffer = await response.arrayBuffer();
const encryptedData = new Uint8Array(arrayBuffer);
// Stream the response with progress tracking
const reader = response.body!.getReader();
const chunks: Uint8Array[] = [];
let downloadedBytes = 0;
while (true) {
const { done, value } = await reader.read();
if (done) break;
chunks.push(value);
downloadedBytes += value.length;
// Call progress callback
if (onProgress && totalSize > 0) {
const percentage = (downloadedBytes / totalSize) * 100;
console.log(`[Download Progress] ${downloadedBytes}/${totalSize} bytes (${percentage.toFixed(1)}%)`);
onProgress({
downloaded: downloadedBytes,
total: totalSize,
percentage
});
}
}
// Combine chunks into single Uint8Array
const encryptedData = new Uint8Array(downloadedBytes);
let offset = 0;
for (const chunk of chunks) {
encryptedData.set(chunk, offset);
offset += chunk.length;
}
console.log(`Downloaded ${encryptedData.length} bytes, encrypted: ${isCrypted}`);

View File

@@ -338,7 +338,17 @@ export class DeezerQueueManager {
downloadURL,
appSettings.musicFolder!,
appSettings.deezerFormat,
undefined,
(progress) => {
// Update progress in queue
updateQueueItem(item.id, {
progress: progress.percentage,
currentTrack: {
title: track.title,
artist: track.artist,
progress: progress.percentage
}
});
},
0,
trackData.SNG_ID
);