refactor: unify queue start status handling
This commit is contained in:
parent
ad46c48c64
commit
b75930cb29
@ -24,6 +24,15 @@ let queuePersistTimer = null;
|
||||
let settingsSaveTimer = null;
|
||||
let lastUploadStats = { state: 'idle', globalSpeedKbs: 0, totalBytes: 0, elapsed: 0, activeJobs: 0 };
|
||||
const AUTO_CHECK_PREF_KEY = 'autoHealthCheckBeforeUpload';
|
||||
const STARTABLE_QUEUE_STATUSES = new Set(['preview', 'queued', 'error', 'aborted', 'skipped']);
|
||||
|
||||
function isStartableQueueStatus(status) {
|
||||
return STARTABLE_QUEUE_STATUSES.has(status);
|
||||
}
|
||||
|
||||
function isStartableQueueJob(job) {
|
||||
return !!job && isStartableQueueStatus(job.status);
|
||||
}
|
||||
|
||||
// Queue state
|
||||
let queueJobs = []; // { id, file, fileName, hoster, status, bytesUploaded, bytesTotal, speedKbs, elapsed, remaining, error, result, attempt, maxAttempts, link }
|
||||
@ -621,8 +630,9 @@ function updateUploadView() {
|
||||
function updateStartButton() {
|
||||
const btn = document.getElementById('startUploadBtn');
|
||||
const hosters = getSelectedHosters();
|
||||
const hasFiles = queueJobs.some(j => j.status === 'queued' || j.status === 'preview' || j.status === 'error');
|
||||
btn.disabled = uploading || hosters.length === 0 || !hasFiles;
|
||||
const hasQueuedJobs = queueJobs.some(isStartableQueueJob);
|
||||
const canBuildQueueFromSelection = selectedFiles.length > 0 && hosters.length > 0;
|
||||
btn.disabled = uploading || !(hasQueuedJobs || canBuildQueueFromSelection);
|
||||
}
|
||||
|
||||
function updateQueueActionButtons() {
|
||||
@ -631,7 +641,7 @@ function updateQueueActionButtons() {
|
||||
const hasSelection = selectedJobIds.size > 0;
|
||||
const hasUploadSelection = queueJobs.some((job) => selectedJobIds.has(job.id) && ['done', 'error', 'aborted', 'skipped'].includes(job.status));
|
||||
const hasAbortSelection = queueJobs.some((job) => selectedJobIds.has(job.id) && ['preview', 'queued', 'getting-server', 'uploading', 'retrying'].includes(job.status));
|
||||
const hasStartableSelection = queueJobs.some((job) => selectedJobIds.has(job.id) && ['preview', 'queued', 'error'].includes(job.status));
|
||||
const hasStartableSelection = queueJobs.some((job) => selectedJobIds.has(job.id) && isStartableQueueStatus(job.status));
|
||||
const hasMovableSelection = hasSelection && !uploading;
|
||||
|
||||
const startSelectedBtn = document.getElementById('startSelectedBtn');
|
||||
@ -644,7 +654,7 @@ function updateQueueActionButtons() {
|
||||
const moveDownBtn = document.getElementById('moveDownBtn');
|
||||
const moveBottomBtn = document.getElementById('moveBottomBtn');
|
||||
|
||||
if (startSelectedBtn) startSelectedBtn.disabled = uploading || !hasStartableSelection || getSelectedHosters().length === 0;
|
||||
if (startSelectedBtn) startSelectedBtn.disabled = uploading || !hasStartableSelection;
|
||||
if (reuploadBtn) reuploadBtn.disabled = !hasUploadSelection;
|
||||
if (abortSelectedBtn) abortSelectedBtn.disabled = !hasAbortSelection;
|
||||
if (finishStopBtn) finishStopBtn.disabled = !uploading;
|
||||
@ -1299,10 +1309,17 @@ async function startUpload() {
|
||||
updateQueueActionButtons();
|
||||
|
||||
const hosters = getSelectedHosters();
|
||||
if (hosters.length === 0) { alert('Bitte mindestens einen Hoster auswählen.'); uploading = false; updateQueueActionButtons(); return; }
|
||||
if (queueJobs.length === 0 && selectedFiles.length > 0) buildQueuePreview();
|
||||
if (queueJobs.length === 0 && selectedFiles.length > 0) {
|
||||
if (hosters.length === 0) {
|
||||
alert('Bitte mindestens einen Hoster auswählen.');
|
||||
uploading = false;
|
||||
updateQueueActionButtons();
|
||||
return;
|
||||
}
|
||||
buildQueuePreview();
|
||||
}
|
||||
|
||||
const jobsToStart = queueJobs.filter((job) => job.status === 'preview' || job.status === 'queued' || job.status === 'error');
|
||||
const jobsToStart = queueJobs.filter((job) => isStartableQueueStatus(job.status));
|
||||
if (jobsToStart.length === 0) { uploading = false; updateQueueActionButtons(); return; }
|
||||
|
||||
try {
|
||||
@ -1416,9 +1433,7 @@ async function startSelectedUpload() {
|
||||
updateQueueActionButtons();
|
||||
|
||||
const hosters = getSelectedHosters();
|
||||
if (hosters.length === 0) { alert('Bitte mindestens einen Hoster auswählen.'); uploading = false; updateQueueActionButtons(); return; }
|
||||
|
||||
const jobsToStart = queueJobs.filter((job) => selectedJobIds.has(job.id) && ['preview', 'queued', 'error', 'aborted', 'skipped'].includes(job.status));
|
||||
const jobsToStart = queueJobs.filter((job) => selectedJobIds.has(job.id) && isStartableQueueStatus(job.status));
|
||||
if (jobsToStart.length === 0) { uploading = false; updateQueueActionButtons(); return; }
|
||||
|
||||
try {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user