diff --git a/lib/doodstream-upload.js b/lib/doodstream-upload.js index 525fa5d..b672405 100644 --- a/lib/doodstream-upload.js +++ b/lib/doodstream-upload.js @@ -10,7 +10,7 @@ const UPLOAD_TIMEOUT = 1800000; // 30 min function _debugLog(msg) { try { const ts = new Date().toISOString(); - fs.appendFileSync(path.join(process.cwd(), 'doodstream-debug.log'), `[${ts}] ${msg}\n`); + fs.appendFileSync(path.join(__dirname, '..', 'doodstream-debug.log'), `[${ts}] ${msg}\n`); } catch {} } diff --git a/lib/hosters.js b/lib/hosters.js index 1475818..4ddd685 100644 --- a/lib/hosters.js +++ b/lib/hosters.js @@ -254,6 +254,7 @@ function createUploadBody(filePath, formFields, onProgress, throttle, signal) { yield preambleBuf; const fileStream = fs.createReadStream(filePath, { highWaterMark: CHUNK_SIZE }); for await (const chunk of fileStream) { + if (signal && signal.aborted) throw new Error('Aborted'); if (throttle) await throttle.consume(chunk.length, signal); bytesRead += chunk.length; yield chunk; diff --git a/lib/throttle.js b/lib/throttle.js index c7bc2ac..abb1ad0 100644 --- a/lib/throttle.js +++ b/lib/throttle.js @@ -21,6 +21,7 @@ class Throttle { bytes -= available; } if (bytes > 0) { + if (signal && signal.aborted) return; // Wait 50ms for tokens to refill await new Promise((r) => setTimeout(r, 50)); } diff --git a/lib/updater.js b/lib/updater.js index 40e47d6..a9fc8b6 100644 --- a/lib/updater.js +++ b/lib/updater.js @@ -56,7 +56,8 @@ function findLatestYml(assets) { async function fetchJson(url, signal) { const controller = new AbortController(); const timeout = setTimeout(() => controller.abort(), CHECK_TIMEOUT); - if (signal) signal.addEventListener('abort', () => controller.abort()); + const onAbort = () => controller.abort(); + if (signal) signal.addEventListener('abort', onAbort); try { const res = await fetch(url, { @@ -67,6 +68,7 @@ async function fetchJson(url, signal) { return await res.json(); } finally { clearTimeout(timeout); + if (signal) signal.removeEventListener('abort', onAbort); } } diff --git a/lib/upload-manager.js b/lib/upload-manager.js index 34db135..0f16879 100644 --- a/lib/upload-manager.js +++ b/lib/upload-manager.js @@ -48,13 +48,20 @@ class UploadManager extends EventEmitter { sem.updateLimit(settings.parallelCount); } // Update global throttle if speed limit changed - if (this.globalThrottle) { - const newKbs = (this.globalSettings.globalMaxSpeedKbs || 0); - if (newKbs > 0) { + const newKbs = (this.globalSettings.globalMaxSpeedKbs || 0); + if (newKbs > 0) { + if (this.globalThrottle) { this.globalThrottle.updateRate(newKbs * 1024); } else { - this.globalThrottle = null; + this.globalThrottle = new Throttle(newKbs * 1024); } + } else { + this.globalThrottle = null; + } + // Update global semaphore live + const globalLimit = this._getGlobalParallelLimit(); + if (globalLimit > 0 && this.globalSemaphore) { + this.globalSemaphore.updateLimit(globalLimit); } } @@ -262,7 +269,7 @@ class UploadManager extends EventEmitter { attempt, maxAttempts }); - await this._sleep(2500, signal); + await this._sleep(3000, signal); } const jobStart = Date.now(); diff --git a/main.js b/main.js index 64eff0b..7daf8ec 100644 --- a/main.js +++ b/main.js @@ -577,6 +577,7 @@ ipcMain.handle('start-upload', (_event, payload) => { // This ensures webContents.send() calls from upload events // are not interleaved with the handle() response. process.nextTick(() => { + if (!uploadManager) { debugLog('nextTick: uploadManager was nulled before startBatch'); return; } debugLog('nextTick: calling startBatch now'); uploadManager.startBatch(tasks).catch((err) => { debugLog(`startBatch REJECTED: ${err && err.stack ? err.stack : err}`); diff --git a/renderer/app.js b/renderer/app.js index a78028c..8019037 100644 --- a/renderer/app.js +++ b/renderer/app.js @@ -691,6 +691,7 @@ function sortQueueJobs(jobs) { else if (key === 'host') cmp = a.hoster.localeCompare(b.hoster); else if (key === 'status') cmp = getStatusOrder(a.status) - getStatusOrder(b.status); else if (key === 'speed') cmp = (a.speedKbs || 0) - (b.speedKbs || 0); + else if (key === 'progress') cmp = (a.progress || 0) - (b.progress || 0); return cmp * factor; }); } @@ -1951,12 +1952,11 @@ async function loadHistory() { for (const file of (batch.files || [])) { for (const result of (file.results || [])) { if (result.status === 'aborted' || result.status === 'error') continue; - const isError = result.status === 'error'; historyRowsData.push({ date: dt.text, dateTs: dt.ts, filename: file.name || '', host: result.hoster || '', - link: isError ? `[Fehler] ${result.error || ''}` : (result.download_url || result.embed_url || ''), - isError, order: order++ + link: result.download_url || result.embed_url || '', + isError: false, order: order++ }); } } diff --git a/renderer/index.html b/renderer/index.html index 1c59ee8..fef09db 100644 --- a/renderer/index.html +++ b/renderer/index.html @@ -84,7 +84,7 @@ Zeit Rest Speed - Fortschritt + Fortschritt