🐛 fix: 'Ausgewählte starten' on queued jobs now force-adds to batch
Previously, clicking 'Ausgewählte starten' on 'Wartet' jobs during an active upload just showed a toast. But the jobs might NOT actually be in the batch (skipped during task building). Now: ALL selected queued/error/aborted jobs are sent to addJobsToBatch. The upload-manager has duplicate protection (checks jobAbortControllers) so jobs already in the batch are skipped. Jobs NOT in the batch get added and start uploading immediately. Toast now shows exact counts: "X hinzugefügt, Y waren schon im Batch" Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
ead6f97115
commit
a5b07c0f73
@ -698,21 +698,23 @@ class UploadManager extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addJobs(tasks) {
|
addJobs(tasks) {
|
||||||
if (!this.running || !tasks || tasks.length === 0) return;
|
if (!this.running || !tasks || tasks.length === 0) return 0;
|
||||||
const { signal } = this.abortController;
|
const { signal } = this.abortController;
|
||||||
const results = this._batchResults || new Map();
|
const results = this._batchResults || new Map();
|
||||||
|
let added = 0;
|
||||||
for (const task of tasks) {
|
for (const task of tasks) {
|
||||||
|
// Skip if this job is already being processed (prevent duplicates)
|
||||||
|
if (task.jobId && this.jobAbortControllers.has(task.jobId)) continue;
|
||||||
const fileName = path.basename(task.file);
|
const fileName = path.basename(task.file);
|
||||||
if (!results.has(task.file)) {
|
if (!results.has(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: [] });
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// Start each new job and track promises so batch-done waits for them
|
|
||||||
for (const task of tasks) {
|
|
||||||
this._additionalPromises.push(this._runJob(task, results, signal));
|
this._additionalPromises.push(this._runJob(task, results, signal));
|
||||||
|
added++;
|
||||||
}
|
}
|
||||||
|
return added;
|
||||||
}
|
}
|
||||||
|
|
||||||
cancelJobs(jobIds) {
|
cancelJobs(jobIds) {
|
||||||
|
|||||||
6
main.js
6
main.js
@ -786,9 +786,9 @@ ipcMain.handle('add-jobs-to-batch', (_event, payload) => {
|
|||||||
const jobs = payload && Array.isArray(payload.jobs) ? payload.jobs : [];
|
const jobs = payload && Array.isArray(payload.jobs) ? payload.jobs : [];
|
||||||
const tasks = buildUploadTasksFromJobs(config, jobs);
|
const tasks = buildUploadTasksFromJobs(config, jobs);
|
||||||
if (tasks.length === 0) return { added: 0 };
|
if (tasks.length === 0) return { added: 0 };
|
||||||
uploadManager.addJobs(tasks);
|
const added = uploadManager.addJobs(tasks);
|
||||||
debugLog(`add-jobs-to-batch: added ${tasks.length} tasks to running batch`);
|
debugLog(`add-jobs-to-batch: ${added} of ${tasks.length} tasks added (${tasks.length - added} already in batch)`);
|
||||||
return { added: tasks.length };
|
return { added };
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle('finish-after-active', () => {
|
ipcMain.handle('finish-after-active', () => {
|
||||||
|
|||||||
@ -1354,25 +1354,28 @@ function _markSkippedJobs(result) {
|
|||||||
|
|
||||||
async function startSelectedUpload() {
|
async function startSelectedUpload() {
|
||||||
if (uploading) {
|
if (uploading) {
|
||||||
// Batch already running — only add error/aborted/skipped jobs (not already-queued ones)
|
// Batch already running — add selected jobs (queued/error/aborted/skipped) to running batch
|
||||||
const retryable = queueJobs.filter(j => selectedJobIds.has(j.id) && ['error', 'aborted', 'skipped'].includes(j.status));
|
// Upload-manager has duplicate protection (skips jobs already tracked)
|
||||||
if (retryable.length > 0) {
|
const addable = queueJobs.filter(j => selectedJobIds.has(j.id) && ['queued', 'error', 'aborted', 'skipped'].includes(j.status));
|
||||||
retryable.forEach(j => {
|
if (addable.length > 0) {
|
||||||
|
addable.forEach(j => {
|
||||||
j.status = 'queued'; j.error = null; j.result = null;
|
j.status = 'queued'; j.error = null; j.result = null;
|
||||||
j.bytesUploaded = 0; j.speedKbs = 0; j.progress = 0; j.uploadId = null;
|
j.bytesUploaded = 0; j.speedKbs = 0; j.progress = 0; j.uploadId = null;
|
||||||
});
|
});
|
||||||
renderQueueTable();
|
renderQueueTable();
|
||||||
const result = await window.api.addJobsToBatch({
|
const result = await window.api.addJobsToBatch({
|
||||||
jobs: retryable.map(j => ({ id: j.id, file: j.file, fileName: j.fileName, hoster: j.hoster }))
|
jobs: addable.map(j => ({ id: j.id, file: j.file, fileName: j.fileName, hoster: j.hoster }))
|
||||||
});
|
});
|
||||||
_markSkippedJobs(result);
|
_markSkippedJobs(result);
|
||||||
persistQueueStateSoon();
|
persistQueueStateSoon();
|
||||||
showCopyToast(`${retryable.length} Jobs zum laufenden Upload hinzugefügt`);
|
const added = result && result.added || 0;
|
||||||
} else {
|
const alreadyInBatch = addable.length - added;
|
||||||
// All selected jobs are already queued/uploading — just inform user
|
if (added > 0 && alreadyInBatch > 0) {
|
||||||
const waiting = queueJobs.filter(j => selectedJobIds.has(j.id) && j.status === 'queued');
|
showCopyToast(`${added} Jobs hinzugefügt, ${alreadyInBatch} waren schon im Batch`);
|
||||||
if (waiting.length > 0) {
|
} else if (added > 0) {
|
||||||
showCopyToast(`${waiting.length} Jobs warten bereits auf ihren Upload-Slot`);
|
showCopyToast(`${added} Jobs zum laufenden Upload hinzugefügt`);
|
||||||
|
} else {
|
||||||
|
showCopyToast(`${addable.length} Jobs sind bereits im laufenden Batch`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user