The completed-upload dedup guard (_completedUploadKeys, "file|hoster") is the single source of truth that keeps a finished job from being re-materialised as a "Bereit" preview by buildQueuePreview(). Three independent paths leaked ghosts back into the queue: A) removeJobFromIndex() unconditionally DELETED the dedup key. The removeFromQueueOnDone auto-remove path (handleProgress), the batch-done sweep, and the terminal-job prune all call removeJobFromIndex on a *finished* job, so the guard handleProgress had just added was immediately wiped and buildQueuePreview re-created the job as a preview both mid-session and after restart. removeJobFromIndex now takes keepCompletedKey; the three auto-removal call sites pass true (keep the guard), while the manual-delete sites keep the old behaviour (drop the guard so the user can re-add the file). D/E) The dedup guard lived only in memory, so every restart began with an empty set and buildQueuePreview rebuilt ghosts from the persisted selectedFiles. buildPersistedQueueState() now serialises the keys whose file is still in the snapshot (completedKeys) and restoreQueueStateFromConfig() re-seeds them. To keep deliberate re-uploads working, applyHosterSelection() clears the persisted key for every freshly (re-)added file: re-adding through the hoster modal is the explicit "upload this again" signal. Both retry paths (retrySelectedJobs, _retryFailedFromBuckets) mutate the existing job in place instead of relying on buildQueuePreview, so they are unaffected. H) buildQueuePreview() excluded error jobs from its existingKeys set, so a file+hoster that already had an 'error' row got a second 'preview' row stacked beside it. Error jobs now count as existing. B/C) parseUploadLogLine() took the filename from a fixed field index and trimmed it. A pipe inside the link shifted the field (entry lost from the log-based dedup) and trimming broke matching against the untrimmed OS basename used as the queue-job key. The filename is now the last non-empty field and is no longer trimmed, so log lines with pipes in the URL and leading-space filenames both match end-to-end. 362 tests pass, lint clean on all touched files. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
35 lines
1.3 KiB
JavaScript
35 lines
1.3 KiB
JavaScript
(function (root) {
|
|
'use strict';
|
|
|
|
function _pad(n) { return String(n).padStart(2, '0'); }
|
|
|
|
function formatUploadLogLine(date, hoster, link, fileName) {
|
|
const d = date instanceof Date ? date : new Date();
|
|
const dateStr = `${d.getFullYear()}-${_pad(d.getMonth() + 1)}-${_pad(d.getDate())} ` +
|
|
`${_pad(d.getHours())}:${_pad(d.getMinutes())}:${_pad(d.getSeconds())}`;
|
|
return `${dateStr}|${hoster}|${link}||${fileName}|\n`;
|
|
}
|
|
|
|
function parseUploadLogLine(line) {
|
|
if (typeof line !== 'string') return null;
|
|
const trimmed = line.trim();
|
|
if (!trimmed || trimmed.startsWith('#')) return null;
|
|
const parts = trimmed.split('|');
|
|
if (parts.length < 5) return null;
|
|
const hoster = (parts[1] || '').trim();
|
|
let fileName = '';
|
|
for (let i = parts.length - 1; i >= 4; i--) {
|
|
if (parts[i].trim() !== '') { fileName = parts[i]; break; }
|
|
}
|
|
if (!hoster || !fileName) return null;
|
|
const tsStr = (parts[0] || '').trim();
|
|
const tsParsed = tsStr ? Date.parse(tsStr.replace(' ', 'T')) : NaN;
|
|
const ts = isNaN(tsParsed) ? undefined : tsParsed;
|
|
return { hoster, fileName, ts };
|
|
}
|
|
|
|
const api = { formatUploadLogLine, parseUploadLogLine };
|
|
if (typeof module !== 'undefined' && module.exports) module.exports = api;
|
|
else if (root) root.UploadLog = api;
|
|
})(typeof window !== 'undefined' ? window : this);
|