Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
127807d62a | ||
|
|
6cd7498f70 | ||
|
|
ddf2710fc6 | ||
|
|
0f57aef7c7 | ||
|
|
f0608dcda1 | ||
|
|
9b10a4356f | ||
|
|
d159ac484a | ||
|
|
f4b5fadc5f | ||
|
|
169817f707 | ||
|
|
1418c2bc17 | ||
|
|
8d33141294 | ||
|
|
35341b522a | ||
|
|
f9aa7f4168 | ||
|
|
d9199f8aaf | ||
|
|
ba4642e09a | ||
|
|
d59c5c1df8 | ||
|
|
4bb18f7abc | ||
|
|
125e5f55ea |
@ -277,7 +277,12 @@ class ConfigStore {
|
|||||||
if (fs.existsSync(this.filePath)) {
|
if (fs.existsSync(this.filePath)) {
|
||||||
const existing = fs.readFileSync(this.filePath, 'utf-8');
|
const existing = fs.readFileSync(this.filePath, 'utf-8');
|
||||||
if (existing && existing.trim().length > 2) {
|
if (existing && existing.trim().length > 2) {
|
||||||
fs.writeFileSync(backupPath, existing, 'utf-8');
|
let isValid = false;
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(existing);
|
||||||
|
isValid = parsed && typeof parsed === 'object' && (parsed.hosters || parsed.hosterSettings || parsed.globalSettings);
|
||||||
|
} catch {}
|
||||||
|
if (isValid) fs.writeFileSync(backupPath, existing, 'utf-8');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {}
|
} catch {}
|
||||||
|
|||||||
@ -499,25 +499,28 @@ async function _resolveDoodstreamUploadByName(apiKey, fileName, baselineCodes, s
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function uploadFile(hosterName, filePath, apiKey, onProgress, signal, throttle) {
|
async function uploadFile(hosterName, filePath, apiKey, onProgress, signal, throttle, opts) {
|
||||||
const config = HOSTER_CONFIGS[hosterName];
|
const config = HOSTER_CONFIGS[hosterName];
|
||||||
if (!config) throw new Error(`Unbekannter Hoster: ${hosterName}`);
|
if (!config) throw new Error(`Unbekannter Hoster: ${hosterName}`);
|
||||||
|
|
||||||
// For byse: snapshot the current file-code list so the post-upload poller
|
|
||||||
// can identify new arrivals even when the initial POST response has an
|
|
||||||
// empty filecode.
|
|
||||||
let byseBaseline = null;
|
let byseBaseline = null;
|
||||||
if (hosterName === 'byse.sx') {
|
if (hosterName === 'byse.sx') {
|
||||||
|
if (opts && opts.byseBaseline instanceof Set) {
|
||||||
|
byseBaseline = opts.byseBaseline;
|
||||||
|
} else {
|
||||||
const baseline = await _fetchByseFileList(apiKey, signal);
|
const baseline = await _fetchByseFileList(apiKey, signal);
|
||||||
byseBaseline = new Set(baseline.map(f => f.file_code));
|
byseBaseline = new Set(baseline.map(f => f.file_code));
|
||||||
}
|
}
|
||||||
// Doodstream: same snapshot so a codeless upload response can be recovered by
|
}
|
||||||
// matching a newly-appeared file in the account by name (see below).
|
|
||||||
let doodBaseline = null;
|
let doodBaseline = null;
|
||||||
if (hosterName === 'doodstream.com') {
|
if (hosterName === 'doodstream.com') {
|
||||||
|
if (opts && opts.doodBaseline instanceof Set) {
|
||||||
|
doodBaseline = opts.doodBaseline;
|
||||||
|
} else {
|
||||||
const baseline = await _fetchDoodstreamFileList(apiKey, signal);
|
const baseline = await _fetchDoodstreamFileList(apiKey, signal);
|
||||||
doodBaseline = new Set(baseline.map(f => f.file_code));
|
doodBaseline = new Set(baseline.map(f => f.file_code));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Step 1: Get upload server
|
// Step 1: Get upload server
|
||||||
const uploadUrl = await getUploadServer(hosterName, config, apiKey, signal);
|
const uploadUrl = await getUploadServer(hosterName, config, apiKey, signal);
|
||||||
@ -647,8 +650,23 @@ async function uploadFile(hosterName, filePath, apiKey, onProgress, signal, thro
|
|||||||
throw new Error(msg);
|
throw new Error(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function prefetchBaseline(hosterName, apiKey, signal) {
|
||||||
|
try {
|
||||||
|
if (hosterName === 'byse.sx') {
|
||||||
|
const baseline = await _fetchByseFileList(apiKey, signal);
|
||||||
|
return new Set(baseline.map(f => f.file_code));
|
||||||
|
}
|
||||||
|
if (hosterName === 'doodstream.com') {
|
||||||
|
const baseline = await _fetchDoodstreamFileList(apiKey, signal);
|
||||||
|
return new Set(baseline.map(f => f.file_code));
|
||||||
|
}
|
||||||
|
} catch { /* leave caller to fall back to per-job fetch */ }
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
uploadFile,
|
uploadFile,
|
||||||
|
prefetchBaseline,
|
||||||
HOSTER_CONFIGS,
|
HOSTER_CONFIGS,
|
||||||
__test: {
|
__test: {
|
||||||
extractUploadServerUrl,
|
extractUploadServerUrl,
|
||||||
|
|||||||
@ -233,7 +233,20 @@ async function installUpdate(onProgress) {
|
|||||||
// Stage: done
|
// Stage: done
|
||||||
if (onProgress) onProgress({ stage: 'done', percent: 100 });
|
if (onProgress) onProgress({ stage: 'done', percent: 100 });
|
||||||
|
|
||||||
setTimeout(() => app.quit(), 900);
|
const _doQuit = () => setTimeout(() => app.quit(), 900);
|
||||||
|
const _getActive = () => {
|
||||||
|
try { return globalThis._mhuUploadManagerRef && globalThis._mhuUploadManagerRef.getActiveJobCount ? globalThis._mhuUploadManagerRef.getActiveJobCount() : 0; }
|
||||||
|
catch { return 0; }
|
||||||
|
};
|
||||||
|
if (_getActive() > 0) {
|
||||||
|
const POLL_MS = 3000;
|
||||||
|
const poller = setInterval(() => {
|
||||||
|
if (_getActive() === 0) { clearInterval(poller); _doQuit(); }
|
||||||
|
}, POLL_MS);
|
||||||
|
setTimeout(() => { try { clearInterval(poller); } catch {} _doQuit(); }, 30 * 60 * 1000);
|
||||||
|
} else {
|
||||||
|
_doQuit();
|
||||||
|
}
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (onProgress) onProgress({ stage: 'error', error: err.message });
|
if (onProgress) onProgress({ stage: 'error', error: err.message });
|
||||||
|
|||||||
@ -2,7 +2,7 @@ const { EventEmitter } = require('events');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const { uploadFile } = require('./hosters');
|
const { uploadFile, prefetchBaseline } = require('./hosters');
|
||||||
const VidmolyUploader = require('./vidmoly-upload');
|
const VidmolyUploader = require('./vidmoly-upload');
|
||||||
const VoeUploader = require('./voe-upload');
|
const VoeUploader = require('./voe-upload');
|
||||||
const DoodstreamUploader = require('./doodstream-upload');
|
const DoodstreamUploader = require('./doodstream-upload');
|
||||||
@ -42,6 +42,7 @@ class UploadManager extends EventEmitter {
|
|||||||
this._failedAccounts = new Map(); // hoster -> Set of failed accountIds
|
this._failedAccounts = new Map(); // hoster -> Set of failed accountIds
|
||||||
this._accountOverrides = new Map(); // hoster -> fallback account object
|
this._accountOverrides = new Map(); // hoster -> fallback account object
|
||||||
this._doodApiKeyCache = new Map(); // accountId/username -> derived doodstream API key ('' = tried, none)
|
this._doodApiKeyCache = new Map(); // accountId/username -> derived doodstream API key ('' = tried, none)
|
||||||
|
this._baselineCache = new Map(); // hoster:apiKey -> Promise<Set<file_code>> (one fetch shared across all jobs in batch)
|
||||||
}
|
}
|
||||||
|
|
||||||
switchAccount(hoster, fallbackAccount) {
|
switchAccount(hoster, fallbackAccount) {
|
||||||
@ -66,6 +67,10 @@ class UploadManager extends EventEmitter {
|
|||||||
return this._accountOverrides.get(hoster) || null;
|
return this._accountOverrides.get(hoster) || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getActiveJobCount() {
|
||||||
|
return this.activeJobs.size;
|
||||||
|
}
|
||||||
|
|
||||||
clearFailedAccount(hoster, accountId) {
|
clearFailedAccount(hoster, accountId) {
|
||||||
return this._failedAccounts.delete(`${hoster}:${accountId}`);
|
return this._failedAccounts.delete(`${hoster}:${accountId}`);
|
||||||
}
|
}
|
||||||
@ -278,6 +283,7 @@ class UploadManager extends EventEmitter {
|
|||||||
this.jobAbortControllers.clear();
|
this.jobAbortControllers.clear();
|
||||||
this.cancelledJobIds.clear();
|
this.cancelledJobIds.clear();
|
||||||
this._doodApiKeyCache.clear(); // re-derive doodstream keys fresh each batch
|
this._doodApiKeyCache.clear(); // re-derive doodstream keys fresh each batch
|
||||||
|
this._baselineCache.clear(); // re-fetch baselines per batch (a long batch could outlast remote-side relevance)
|
||||||
this.semaphores = {};
|
this.semaphores = {};
|
||||||
this.globalSemaphore = null;
|
this.globalSemaphore = null;
|
||||||
this.globalThrottle = null;
|
this.globalThrottle = null;
|
||||||
@ -308,18 +314,32 @@ class UploadManager extends EventEmitter {
|
|||||||
this._batchResults = results;
|
this._batchResults = results;
|
||||||
this._additionalPromises = []; // Track jobs added mid-batch via addJobs()
|
this._additionalPromises = []; // Track jobs added mid-batch via addJobs()
|
||||||
|
|
||||||
for (const task of tasks) {
|
const DEDUP_CHUNK = 200;
|
||||||
const fileName = path.basename(task.file);
|
for (let i = 0; i < tasks.length; i += DEDUP_CHUNK) {
|
||||||
|
if (signal.aborted) break;
|
||||||
|
const end = Math.min(i + DEDUP_CHUNK, tasks.length);
|
||||||
|
for (let j = i; j < end; j++) {
|
||||||
|
const task = tasks[j];
|
||||||
if (!results.has(task.file)) {
|
if (!results.has(task.file)) {
|
||||||
|
const fileName = path.basename(task.file);
|
||||||
let size = 0;
|
let size = 0;
|
||||||
try { size = fs.statSync(task.file).size; } catch {}
|
try { size = fs.statSync(task.file).size; } catch {}
|
||||||
results.set(task.file, { name: fileName, size, results: [] });
|
results.set(task.file, { name: fileName, size, results: [] });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (end < tasks.length) await new Promise(setImmediate);
|
||||||
|
}
|
||||||
|
|
||||||
this._startStatsTimer();
|
this._startStatsTimer();
|
||||||
|
|
||||||
const promises = tasks.map((task) => this._runJob(task, results, signal));
|
const SPAWN_CHUNK = 100;
|
||||||
|
const promises = [];
|
||||||
|
for (let i = 0; i < tasks.length; i += SPAWN_CHUNK) {
|
||||||
|
if (signal.aborted) break;
|
||||||
|
const end = Math.min(i + SPAWN_CHUNK, tasks.length);
|
||||||
|
for (let j = i; j < end; j++) promises.push(this._runJob(tasks[j], results, signal));
|
||||||
|
if (end < tasks.length) await new Promise(setImmediate);
|
||||||
|
}
|
||||||
await Promise.allSettled(promises);
|
await Promise.allSettled(promises);
|
||||||
// Wait for any jobs added mid-batch via addJobs()
|
// Wait for any jobs added mid-batch via addJobs()
|
||||||
while (this._additionalPromises.length > 0) {
|
while (this._additionalPromises.length > 0) {
|
||||||
@ -355,7 +375,12 @@ class UploadManager extends EventEmitter {
|
|||||||
const fileName = path.basename(task.file);
|
const fileName = path.basename(task.file);
|
||||||
let fileSize = 0;
|
let fileSize = 0;
|
||||||
let fileNotFound = false;
|
let fileNotFound = false;
|
||||||
|
const cachedResult = results && results.get(task.file);
|
||||||
|
if (cachedResult && typeof cachedResult.size === 'number' && cachedResult.size > 0) {
|
||||||
|
fileSize = cachedResult.size;
|
||||||
|
} else {
|
||||||
try { fileSize = fs.statSync(task.file).size; } catch { fileNotFound = true; }
|
try { fileSize = fs.statSync(task.file).size; } catch { fileNotFound = true; }
|
||||||
|
}
|
||||||
|
|
||||||
const maxAttempts = Math.max(1, (settings.retries || 0) + 1);
|
const maxAttempts = Math.max(1, (settings.retries || 0) + 1);
|
||||||
const jobAbortController = new AbortController();
|
const jobAbortController = new AbortController();
|
||||||
@ -420,23 +445,13 @@ class UploadManager extends EventEmitter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._emitProgress(uploadId, fileName, task.hoster, { accountId: task.accountId,
|
// The initial 'queued' emit per job is suppressed: with N=2000+ tasks
|
||||||
jobId,
|
// it produces 2000+ main→renderer IPCs back-to-back at startBatch and
|
||||||
status: 'queued',
|
// freezes the renderer event loop for tens of seconds. The renderer
|
||||||
progress: 0,
|
// already holds each job in 'queued'/'preview' state from its own
|
||||||
bytesUploaded: 0,
|
// queueJobs array; the first event it actually needs from main is the
|
||||||
bytesTotal: fileSize,
|
// 'getting-server' / 'uploading' transition for the jobs that the
|
||||||
speedKbs: 0,
|
// semaphore lets through.
|
||||||
elapsed: 0,
|
|
||||||
remaining: 0,
|
|
||||||
error: null,
|
|
||||||
result: null,
|
|
||||||
attempt: 0,
|
|
||||||
maxAttempts
|
|
||||||
});
|
|
||||||
|
|
||||||
// Acquire hoster semaphore first so jobs waiting for a hoster slot
|
|
||||||
// don't waste global slots (prevents underutilization)
|
|
||||||
await hosterSemaphore.acquire(signal);
|
await hosterSemaphore.acquire(signal);
|
||||||
hosterSlotAcquired = true;
|
hosterSlotAcquired = true;
|
||||||
|
|
||||||
@ -545,6 +560,7 @@ class UploadManager extends EventEmitter {
|
|||||||
speedAbort = new AbortController();
|
speedAbort = new AbortController();
|
||||||
uploadSignalBundle = this._combineManySignals([signal, speedAbort.signal]);
|
uploadSignalBundle = this._combineManySignals([signal, speedAbort.signal]);
|
||||||
speedMonitor = setInterval(() => {
|
speedMonitor = setInterval(() => {
|
||||||
|
try {
|
||||||
if (currentSpeedKbs > 0 && currentSpeedKbs < settings.restartBelowKbs) {
|
if (currentSpeedKbs > 0 && currentSpeedKbs < settings.restartBelowKbs) {
|
||||||
if (!lowSpeedSince) lowSpeedSince = Date.now();
|
if (!lowSpeedSince) lowSpeedSince = Date.now();
|
||||||
if (Date.now() - lowSpeedSince > 6000) {
|
if (Date.now() - lowSpeedSince > 6000) {
|
||||||
@ -553,6 +569,7 @@ class UploadManager extends EventEmitter {
|
|||||||
} else {
|
} else {
|
||||||
lowSpeedSince = 0;
|
lowSpeedSince = 0;
|
||||||
}
|
}
|
||||||
|
} catch (e) { this._rotLog('speed-monitor-error', { jobId, error: e && e.message }); }
|
||||||
}, 2000);
|
}, 2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -566,10 +583,11 @@ class UploadManager extends EventEmitter {
|
|||||||
const PROGRESS_EMIT_INTERVAL = 250; // ms – throttle UI updates
|
const PROGRESS_EMIT_INTERVAL = 250; // ms – throttle UI updates
|
||||||
|
|
||||||
const progressCb = (bytesUploaded, bytesTotal) => {
|
const progressCb = (bytesUploaded, bytesTotal) => {
|
||||||
|
try {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const elapsed = Math.round((now - jobStart) / 1000);
|
const elapsed = Math.round((now - jobStart) / 1000);
|
||||||
const timeDelta = (now - lastSpeedTime) / 1000;
|
const timeDelta = (now - lastSpeedTime) / 1000;
|
||||||
if (timeDelta >= 1) {
|
if (Number.isFinite(timeDelta) && timeDelta >= 1) {
|
||||||
const bytesDelta = bytesUploaded - lastBytes;
|
const bytesDelta = bytesUploaded - lastBytes;
|
||||||
currentSpeedKbs = Math.round(bytesDelta / timeDelta / 1024);
|
currentSpeedKbs = Math.round(bytesDelta / timeDelta / 1024);
|
||||||
lastBytes = bytesUploaded;
|
lastBytes = bytesUploaded;
|
||||||
@ -579,7 +597,6 @@ class UploadManager extends EventEmitter {
|
|||||||
activeEntry.speedKbs = currentSpeedKbs;
|
activeEntry.speedKbs = currentSpeedKbs;
|
||||||
activeEntry.bytesUploaded = bytesUploaded;
|
activeEntry.bytesUploaded = bytesUploaded;
|
||||||
|
|
||||||
// Throttle progress emissions to reduce IPC + rendering overhead
|
|
||||||
if (now - lastEmitTime < PROGRESS_EMIT_INTERVAL) return;
|
if (now - lastEmitTime < PROGRESS_EMIT_INTERVAL) return;
|
||||||
lastEmitTime = now;
|
lastEmitTime = now;
|
||||||
|
|
||||||
@ -601,6 +618,7 @@ class UploadManager extends EventEmitter {
|
|||||||
attempt,
|
attempt,
|
||||||
maxAttempts
|
maxAttempts
|
||||||
});
|
});
|
||||||
|
} catch { /* progress callbacks must never throw — swallowing is correct, the stream keeps going */ }
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = await this._executeUpload(task, progressCb, uploadSignalBundle.signal, throttle);
|
const result = await this._executeUpload(task, progressCb, uploadSignalBundle.signal, throttle);
|
||||||
@ -924,7 +942,9 @@ class UploadManager extends EventEmitter {
|
|||||||
const apiKey = await this._resolveDoodstreamApiKey(task);
|
const apiKey = await this._resolveDoodstreamApiKey(task);
|
||||||
if (apiKey) {
|
if (apiKey) {
|
||||||
this._rotLog('doodstream-via-api', { accountId: task.accountId, fileName: path.basename(task.file) });
|
this._rotLog('doodstream-via-api', { accountId: task.accountId, fileName: path.basename(task.file) });
|
||||||
return uploadFile('doodstream.com', task.file, apiKey, progressCb, signal, throttle);
|
return uploadFile('doodstream.com', task.file, apiKey, progressCb, signal, throttle, {
|
||||||
|
doodBaseline: await this._getBaseline('doodstream.com', apiKey, signal)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
this._rotLog('doodstream-via-web', { accountId: task.accountId, fileName: path.basename(task.file) });
|
this._rotLog('doodstream-via-web', { accountId: task.accountId, fileName: path.basename(task.file) });
|
||||||
const dood = new DoodstreamUploader();
|
const dood = new DoodstreamUploader();
|
||||||
@ -934,10 +954,23 @@ class UploadManager extends EventEmitter {
|
|||||||
const clouddrop = new ClouddropUploader(task.apiKey);
|
const clouddrop = new ClouddropUploader(task.apiKey);
|
||||||
return clouddrop.upload(task.file, progressCb, signal, throttle);
|
return clouddrop.upload(task.file, progressCb, signal, throttle);
|
||||||
} else {
|
} else {
|
||||||
return uploadFile(task.hoster, task.file, task.apiKey, progressCb, signal, throttle);
|
const baselineOpts = {};
|
||||||
|
if (task.hoster === 'byse.sx') baselineOpts.byseBaseline = await this._getBaseline('byse.sx', task.apiKey, signal);
|
||||||
|
if (task.hoster === 'doodstream.com') baselineOpts.doodBaseline = await this._getBaseline('doodstream.com', task.apiKey, signal);
|
||||||
|
return uploadFile(task.hoster, task.file, task.apiKey, progressCb, signal, throttle, baselineOpts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_getBaseline(hosterName, apiKey, signal) {
|
||||||
|
if (!apiKey) return Promise.resolve(null);
|
||||||
|
const key = `${hosterName}:${apiKey}`;
|
||||||
|
let pending = this._baselineCache.get(key);
|
||||||
|
if (pending) return pending;
|
||||||
|
pending = prefetchBaseline(hosterName, apiKey, signal);
|
||||||
|
this._baselineCache.set(key, pending);
|
||||||
|
return pending;
|
||||||
|
}
|
||||||
|
|
||||||
// Resolve (and cache per batch) the doodstream API key for a login-only
|
// Resolve (and cache per batch) the doodstream API key for a login-only
|
||||||
// account by logging in once and scraping+validating it from the session.
|
// account by logging in once and scraping+validating it from the session.
|
||||||
// Returns the key string, or '' when none could be derived (cached either way
|
// Returns the key string, or '' when none could be derived (cached either way
|
||||||
@ -967,7 +1000,7 @@ class UploadManager extends EventEmitter {
|
|||||||
_startStatsTimer() {
|
_startStatsTimer() {
|
||||||
if (this.statsInterval) clearInterval(this.statsInterval);
|
if (this.statsInterval) clearInterval(this.statsInterval);
|
||||||
this.statsInterval = setInterval(() => {
|
this.statsInterval = setInterval(() => {
|
||||||
// Single pass over active jobs instead of two.
|
try {
|
||||||
let globalSpeedKbs = 0;
|
let globalSpeedKbs = 0;
|
||||||
let activeCount = 0;
|
let activeCount = 0;
|
||||||
let inProgressBytes = 0;
|
let inProgressBytes = 0;
|
||||||
@ -987,6 +1020,7 @@ class UploadManager extends EventEmitter {
|
|||||||
activeJobs: activeCount,
|
activeJobs: activeCount,
|
||||||
pendingJobs: Object.values(this.semaphores).reduce((sum, semaphore) => sum + semaphore.pending, 0)
|
pendingJobs: Object.values(this.semaphores).reduce((sum, semaphore) => sum + semaphore.pending, 0)
|
||||||
});
|
});
|
||||||
|
} catch { /* never let a stats tick crash the timer + caller */ }
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -382,7 +382,7 @@ class VidmolyUploader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (best && (bestScore > 0 || newFiles.length === 1)) {
|
if (best && bestScore > 0) {
|
||||||
return this._buildUrlsFromCode(best.file_code);
|
return this._buildUrlsFromCode(best.file_code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
305
main.js
305
main.js
@ -208,6 +208,7 @@ function getAllLogPaths() {
|
|||||||
debug: debugPath,
|
debug: debugPath,
|
||||||
accountRotation: rot,
|
accountRotation: rot,
|
||||||
doodstreamDebug: path.join(dir, 'doodstream-debug.log'),
|
doodstreamDebug: path.join(dir, 'doodstream-debug.log'),
|
||||||
|
crashLog: path.join(dir, 'crash.log'),
|
||||||
logDir: dir
|
logDir: dir
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -216,23 +217,10 @@ function rotLog(msg, ts) {
|
|||||||
try {
|
try {
|
||||||
const iso = new Date(ts || Date.now()).toISOString();
|
const iso = new Date(ts || Date.now()).toISOString();
|
||||||
const line = `[${iso}] ${msg}\n`;
|
const line = `[${iso}] ${msg}\n`;
|
||||||
// Write synchronously. Rotation events are rare (a handful per batch) so
|
_rotLogBuffer.push(line);
|
||||||
// the batching optimization from debugLog doesn't buy us anything, and
|
if (!_rotLogFlushTimer) {
|
||||||
// syncing guarantees the user can refresh the file and see fresh entries
|
_rotLogFlushTimer = setTimeout(() => { _rotLogFlushTimer = null; _flushRotLog(); }, 500);
|
||||||
// without waiting on a flush timer.
|
|
||||||
const candidates = [
|
|
||||||
getRotLogPath(),
|
|
||||||
path.join(app.getPath('desktop') || app.getPath('userData'), 'account-rotation.log'),
|
|
||||||
path.join(app.getPath('userData'), 'account-rotation.log')
|
|
||||||
];
|
|
||||||
for (const target of candidates) {
|
|
||||||
try {
|
|
||||||
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
||||||
fs.appendFileSync(target, line, 'utf-8');
|
|
||||||
break;
|
|
||||||
} catch {}
|
|
||||||
}
|
}
|
||||||
// Mirror into the main debug log for single-file-grep convenience.
|
|
||||||
_debugLogBuffer.push(`[${iso}] [ROT] ${msg}\n`);
|
_debugLogBuffer.push(`[${iso}] [ROT] ${msg}\n`);
|
||||||
if (!_debugLogFlushTimer) {
|
if (!_debugLogFlushTimer) {
|
||||||
_debugLogFlushTimer = setTimeout(() => { _debugLogFlushTimer = null; _flushDebugLog(); }, 500);
|
_debugLogFlushTimer = setTimeout(() => { _debugLogFlushTimer = null; _flushDebugLog(); }, 500);
|
||||||
@ -240,11 +228,62 @@ function rotLog(msg, ts) {
|
|||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Catch unhandled rejections from fire-and-forget async calls
|
function safeSend(channel, data) {
|
||||||
|
if (!mainWindow || mainWindow.isDestroyed()) return false;
|
||||||
|
try {
|
||||||
|
mainWindow.webContents.send(channel, data);
|
||||||
|
return true;
|
||||||
|
} catch (err) {
|
||||||
|
debugLog(`safeSend(${channel}) failed: ${err && err.message ? err.message : err}`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function _writeCrashLog(prefix, err, extra) {
|
||||||
|
try {
|
||||||
|
const ts = new Date().toISOString();
|
||||||
|
const line = `[${ts}] ${prefix} ${err && err.stack ? err.stack : (err && err.message) || String(err)}${extra ? ' :: ' + JSON.stringify(extra) : ''}\n`;
|
||||||
|
try {
|
||||||
|
const target = getDebugLogPath();
|
||||||
|
fs.appendFileSync(target, line, 'utf-8');
|
||||||
|
} catch {}
|
||||||
|
try {
|
||||||
|
const crashDir = path.dirname(getDebugLogPath());
|
||||||
|
fs.appendFileSync(path.join(crashDir, 'crash.log'), line, 'utf-8');
|
||||||
|
} catch {}
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
|
||||||
process.on('unhandledRejection', (reason) => {
|
process.on('unhandledRejection', (reason) => {
|
||||||
debugLog(`UNHANDLED REJECTION: ${reason && reason.stack ? reason.stack : reason}`);
|
debugLog(`UNHANDLED REJECTION: ${reason && reason.stack ? reason.stack : reason}`);
|
||||||
|
_writeCrashLog('UNHANDLED REJECTION', reason);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
process.on('uncaughtException', (err, origin) => {
|
||||||
|
_writeCrashLog('UNCAUGHT EXCEPTION (' + origin + ')', err);
|
||||||
|
debugLog(`UNCAUGHT EXCEPTION (${origin}): ${err && err.stack ? err.stack : err}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
process.on('exit', (code) => {
|
||||||
|
try { _writeCrashLog('PROCESS EXIT', new Error('code=' + code)); } catch {}
|
||||||
|
});
|
||||||
|
|
||||||
|
process.on('warning', (warning) => {
|
||||||
|
debugLog(`PROCESS WARNING: ${warning.name} ${warning.message}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const sig of ['SIGINT', 'SIGTERM', 'SIGHUP', 'SIGBREAK']) {
|
||||||
|
try {
|
||||||
|
process.on(sig, () => {
|
||||||
|
_writeCrashLog('SIGNAL ' + sig, new Error('process received ' + sig));
|
||||||
|
try {
|
||||||
|
if (_debugLogBuffer.length) fs.appendFileSync(getDebugLogPath(), _debugLogBuffer.join(''), 'utf-8');
|
||||||
|
} catch {}
|
||||||
|
process.exit(0);
|
||||||
|
});
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
|
||||||
function withTimeout(promise, timeoutMs, label) {
|
function withTimeout(promise, timeoutMs, label) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
@ -444,9 +483,7 @@ function _flushUploadLog() {
|
|||||||
// next session writes here directly (no more fallback ladder) and
|
// next session writes here directly (no more fallback ladder) and
|
||||||
// the Settings input reflects reality.
|
// the Settings input reflects reality.
|
||||||
_persistFallbackLogPath(target.path);
|
_persistFallbackLogPath(target.path);
|
||||||
if (mainWindow && !mainWindow.isDestroyed()) {
|
safeSend('upload-log-fallback', { fallbackPath: target.path });
|
||||||
mainWindow.webContents.send('upload-log-fallback', { fallbackPath: target.path });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (_uploadLogBuffer.length && !_uploadLogFlushTimer) setImmediate(_flushUploadLog);
|
if (_uploadLogBuffer.length && !_uploadLogFlushTimer) setImmediate(_flushUploadLog);
|
||||||
});
|
});
|
||||||
@ -474,9 +511,7 @@ function _persistFallbackLogPath(workingPath) {
|
|||||||
cfg.globalSettings = gs;
|
cfg.globalSettings = gs;
|
||||||
configStore.save({ globalSettings: gs }).catch(() => {});
|
configStore.save({ globalSettings: gs }).catch(() => {});
|
||||||
_invalidateUploadLogTargetCache();
|
_invalidateUploadLogTargetCache();
|
||||||
if (mainWindow && !mainWindow.isDestroyed()) {
|
safeSend('log-path-auto-updated', { logFilePath: toSave });
|
||||||
mainWindow.webContents.send('log-path-auto-updated', { logFilePath: toSave });
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
debugLog(`persist fallback logpath failed: ${err.message}`);
|
debugLog(`persist fallback logpath failed: ${err.message}`);
|
||||||
}
|
}
|
||||||
@ -960,6 +995,51 @@ function createWindow() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
mainWindow.webContents.setBackgroundThrottling(false);
|
mainWindow.webContents.setBackgroundThrottling(false);
|
||||||
|
|
||||||
|
mainWindow.webContents.on('render-process-gone', (_event, details) => {
|
||||||
|
_writeCrashLog('RENDER PROCESS GONE', new Error(details.reason || 'unknown'), details);
|
||||||
|
debugLog(`RENDER PROCESS GONE: reason=${details.reason} exitCode=${details.exitCode}`);
|
||||||
|
if (mainWindow && !mainWindow.isDestroyed()) {
|
||||||
|
try {
|
||||||
|
const choice = dialog.showMessageBoxSync(mainWindow, {
|
||||||
|
type: 'error',
|
||||||
|
title: 'Renderer abgestürzt',
|
||||||
|
message: `Der Renderer-Prozess ist abgestürzt (${details.reason}).`,
|
||||||
|
detail: 'Bitte Diagnose-Paket exportieren und einsenden. Klick "Neu laden" um die UI wiederherzustellen — laufende Uploads im Main-Process bleiben aktiv.',
|
||||||
|
buttons: ['Neu laden', 'Beenden'],
|
||||||
|
defaultId: 0,
|
||||||
|
cancelId: 1
|
||||||
|
});
|
||||||
|
if (choice === 0) {
|
||||||
|
mainWindow.webContents.reload();
|
||||||
|
} else {
|
||||||
|
app.exit(1);
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
try { mainWindow.webContents.reload(); } catch {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mainWindow.webContents.on('unresponsive', () => {
|
||||||
|
_writeCrashLog('RENDERER UNRESPONSIVE', new Error('webContents unresponsive'));
|
||||||
|
debugLog('RENDERER UNRESPONSIVE');
|
||||||
|
});
|
||||||
|
|
||||||
|
mainWindow.webContents.on('responsive', () => {
|
||||||
|
debugLog('RENDERER RESPONSIVE AGAIN');
|
||||||
|
});
|
||||||
|
|
||||||
|
mainWindow.webContents.on('did-fail-load', (_event, errorCode, errorDescription, validatedURL) => {
|
||||||
|
_writeCrashLog('DID-FAIL-LOAD', new Error(errorDescription), { errorCode, validatedURL });
|
||||||
|
debugLog(`DID-FAIL-LOAD: ${errorCode} ${errorDescription} url=${validatedURL}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
app.on('child-process-gone', (_event, details) => {
|
||||||
|
_writeCrashLog('CHILD PROCESS GONE', new Error(details.reason || 'unknown'), details);
|
||||||
|
debugLog(`CHILD PROCESS GONE: type=${details.type} reason=${details.reason} exitCode=${details.exitCode}`);
|
||||||
|
});
|
||||||
|
|
||||||
mainWindow.loadFile(path.join(__dirname, 'renderer', 'index.html'));
|
mainWindow.loadFile(path.join(__dirname, 'renderer', 'index.html'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1053,7 +1133,7 @@ app.whenReady().then(() => {
|
|||||||
logInfo(`update-check: available=${result && result.available}, remote=${result && result.remoteVersion}`);
|
logInfo(`update-check: available=${result && result.available}, remote=${result && result.remoteVersion}`);
|
||||||
logDebug(`update-check result: ${JSON.stringify(result)}`);
|
logDebug(`update-check result: ${JSON.stringify(result)}`);
|
||||||
if (result && result.available && mainWindow && !mainWindow.isDestroyed()) {
|
if (result && result.available && mainWindow && !mainWindow.isDestroyed()) {
|
||||||
mainWindow.webContents.send('app:update-available', result);
|
safeSend('app:update-available', result);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logError('update-check failed', err);
|
logError('update-check failed', err);
|
||||||
@ -1062,6 +1142,9 @@ app.whenReady().then(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.on('window-all-closed', () => {
|
app.on('window-all-closed', () => {
|
||||||
|
const activeJobs = uploadManager && typeof uploadManager.getActiveJobCount === 'function' ? uploadManager.getActiveJobCount() : 0;
|
||||||
|
debugLog(`window-all-closed: activeJobs=${activeJobs}, uploadManager=${!!uploadManager}`);
|
||||||
|
_writeCrashLog('WINDOW-ALL-CLOSED', new Error('all windows closed'), { activeJobs, uploadManager: !!uploadManager });
|
||||||
app.quit();
|
app.quit();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1072,7 +1155,8 @@ app.on('before-quit', () => {
|
|||||||
if (remoteServer) { remoteServer.stop(); remoteServer = null; }
|
if (remoteServer) { remoteServer.stop(); remoteServer = null; }
|
||||||
destroyCaptureWindow();
|
destroyCaptureWindow();
|
||||||
} catch {}
|
} catch {}
|
||||||
destroyDropTargetWindow();
|
try { destroyDropTargetWindow(); } catch {}
|
||||||
|
try { if (tray && !tray.isDestroyed()) { tray.destroy(); tray = null; } } catch {}
|
||||||
// Flush pending log buffers synchronously so no lines are lost.
|
// Flush pending log buffers synchronously so no lines are lost.
|
||||||
try {
|
try {
|
||||||
if (_debugLogBuffer.length) {
|
if (_debugLogBuffer.length) {
|
||||||
@ -1133,13 +1217,11 @@ ipcMain.handle('save-config', async (_event, config) => {
|
|||||||
rotLog(`main: config-updated → late fallback ${fallback.id} for ${hoster} (was stuck on ${failedAccountId})`);
|
rotLog(`main: config-updated → late fallback ${fallback.id} for ${hoster} (was stuck on ${failedAccountId})`);
|
||||||
uploadManager.switchAccount(hoster, fallback);
|
uploadManager.switchAccount(hoster, fallback);
|
||||||
_sessionAccountOverrides.set(hoster, fallback);
|
_sessionAccountOverrides.set(hoster, fallback);
|
||||||
if (mainWindow && !mainWindow.isDestroyed()) {
|
safeSend('account-switched', {
|
||||||
mainWindow.webContents.send('account-switched', {
|
|
||||||
hoster, fromAccountId: failedAccountId, toAccountId: fallback.id
|
hoster, fromAccountId: failedAccountId, toAccountId: fallback.id
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
debugLog(`save-config re-resolve failed: ${err && err.message ? err.message : err}`);
|
debugLog(`save-config re-resolve failed: ${err && err.message ? err.message : err}`);
|
||||||
}
|
}
|
||||||
@ -1297,33 +1379,32 @@ ipcMain.handle('select-folder', async () => {
|
|||||||
});
|
});
|
||||||
if (result.canceled || !result.filePaths.length) return null;
|
if (result.canceled || !result.filePaths.length) return null;
|
||||||
|
|
||||||
// Recursively collect all files from selected folders
|
|
||||||
const files = [];
|
const files = [];
|
||||||
const walk = (dir) => {
|
for (const folder of result.filePaths) await walkFolderAsync(folder, files);
|
||||||
try {
|
|
||||||
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
||||||
const full = path.join(dir, entry.name);
|
|
||||||
if (entry.isDirectory()) walk(full);
|
|
||||||
else if (entry.isFile()) files.push(full);
|
|
||||||
}
|
|
||||||
} catch {}
|
|
||||||
};
|
|
||||||
for (const folder of result.filePaths) walk(folder);
|
|
||||||
return files.length > 0 ? files : null;
|
return files.length > 0 ? files : null;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
async function walkFolderAsync(rootDir, outFiles) {
|
||||||
|
const fsp = fs.promises;
|
||||||
|
const stack = [rootDir];
|
||||||
|
let scanned = 0;
|
||||||
|
while (stack.length > 0) {
|
||||||
|
const dir = stack.pop();
|
||||||
|
let entries;
|
||||||
|
try { entries = await fsp.readdir(dir, { withFileTypes: true }); }
|
||||||
|
catch { continue; }
|
||||||
|
for (const entry of entries) {
|
||||||
|
const full = path.join(dir, entry.name);
|
||||||
|
if (entry.isDirectory()) stack.push(full);
|
||||||
|
else if (entry.isFile()) outFiles.push(full);
|
||||||
|
}
|
||||||
|
if ((++scanned % 8) === 0) await new Promise(setImmediate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ipcMain.handle('resolve-folder-files', async (_event, folderPath) => {
|
ipcMain.handle('resolve-folder-files', async (_event, folderPath) => {
|
||||||
const files = [];
|
const files = [];
|
||||||
const walk = (dir) => {
|
await walkFolderAsync(folderPath, files);
|
||||||
try {
|
|
||||||
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
||||||
const full = path.join(dir, entry.name);
|
|
||||||
if (entry.isDirectory()) walk(full);
|
|
||||||
else if (entry.isFile()) files.push(full);
|
|
||||||
}
|
|
||||||
} catch {}
|
|
||||||
};
|
|
||||||
walk(folderPath);
|
|
||||||
return files;
|
return files;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1382,9 +1463,29 @@ ipcMain.handle('start-upload', (_event, payload) => {
|
|||||||
|
|
||||||
// Pass hoster settings to the upload manager
|
// Pass hoster settings to the upload manager
|
||||||
uploadManager = new UploadManager(config.hosterSettings || {}, config.globalSettings || {});
|
uploadManager = new UploadManager(config.hosterSettings || {}, config.globalSettings || {});
|
||||||
|
globalThis._mhuUploadManagerRef = uploadManager;
|
||||||
|
|
||||||
|
const _progressByJob = new Map();
|
||||||
|
const _progressTerminalQueue = [];
|
||||||
|
let _progressFlushTimer = null;
|
||||||
|
const PROGRESS_BATCH_INTERVAL_MS = 100;
|
||||||
|
function _scheduleProgressFlush() {
|
||||||
|
if (_progressFlushTimer) return;
|
||||||
|
_progressFlushTimer = setTimeout(() => {
|
||||||
|
_progressFlushTimer = null;
|
||||||
|
if (!mainWindow || mainWindow.isDestroyed()) {
|
||||||
|
_progressByJob.clear();
|
||||||
|
_progressTerminalQueue.length = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const batch = _progressTerminalQueue.splice(0);
|
||||||
|
for (const v of _progressByJob.values()) batch.push(v);
|
||||||
|
_progressByJob.clear();
|
||||||
|
if (batch.length) safeSend('upload-progress-batch', batch);
|
||||||
|
}, PROGRESS_BATCH_INTERVAL_MS);
|
||||||
|
}
|
||||||
|
|
||||||
uploadManager.on('progress', (data) => {
|
uploadManager.on('progress', (data) => {
|
||||||
// Only log state changes, not continuous progress updates
|
|
||||||
if (data.status !== 'uploading') {
|
if (data.status !== 'uploading') {
|
||||||
debugLog(`progress: ${data.fileName} ${data.hoster} ${data.status} ${data.error || ''}`);
|
debugLog(`progress: ${data.fileName} ${data.hoster} ${data.status} ${data.error || ''}`);
|
||||||
_appendJobLog(data.jobId, {
|
_appendJobLog(data.jobId, {
|
||||||
@ -1393,10 +1494,6 @@ ipcMain.handle('start-upload', (_event, payload) => {
|
|||||||
error: data.error || null, attempt: data.attempt || 0, maxAttempts: data.maxAttempts || 0
|
error: data.error || null, attempt: data.attempt || 0, maxAttempts: data.maxAttempts || 0
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Write to fileuploader.log immediately when a single upload finishes —
|
|
||||||
// unless the user disabled logging for this hoster (per-hoster toggle).
|
|
||||||
// Read from the live uploadManager.hosterSettings so a mid-batch toggle
|
|
||||||
// (which calls updateSettings) takes effect immediately.
|
|
||||||
if (data.status === 'done' && data.result) {
|
if (data.status === 'done' && data.result) {
|
||||||
const link = data.result.download_url || data.result.embed_url || data.result.file_code || '';
|
const link = data.result.download_url || data.result.embed_url || data.result.file_code || '';
|
||||||
if (link) {
|
if (link) {
|
||||||
@ -1409,22 +1506,29 @@ ipcMain.handle('start-upload', (_event, payload) => {
|
|||||||
debugLog(`WARNING: done but no link for ${data.fileName} @ ${data.hoster}: ${JSON.stringify(data.result)}`);
|
debugLog(`WARNING: done but no link for ${data.fileName} @ ${data.hoster}: ${JSON.stringify(data.result)}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mainWindow && !mainWindow.isDestroyed()) {
|
const isTerminal = data.status === 'done' || data.status === 'error' || data.status === 'aborted' || data.status === 'skipped';
|
||||||
mainWindow.webContents.send('upload-progress', data);
|
if (isTerminal) {
|
||||||
|
if (data.jobId) _progressByJob.delete(data.jobId);
|
||||||
|
_progressTerminalQueue.push(data);
|
||||||
|
} else if (data.jobId) {
|
||||||
|
_progressByJob.set(data.jobId, data);
|
||||||
|
} else {
|
||||||
|
_progressTerminalQueue.push(data);
|
||||||
}
|
}
|
||||||
|
_scheduleProgressFlush();
|
||||||
});
|
});
|
||||||
|
|
||||||
uploadManager.on('stats', (data) => {
|
uploadManager.on('stats', (data) => {
|
||||||
if (mainWindow && !mainWindow.isDestroyed()) {
|
try {
|
||||||
mainWindow.webContents.send('upload-stats', data);
|
if (!data || typeof data !== 'object') return;
|
||||||
}
|
safeSend('upload-stats', data);
|
||||||
// Update tray tooltip with upload progress
|
|
||||||
if (data.state === 'uploading' && data.activeJobs > 0) {
|
if (data.state === 'uploading' && data.activeJobs > 0) {
|
||||||
const speedMb = ((data.globalSpeedKbs || 0) / 1024).toFixed(1);
|
const speedMb = ((Number(data.globalSpeedKbs) || 0) / 1024).toFixed(1);
|
||||||
updateTrayTooltip(`Upload: ${data.activeJobs} aktiv - ${speedMb} MB/s`);
|
updateTrayTooltip(`Upload: ${data.activeJobs} aktiv - ${speedMb} MB/s`);
|
||||||
} else {
|
} else {
|
||||||
updateTrayTooltip('Multi-Hoster-Upload');
|
updateTrayTooltip('Multi-Hoster-Upload');
|
||||||
}
|
}
|
||||||
|
} catch (e) { debugLog(`stats listener error: ${e && e.message}`); }
|
||||||
});
|
});
|
||||||
|
|
||||||
uploadManager.on('account-failed', ({ hoster, accountId }) => {
|
uploadManager.on('account-failed', ({ hoster, accountId }) => {
|
||||||
@ -1437,9 +1541,7 @@ ipcMain.handle('start-upload', (_event, payload) => {
|
|||||||
rotLog(`main: account-failed ${hoster} ${accountId} → resolved fallback ${fallback.id}`);
|
rotLog(`main: account-failed ${hoster} ${accountId} → resolved fallback ${fallback.id}`);
|
||||||
uploadManager.switchAccount(hoster, fallback);
|
uploadManager.switchAccount(hoster, fallback);
|
||||||
_sessionAccountOverrides.set(hoster, fallback);
|
_sessionAccountOverrides.set(hoster, fallback);
|
||||||
if (mainWindow && !mainWindow.isDestroyed()) {
|
safeSend('account-switched', { hoster, fromAccountId: accountId, toAccountId: fallback.id });
|
||||||
mainWindow.webContents.send('account-switched', { hoster, fromAccountId: accountId, toAccountId: fallback.id });
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
rotLog(`main: account-failed ${hoster} ${accountId} → NO fallback available (end of chain)`);
|
rotLog(`main: account-failed ${hoster} ${accountId} → NO fallback available (end of chain)`);
|
||||||
}
|
}
|
||||||
@ -1455,17 +1557,25 @@ ipcMain.handle('start-upload', (_event, payload) => {
|
|||||||
'doodstream-via-web'
|
'doodstream-via-web'
|
||||||
]);
|
]);
|
||||||
uploadManager.on('rot-log', (entry) => {
|
uploadManager.on('rot-log', (entry) => {
|
||||||
|
try {
|
||||||
|
if (!entry || typeof entry !== 'object') return;
|
||||||
const { ts, event, ...rest } = entry;
|
const { ts, event, ...rest } = entry;
|
||||||
const pairs = Object.entries(rest)
|
const pairs = Object.entries(rest)
|
||||||
.map(([k, v]) => `${k}=${typeof v === 'string' ? v : JSON.stringify(v)}`)
|
.map(([k, v]) => {
|
||||||
|
let sv;
|
||||||
|
try { sv = typeof v === 'string' ? v : JSON.stringify(v); }
|
||||||
|
catch { sv = '<unserializable>'; }
|
||||||
|
return `${k}=${sv}`;
|
||||||
|
})
|
||||||
.join(' ');
|
.join(' ');
|
||||||
rotLog(`[${event}] ${pairs}`, ts);
|
rotLog(`[${event}] ${pairs}`, ts);
|
||||||
if (entry.jobId) {
|
if (entry.jobId) {
|
||||||
_appendJobLog(entry.jobId, { ts: ts || Date.now(), kind: 'rot', event, ...rest });
|
_appendJobLog(entry.jobId, { ts: ts || Date.now(), kind: 'rot', event, ...rest });
|
||||||
}
|
}
|
||||||
if (mainWindow && !mainWindow.isDestroyed() && ROT_LOG_RENDERER_EVENTS.has(event)) {
|
if (ROT_LOG_RENDERER_EVENTS.has(event)) {
|
||||||
mainWindow.webContents.send('account-rotation-log', entry);
|
safeSend('account-rotation-log', entry);
|
||||||
}
|
}
|
||||||
|
} catch (e) { debugLog(`rot-log listener error: ${e && e.message}`); }
|
||||||
});
|
});
|
||||||
|
|
||||||
// Capture the manager identity at listener-registration time so the post-
|
// Capture the manager identity at listener-registration time so the post-
|
||||||
@ -1482,13 +1592,11 @@ ipcMain.handle('start-upload', (_event, payload) => {
|
|||||||
try { await configStore.appendHistory(summary); } catch (err) {
|
try { await configStore.appendHistory(summary); } catch (err) {
|
||||||
debugLog(`appendHistory failed: ${err.message}`);
|
debugLog(`appendHistory failed: ${err.message}`);
|
||||||
}
|
}
|
||||||
if (mainWindow && !mainWindow.isDestroyed()) {
|
safeSend('upload-batch-done', summary);
|
||||||
mainWindow.webContents.send('upload-batch-done', summary);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Shutdown after finish
|
// Shutdown after finish
|
||||||
handleShutdownAfterFinish();
|
handleShutdownAfterFinish();
|
||||||
if (uploadManager === _thisManager) uploadManager = null;
|
if (uploadManager === _thisManager) { uploadManager = null; globalThis._mhuUploadManagerRef = null; }
|
||||||
else debugLog('batch-done: skipping uploadManager null-out — a newer manager replaced this one mid-await');
|
else debugLog('batch-done: skipping uploadManager null-out — a newer manager replaced this one mid-await');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1504,8 +1612,7 @@ ipcMain.handle('start-upload', (_event, payload) => {
|
|||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
debugLog(`startBatch REJECTED: ${err && err.stack ? err.stack : err}`);
|
debugLog(`startBatch REJECTED: ${err && err.stack ? err.stack : err}`);
|
||||||
// Forward error to renderer as batch-done with failure
|
// Forward error to renderer as batch-done with failure
|
||||||
if (mainWindow && !mainWindow.isDestroyed()) {
|
safeSend('upload-batch-done', {
|
||||||
mainWindow.webContents.send('upload-batch-done', {
|
|
||||||
id: 'error',
|
id: 'error',
|
||||||
timestamp: new Date().toISOString(),
|
timestamp: new Date().toISOString(),
|
||||||
total: tasks.length,
|
total: tasks.length,
|
||||||
@ -1514,7 +1621,6 @@ ipcMain.handle('start-upload', (_event, payload) => {
|
|||||||
files: [],
|
files: [],
|
||||||
error: err ? err.message : 'Unbekannter Fehler'
|
error: err ? err.message : 'Unbekannter Fehler'
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1701,6 +1807,7 @@ ipcMain.handle('create-support-bundle', async () => {
|
|||||||
{ label: 'debug.log (last 5 MB)', path: paths.debug, maxBytes: 5 * 1024 * 1024 },
|
{ label: 'debug.log (last 5 MB)', path: paths.debug, maxBytes: 5 * 1024 * 1024 },
|
||||||
{ label: 'account-rotation.log (last 2 MB)', path: paths.accountRotation, maxBytes: 2 * 1024 * 1024 },
|
{ label: 'account-rotation.log (last 2 MB)', path: paths.accountRotation, maxBytes: 2 * 1024 * 1024 },
|
||||||
{ label: 'doodstream-debug.log (last 2 MB)', path: paths.doodstreamDebug, maxBytes: 2 * 1024 * 1024 },
|
{ label: 'doodstream-debug.log (last 2 MB)', path: paths.doodstreamDebug, maxBytes: 2 * 1024 * 1024 },
|
||||||
|
{ label: 'crash.log', path: path.join(paths.logDir || path.dirname(paths.debug), 'crash.log'), maxBytes: 1 * 1024 * 1024 },
|
||||||
{ label: 'fileuploader.log (last 1 MB)', path: paths.fileuploader, maxBytes: 1 * 1024 * 1024 }
|
{ label: 'fileuploader.log (last 1 MB)', path: paths.fileuploader, maxBytes: 1 * 1024 * 1024 }
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
@ -1742,12 +1849,19 @@ ipcMain.handle('export-backup', async () => {
|
|||||||
const { canceled, filePath } = await dialog.showSaveDialog(mainWindow, {
|
const { canceled, filePath } = await dialog.showSaveDialog(mainWindow, {
|
||||||
title: 'Backup exportieren',
|
title: 'Backup exportieren',
|
||||||
defaultPath: `multi-hoster-backup-${new Date().toISOString().slice(0, 10)}.mhu`,
|
defaultPath: `multi-hoster-backup-${new Date().toISOString().slice(0, 10)}.mhu`,
|
||||||
filters: [{ name: 'Multi-Hoster Backup', extensions: ['mhu'] }]
|
filters: [
|
||||||
|
{ name: 'Multi-Hoster Backup (verschlüsselt)', extensions: ['mhu'] },
|
||||||
|
{ name: 'Multi-Hoster Backup (Klartext JSON)', extensions: ['json'] }
|
||||||
|
]
|
||||||
});
|
});
|
||||||
if (canceled || !filePath) return { ok: false, canceled: true };
|
if (canceled || !filePath) return { ok: false, canceled: true };
|
||||||
const config = configStore.load();
|
const config = configStore.load();
|
||||||
|
if (filePath.toLowerCase().endsWith('.json')) {
|
||||||
|
fs.writeFileSync(filePath, JSON.stringify(config, null, 2), 'utf-8');
|
||||||
|
} else {
|
||||||
const encrypted = backupCrypto.encrypt(config);
|
const encrypted = backupCrypto.encrypt(config);
|
||||||
fs.writeFileSync(filePath, encrypted);
|
fs.writeFileSync(filePath, encrypted);
|
||||||
|
}
|
||||||
return { ok: true, path: filePath };
|
return { ok: true, path: filePath };
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1759,7 +1873,11 @@ ipcMain.handle('import-backup', async (_event, legacyPassword) => {
|
|||||||
} else {
|
} else {
|
||||||
const { canceled, filePaths } = await dialog.showOpenDialog(mainWindow, {
|
const { canceled, filePaths } = await dialog.showOpenDialog(mainWindow, {
|
||||||
title: 'Backup importieren',
|
title: 'Backup importieren',
|
||||||
filters: [{ name: 'Multi-Hoster Backup', extensions: ['mhu'] }],
|
filters: [
|
||||||
|
{ name: 'Multi-Hoster Backup', extensions: ['mhu', 'json'] },
|
||||||
|
{ name: 'Verschlüsselt (.mhu)', extensions: ['mhu'] },
|
||||||
|
{ name: 'Klartext (.json)', extensions: ['json'] }
|
||||||
|
],
|
||||||
properties: ['openFile']
|
properties: ['openFile']
|
||||||
});
|
});
|
||||||
if (canceled || !filePaths.length) return { ok: false, canceled: true };
|
if (canceled || !filePaths.length) return { ok: false, canceled: true };
|
||||||
@ -1768,15 +1886,26 @@ ipcMain.handle('import-backup', async (_event, legacyPassword) => {
|
|||||||
_lastImportPath = sourcePath;
|
_lastImportPath = sourcePath;
|
||||||
}
|
}
|
||||||
let imported;
|
let imported;
|
||||||
|
const looksLikeJson = buffer.length >= 1 && (buffer[0] === 0x7B || buffer[0] === 0x20 || buffer[0] === 0x0A || buffer[0] === 0x0D || buffer[0] === 0x09 || buffer[0] === 0xEF);
|
||||||
|
if (looksLikeJson) {
|
||||||
|
try {
|
||||||
|
const text = buffer.toString('utf-8').replace(/^\uFEFF/, '');
|
||||||
|
imported = JSON.parse(text);
|
||||||
|
} catch (err) {
|
||||||
|
_lastImportPath = null;
|
||||||
|
return { ok: false, error: 'Klartext-Backup ist kein gültiges JSON: ' + (err.message || err) };
|
||||||
|
}
|
||||||
|
} else {
|
||||||
try {
|
try {
|
||||||
imported = backupCrypto.decrypt(buffer, legacyPassword);
|
imported = backupCrypto.decrypt(buffer, legacyPassword);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err && err.needsPassword) {
|
if (err && err.needsPassword) {
|
||||||
return { ok: false, needsPassword: true };
|
return { ok: false, needsPassword: true, hint: 'Falls dieses Backup mit der aktuellen Version erzeugt wurde, ist die Datei vermutlich beim Transfer beschädigt worden (z. B. FTP-Text-Modus). Versuch es mit einem Klartext-JSON-Export.' };
|
||||||
}
|
}
|
||||||
_lastImportPath = null;
|
_lastImportPath = null;
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
_lastImportPath = null;
|
_lastImportPath = null;
|
||||||
// Validate imported data has required structure
|
// Validate imported data has required structure
|
||||||
if (!imported || typeof imported !== 'object' || !imported.hosters || !imported.hosterSettings || !imported.globalSettings) {
|
if (!imported || typeof imported !== 'object' || !imported.hosters || !imported.hosterSettings || !imported.globalSettings) {
|
||||||
@ -1893,13 +2022,9 @@ ipcMain.handle('app:check-updates', async () => {
|
|||||||
|
|
||||||
ipcMain.handle('app:install-update', () => {
|
ipcMain.handle('app:install-update', () => {
|
||||||
installUpdate((progress) => {
|
installUpdate((progress) => {
|
||||||
if (mainWindow && !mainWindow.isDestroyed()) {
|
safeSend('app:update-progress', progress);
|
||||||
mainWindow.webContents.send('app:update-progress', progress);
|
|
||||||
}
|
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
if (mainWindow && !mainWindow.isDestroyed()) {
|
safeSend('app:update-progress', { stage: 'error', error: err.message });
|
||||||
mainWindow.webContents.send('app:update-progress', { stage: 'error', error: err.message });
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return { started: true };
|
return { started: true };
|
||||||
});
|
});
|
||||||
@ -1978,9 +2103,7 @@ function startFolderMonitor(settings) {
|
|||||||
folderMonitor.removeAllListeners();
|
folderMonitor.removeAllListeners();
|
||||||
folderMonitor.on('new-files', (files) => {
|
folderMonitor.on('new-files', (files) => {
|
||||||
debugLog(`folder-monitor: ${files.length} new file(s)`);
|
debugLog(`folder-monitor: ${files.length} new file(s)`);
|
||||||
if (mainWindow && !mainWindow.isDestroyed()) {
|
safeSend('folder-monitor:new-files', files);
|
||||||
mainWindow.webContents.send('folder-monitor:new-files', files);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
folderMonitor.on('error', (err) => {
|
folderMonitor.on('error', (err) => {
|
||||||
debugLog(`folder-monitor error: ${err.message}`);
|
debugLog(`folder-monitor error: ${err.message}`);
|
||||||
@ -2224,9 +2347,7 @@ ipcMain.handle('remote:get-capture-source-id', async () => {
|
|||||||
|
|
||||||
// IPC: Client count updates from capture window
|
// IPC: Client count updates from capture window
|
||||||
ipcMain.on('remote:client-count', (_event, count) => {
|
ipcMain.on('remote:client-count', (_event, count) => {
|
||||||
if (mainWindow && !mainWindow.isDestroyed()) {
|
safeSend('remote:client-count', count);
|
||||||
mainWindow.webContents.send('remote:client-count', count);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// IPC: Remote settings
|
// IPC: Remote settings
|
||||||
@ -2331,7 +2452,7 @@ ipcMain.on('drop-target:files', (_event, paths) => {
|
|||||||
mainWindow.show();
|
mainWindow.show();
|
||||||
mainWindow.focus();
|
mainWindow.focus();
|
||||||
}
|
}
|
||||||
mainWindow.webContents.send('drop-target:files', paths);
|
safeSend('drop-target:files', paths);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -2368,9 +2489,7 @@ function handleShutdownAfterFinish() {
|
|||||||
const { exec } = require('child_process');
|
const { exec } = require('child_process');
|
||||||
|
|
||||||
// Notify renderer
|
// Notify renderer
|
||||||
if (mainWindow && !mainWindow.isDestroyed()) {
|
safeSend('shutdown-countdown', { mode: shutdownMode, seconds: 60 });
|
||||||
mainWindow.webContents.send('shutdown-countdown', { mode: shutdownMode, seconds: 60 });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear any previous countdown to prevent orphaned timers
|
// Clear any previous countdown to prevent orphaned timers
|
||||||
if (shutdownTimer) clearTimeout(shutdownTimer);
|
if (shutdownTimer) clearTimeout(shutdownTimer);
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "multi-hoster-uploader",
|
"name": "multi-hoster-uploader",
|
||||||
"version": "3.3.45",
|
"version": "3.3.54",
|
||||||
"description": "Upload files to doodstream, voe, vidmoly, byse simultaneously",
|
"description": "Upload files to doodstream, voe, vidmoly, byse simultaneously",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@ -93,6 +93,9 @@ contextBridge.exposeInMainWorld('api', {
|
|||||||
onUploadProgress: (callback) => {
|
onUploadProgress: (callback) => {
|
||||||
ipcRenderer.on('upload-progress', (_event, data) => callback(data));
|
ipcRenderer.on('upload-progress', (_event, data) => callback(data));
|
||||||
},
|
},
|
||||||
|
onUploadProgressBatch: (callback) => {
|
||||||
|
ipcRenderer.on('upload-progress-batch', (_event, batch) => callback(batch));
|
||||||
|
},
|
||||||
onUploadBatchDone: (callback) => {
|
onUploadBatchDone: (callback) => {
|
||||||
ipcRenderer.on('upload-batch-done', (_event, data) => callback(data));
|
ipcRenderer.on('upload-batch-done', (_event, data) => callback(data));
|
||||||
},
|
},
|
||||||
|
|||||||
156
renderer/app.js
156
renderer/app.js
@ -63,10 +63,12 @@ const queueSortState = { key: 'filename', direction: 'asc' };
|
|||||||
// History state
|
// History state
|
||||||
let historyRowsData = [];
|
let historyRowsData = [];
|
||||||
let historySortState = { key: 'date', direction: 'desc' };
|
let historySortState = { key: 'date', direction: 'desc' };
|
||||||
|
let _historySortClicked = false;
|
||||||
|
|
||||||
// Session-specific files for the "Files" panel (resets each session)
|
// Session-specific files for the "Files" panel (resets each session)
|
||||||
let sessionFilesData = [];
|
let sessionFilesData = [];
|
||||||
const recentSortState = { key: 'date', direction: 'desc' };
|
const recentSortState = { key: 'date', direction: 'desc' };
|
||||||
|
let _recentSortClicked = false;
|
||||||
const selectedRecentIds = new Set();
|
const selectedRecentIds = new Set();
|
||||||
// Maintained incrementally — avoids O(n) filter() scans every 250ms in the status bar.
|
// Maintained incrementally — avoids O(n) filter() scans every 250ms in the status bar.
|
||||||
let _sessionDoneCount = 0;
|
let _sessionDoneCount = 0;
|
||||||
@ -75,6 +77,19 @@ let _sessionErrorCount = 0;
|
|||||||
// Huge with thousands of rows × thousands of incoming results.
|
// Huge with thousands of rows × thousands of incoming results.
|
||||||
const _sessionFileKeys = new Set();
|
const _sessionFileKeys = new Set();
|
||||||
|
|
||||||
|
window.addEventListener('error', (e) => {
|
||||||
|
try {
|
||||||
|
const msg = `RENDERER ERROR: ${e.message} at ${e.filename}:${e.lineno}:${e.colno}${e.error && e.error.stack ? '\n' + e.error.stack : ''}`;
|
||||||
|
if (window.api && window.api.debugLog) window.api.debugLog(msg);
|
||||||
|
} catch {}
|
||||||
|
});
|
||||||
|
window.addEventListener('unhandledrejection', (e) => {
|
||||||
|
try {
|
||||||
|
const reason = e.reason && e.reason.stack ? e.reason.stack : (e.reason && e.reason.message) || String(e.reason);
|
||||||
|
if (window.api && window.api.debugLog) window.api.debugLog(`RENDERER UNHANDLED REJECTION: ${reason}`);
|
||||||
|
} catch {}
|
||||||
|
});
|
||||||
|
|
||||||
// --- Init ---
|
// --- Init ---
|
||||||
async function init() {
|
async function init() {
|
||||||
config = await window.api.getConfig();
|
config = await window.api.getConfig();
|
||||||
@ -108,24 +123,19 @@ async function init() {
|
|||||||
window.api.onUpdateAvailable(showUpdateBanner);
|
window.api.onUpdateAvailable(showUpdateBanner);
|
||||||
window.api.onUpdateProgress(handleUpdateProgress);
|
window.api.onUpdateProgress(handleUpdateProgress);
|
||||||
|
|
||||||
// Upload event listeners — debug log only on state transitions; the 'uploading'
|
|
||||||
// tick fires 4×/sec per active job and an IPC roundtrip per event would
|
|
||||||
// backlog the renderer↔main channel with hundreds of messages/sec.
|
|
||||||
window.api.onUploadProgress((data) => {
|
window.api.onUploadProgress((data) => {
|
||||||
if (data.status !== 'uploading') {
|
|
||||||
window.api.debugLog('RX upload-progress: ' + data.status + ' ' + data.hoster + ' ' + (data.fileName || ''));
|
|
||||||
}
|
|
||||||
handleProgress(data);
|
handleProgress(data);
|
||||||
});
|
});
|
||||||
|
if (window.api.onUploadProgressBatch) {
|
||||||
|
window.api.onUploadProgressBatch((batch) => {
|
||||||
|
if (!Array.isArray(batch)) return;
|
||||||
|
for (let i = 0; i < batch.length; i++) handleProgress(batch[i]);
|
||||||
|
});
|
||||||
|
}
|
||||||
window.api.onUploadBatchDone((data) => {
|
window.api.onUploadBatchDone((data) => {
|
||||||
window.api.debugLog('RX upload-batch-done');
|
|
||||||
handleBatchDone(data);
|
handleBatchDone(data);
|
||||||
});
|
});
|
||||||
window.api.onUploadStats((data) => {
|
window.api.onUploadStats((data) => {
|
||||||
// Stats fire every second per upload session — skip while uploading.
|
|
||||||
if (data.state !== 'uploading') {
|
|
||||||
window.api.debugLog('RX upload-stats: state=' + data.state + ' active=' + data.activeJobs);
|
|
||||||
}
|
|
||||||
handleStats(data);
|
handleStats(data);
|
||||||
});
|
});
|
||||||
window.api.onShutdownCountdown(handleShutdownCountdown);
|
window.api.onShutdownCountdown(handleShutdownCountdown);
|
||||||
@ -1448,7 +1458,7 @@ async function doBackupExport() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function askLegacyBackupPassword() {
|
function askLegacyBackupPassword(hint) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const overlay = document.createElement('div');
|
const overlay = document.createElement('div');
|
||||||
overlay.className = 'modal-overlay';
|
overlay.className = 'modal-overlay';
|
||||||
@ -1461,7 +1471,7 @@ function askLegacyBackupPassword() {
|
|||||||
const header = document.createElement('div');
|
const header = document.createElement('div');
|
||||||
header.className = 'modal-header';
|
header.className = 'modal-header';
|
||||||
const h3 = document.createElement('h3');
|
const h3 = document.createElement('h3');
|
||||||
h3.textContent = 'Passwort erforderlich';
|
h3.textContent = 'Backup nicht entschlüsselbar';
|
||||||
header.appendChild(h3);
|
header.appendChild(h3);
|
||||||
|
|
||||||
const body = document.createElement('div');
|
const body = document.createElement('div');
|
||||||
@ -1469,7 +1479,15 @@ function askLegacyBackupPassword() {
|
|||||||
const p = document.createElement('p');
|
const p = document.createElement('p');
|
||||||
p.style.margin = '0 0 10px';
|
p.style.margin = '0 0 10px';
|
||||||
p.style.fontSize = '13px';
|
p.style.fontSize = '13px';
|
||||||
p.textContent = 'Dieses Backup wurde mit einem Passwort verschlüsselt.';
|
p.textContent = 'Wenn das Backup mit der alten Passwort-Option (vor v3.0) erstellt wurde, hier eingeben.';
|
||||||
|
if (hint) {
|
||||||
|
const p2 = document.createElement('p');
|
||||||
|
p2.style.margin = '0 0 10px';
|
||||||
|
p2.style.fontSize = '12px';
|
||||||
|
p2.style.color = 'var(--text-dim)';
|
||||||
|
p2.textContent = hint;
|
||||||
|
body.appendChild(p2);
|
||||||
|
}
|
||||||
const input = document.createElement('input');
|
const input = document.createElement('input');
|
||||||
input.type = 'password';
|
input.type = 'password';
|
||||||
input.className = 'key-input';
|
input.className = 'key-input';
|
||||||
@ -1513,7 +1531,7 @@ async function doBackupImport(legacyPassword) {
|
|||||||
const result = await window.api.importBackup(pw);
|
const result = await window.api.importBackup(pw);
|
||||||
if (!result || result.canceled) return;
|
if (!result || result.canceled) return;
|
||||||
if (result.needsPassword) {
|
if (result.needsPassword) {
|
||||||
const entered = await askLegacyBackupPassword();
|
const entered = await askLegacyBackupPassword(result.hint);
|
||||||
if (entered) doBackupImport(entered);
|
if (entered) doBackupImport(entered);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1878,6 +1896,14 @@ async function cancelUpload() {
|
|||||||
|
|
||||||
// --- Progress handling ---
|
// --- Progress handling ---
|
||||||
function handleProgress(data) {
|
function handleProgress(data) {
|
||||||
|
try {
|
||||||
|
if (!data || typeof data !== 'object') return;
|
||||||
|
_handleProgressImpl(data);
|
||||||
|
} catch (err) {
|
||||||
|
if (window.api && window.api.debugLog) window.api.debugLog(`handleProgress error: ${err && err.stack ? err.stack : err}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function _handleProgressImpl(data) {
|
||||||
let job = data.jobId ? _jobIndexById.get(data.jobId) : null;
|
let job = data.jobId ? _jobIndexById.get(data.jobId) : null;
|
||||||
if (!job && data.uploadId) job = _jobIndexByUploadId.get(data.uploadId);
|
if (!job && data.uploadId) job = _jobIndexByUploadId.get(data.uploadId);
|
||||||
if (!job) {
|
if (!job) {
|
||||||
@ -2139,6 +2165,14 @@ function _retryFailedFromBuckets(buckets, transientOnly) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleStats(data) {
|
function handleStats(data) {
|
||||||
|
try {
|
||||||
|
if (!data || typeof data !== 'object') return;
|
||||||
|
_handleStatsImpl(data);
|
||||||
|
} catch (err) {
|
||||||
|
if (window.api && window.api.debugLog) window.api.debugLog(`handleStats error: ${err && err.stack ? err.stack : err}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function _handleStatsImpl(data) {
|
||||||
lastUploadStats = {
|
lastUploadStats = {
|
||||||
state: data.state || 'idle',
|
state: data.state || 'idle',
|
||||||
globalSpeedKbs: data.globalSpeedKbs || 0,
|
globalSpeedKbs: data.globalSpeedKbs || 0,
|
||||||
@ -2466,7 +2500,7 @@ function _computeQueueStats() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_queueStatsCache = { total, remaining, inProgress, done, errors, bytesRemaining, totalSize, remainingSize, inProgressBytes };
|
_queueStatsCache = { total, remaining, inProgress, done, errors, bytesRemaining, totalSize, remainingSize, inProgressBytes };
|
||||||
queueMicrotask(() => { _queueStatsCache = null; });
|
(typeof queueMicrotask === 'function' ? queueMicrotask : (fn) => Promise.resolve().then(fn))(() => { _queueStatsCache = null; });
|
||||||
return _queueStatsCache;
|
return _queueStatsCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2527,8 +2561,10 @@ async function executeHealthCheck(hosters, _mode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function runHealthCheck(mode = 'manual', requestedHosters = null) {
|
async function runHealthCheck(mode = 'manual', requestedHosters = null) {
|
||||||
if (healthCheckRunning || (uploading && mode === 'manual')) return [];
|
if (healthCheckRunning) {
|
||||||
// Build check list: all enabled accounts with creds
|
if (mode === 'manual') showCopyToast('Account-Check läuft bereits.');
|
||||||
|
return [];
|
||||||
|
}
|
||||||
let hosters;
|
let hosters;
|
||||||
if (Array.isArray(requestedHosters) && requestedHosters.length > 0) {
|
if (Array.isArray(requestedHosters) && requestedHosters.length > 0) {
|
||||||
hosters = requestedHosters;
|
hosters = requestedHosters;
|
||||||
@ -3655,7 +3691,10 @@ async function deleteAccount(accountId) {
|
|||||||
// Fire-and-forget the persist. The earlier `await getConfig()` round-trip
|
// Fire-and-forget the persist. The earlier `await getConfig()` round-trip
|
||||||
// was redundant (we already have the truth in memory) and was the main
|
// was redundant (we already have the truth in memory) and was the main
|
||||||
// source of perceived lag on add/delete.
|
// source of perceived lag on add/delete.
|
||||||
window.api.saveConfig({ hosters: config.hosters }).catch(() => {});
|
window.api.saveConfig({ hosters: config.hosters }).catch((err) => {
|
||||||
|
if (window.api && window.api.debugLog) window.api.debugLog(`deleteAccount saveConfig failed: ${err && err.message ? err.message : err}`);
|
||||||
|
showCopyToast('Account-Löschung konnte nicht persistiert werden — bitte erneut versuchen.');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function readAccountCredsFromModal(authType) {
|
function readAccountCredsFromModal(authType) {
|
||||||
@ -3861,6 +3900,15 @@ async function _commitAccount(ctx, creds, validatedStatus, validatedMessage) {
|
|||||||
const idx = config.hosters[ctx.hosterName].findIndex(a => a.id === accountId);
|
const idx = config.hosters[ctx.hosterName].findIndex(a => a.id === accountId);
|
||||||
if (idx >= 0) {
|
if (idx >= 0) {
|
||||||
config.hosters[ctx.hosterName][idx] = { ...config.hosters[ctx.hosterName][idx], ...creds };
|
config.hosters[ctx.hosterName][idx] = { ...config.hosters[ctx.hosterName][idx], ...creds };
|
||||||
|
} else {
|
||||||
|
_accountModalBusy = false;
|
||||||
|
const _sb = document.getElementById('saveAccountBtn'); if (_sb) _sb.disabled = false;
|
||||||
|
const _st = document.getElementById('accountModalStatus');
|
||||||
|
if (_st) {
|
||||||
|
_st.textContent = 'Account nicht mehr in der Config — wurde extern gelöscht. Modal schließen und neu anlegen.';
|
||||||
|
_st.className = 'account-modal-status error';
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
accountId = `${ctx.hosterName}-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;
|
accountId = `${ctx.hosterName}-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;
|
||||||
@ -4108,17 +4156,32 @@ function renderHistoryTable(container) {
|
|||||||
${headerCell('date', 'Date')}${headerCell('filename', 'Filename')}${headerCell('host', 'Host')}${headerCell('link', 'Link')}
|
${headerCell('date', 'Date')}${headerCell('filename', 'Filename')}${headerCell('host', 'Host')}${headerCell('link', 'Link')}
|
||||||
</tr></thead><tbody>`;
|
</tr></thead><tbody>`;
|
||||||
|
|
||||||
rows.forEach(row => {
|
const parts = [html];
|
||||||
html += `<tr class="history-row${row.isError ? ' error' : ''}" data-link="${escapeAttr(row.link)}">
|
const len = rows.length;
|
||||||
<td class="col-date">${escapeHtml(row.date)}</td>
|
for (let i = 0; i < len; i++) {
|
||||||
<td class="col-filename">${escapeHtml(row.filename)}</td>
|
const row = rows[i];
|
||||||
<td class="col-host">${escapeHtml(row.host)}</td>
|
const link = row.link || '';
|
||||||
<td class="col-link">${escapeHtml(row.link)}</td>
|
const date = escapeHtml(row.date);
|
||||||
</tr>`;
|
const filename = escapeHtml(row.filename);
|
||||||
});
|
const host = escapeHtml(row.host);
|
||||||
|
const linkHtml = escapeHtml(link);
|
||||||
html += '</tbody></table>';
|
const linkAttr = escapeAttr(link);
|
||||||
container.innerHTML = html;
|
parts.push('<tr class="history-row');
|
||||||
|
if (row.isError) parts.push(' error');
|
||||||
|
parts.push('" data-link="');
|
||||||
|
parts.push(linkAttr);
|
||||||
|
parts.push('"><td class="col-date">');
|
||||||
|
parts.push(date);
|
||||||
|
parts.push('</td><td class="col-filename">');
|
||||||
|
parts.push(filename);
|
||||||
|
parts.push('</td><td class="col-host">');
|
||||||
|
parts.push(host);
|
||||||
|
parts.push('</td><td class="col-link">');
|
||||||
|
parts.push(linkHtml);
|
||||||
|
parts.push('</td></tr>');
|
||||||
|
}
|
||||||
|
parts.push('</tbody></table>');
|
||||||
|
container.innerHTML = parts.join('');
|
||||||
|
|
||||||
// Delegated listeners: bind once per render-target instead of once per
|
// Delegated listeners: bind once per render-target instead of once per
|
||||||
// row/header. With a 5000-row history the per-row bind path was a
|
// row/header. With a 5000-row history the per-row bind path was a
|
||||||
@ -4130,8 +4193,14 @@ function renderHistoryTable(container) {
|
|||||||
const th = e.target.closest('th.sortable');
|
const th = e.target.closest('th.sortable');
|
||||||
if (th && container.contains(th)) {
|
if (th && container.contains(th)) {
|
||||||
const key = th.dataset.historySort;
|
const key = th.dataset.historySort;
|
||||||
if (historySortState.key === key) historySortState.direction = historySortState.direction === 'asc' ? 'desc' : 'asc';
|
const defaultDir = key === 'date' ? 'desc' : 'asc';
|
||||||
else { historySortState.key = key; historySortState.direction = key === 'date' ? 'desc' : 'asc'; }
|
if (!_historySortClicked || historySortState.key !== key) {
|
||||||
|
_historySortClicked = true;
|
||||||
|
historySortState.key = key;
|
||||||
|
historySortState.direction = defaultDir;
|
||||||
|
} else {
|
||||||
|
historySortState.direction = historySortState.direction === 'asc' ? 'desc' : 'asc';
|
||||||
|
}
|
||||||
renderHistoryTable(container);
|
renderHistoryTable(container);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -4187,11 +4256,13 @@ function setupListeners() {
|
|||||||
const th = e.target.closest('th[data-recent-sort]');
|
const th = e.target.closest('th[data-recent-sort]');
|
||||||
if (!th) return;
|
if (!th) return;
|
||||||
const key = th.dataset.recentSort;
|
const key = th.dataset.recentSort;
|
||||||
if (recentSortState.key === key) {
|
const defaultDir = key === 'date' ? 'desc' : 'asc';
|
||||||
recentSortState.direction = recentSortState.direction === 'desc' ? 'asc' : 'desc';
|
if (!_recentSortClicked || recentSortState.key !== key) {
|
||||||
} else {
|
_recentSortClicked = true;
|
||||||
recentSortState.key = key;
|
recentSortState.key = key;
|
||||||
recentSortState.direction = key === 'date' ? 'desc' : 'asc';
|
recentSortState.direction = defaultDir;
|
||||||
|
} else {
|
||||||
|
recentSortState.direction = recentSortState.direction === 'desc' ? 'asc' : 'desc';
|
||||||
}
|
}
|
||||||
renderRecentUploadsPanel();
|
renderRecentUploadsPanel();
|
||||||
});
|
});
|
||||||
@ -4785,4 +4856,15 @@ function updateStatsPanel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --- Start ---
|
// --- Start ---
|
||||||
init();
|
init().catch((err) => {
|
||||||
|
try {
|
||||||
|
if (window.api && window.api.debugLog) window.api.debugLog(`init failed: ${err && err.stack ? err.stack : err}`);
|
||||||
|
const root = document.getElementById('app') || document.body;
|
||||||
|
if (root) {
|
||||||
|
const banner = document.createElement('div');
|
||||||
|
banner.style.cssText = 'position:fixed;top:0;left:0;right:0;background:#5a1e1e;color:#fff;padding:8px;z-index:99999;font-family:sans-serif;font-size:13px';
|
||||||
|
banner.textContent = 'Initialisierung fehlgeschlagen: ' + (err && err.message ? err.message : err) + ' — bitte Diagnose-Paket exportieren oder Programm neu starten.';
|
||||||
|
root.appendChild(banner);
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
});
|
||||||
|
|||||||
@ -31,6 +31,7 @@ describe('UploadManager', () => {
|
|||||||
const origRequire = module.constructor.prototype.require;
|
const origRequire = module.constructor.prototype.require;
|
||||||
const hosters = require('../lib/hosters');
|
const hosters = require('../lib/hosters');
|
||||||
hosters.uploadFile = mockUploadFile;
|
hosters.uploadFile = mockUploadFile;
|
||||||
|
hosters.prefetchBaseline = async () => null;
|
||||||
|
|
||||||
// Mock fs.statSync for test file paths
|
// Mock fs.statSync for test file paths
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
@ -55,8 +56,8 @@ describe('UploadManager', () => {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
const statuses = events.map(e => e.status);
|
const statuses = events.map(e => e.status);
|
||||||
assert.ok(statuses.includes('queued'), 'should have queued status');
|
|
||||||
assert.ok(statuses.includes('done'), 'should have done status');
|
assert.ok(statuses.includes('done'), 'should have done status');
|
||||||
|
assert.ok(events.length > 0, 'should emit at least one progress event');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('emits batch-done with correct summary', async () => {
|
it('emits batch-done with correct summary', async () => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user