From 201e12ecc3f572181c215b7ce743df8490544fde Mon Sep 17 00:00:00 2001 From: advplyr Date: Wed, 5 Feb 2025 16:15:00 -0600 Subject: [PATCH] Update downloadFile to debug log percentage complete --- server/utils/fileUtils.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/server/utils/fileUtils.js b/server/utils/fileUtils.js index 3725481f..19ac2efe 100644 --- a/server/utils/fileUtils.js +++ b/server/utils/fileUtils.js @@ -286,10 +286,23 @@ module.exports.downloadFile = (url, filepath, contentTypeFilter = null) => { return reject(new Error(`Invalid content type "${response.headers?.['content-type'] || ''}"`)) } + const totalSize = parseInt(response.headers['content-length'], 10) + let downloadedSize = 0 + // Write to filepath const writer = fs.createWriteStream(filepath) response.data.pipe(writer) + let lastProgress = 0 + response.data.on('data', (chunk) => { + downloadedSize += chunk.length + const progress = totalSize ? Math.round((downloadedSize / totalSize) * 100) : 0 + if (progress >= lastProgress + 5) { + Logger.debug(`[fileUtils] File "${Path.basename(filepath)}" download progress: ${progress}% (${downloadedSize}/${totalSize} bytes)`) + lastProgress = progress + } + }) + writer.on('finish', resolve) writer.on('error', reject) })