This commit is contained in:
1 parent
a5d6a1d5b1
commit
54750bda8f
4 files changed
+510
-31
No files matched your search
+120
-2
@@ -433,7 +433,6 @@ class UploadManager extends EventEmitter {
|
||||
const batchId = `batch-${Date.now()}`;
|
||||
const results = new Map(); // filePath -> { name, size, results: [] }
|
||||
this._batchResults = results;
|
||||
this._batchTaskCount = tasks.length;
|
||||
this._additionalPromises = []; // Track jobs added mid-batch via addJobs()
|
||||
this._batchTaskCount = tasks.length;
|
||||
|
||||
@@ -529,6 +528,7 @@ class UploadManager extends EventEmitter {
|
||||
let lastError = null;
|
||||
let lastFailureDetails = null;
|
||||
let finalAttempt = 0;
|
||||
let deferredUpload = null;
|
||||
|
||||
const recordFinalResult = (status, payload = {}) => {
|
||||
if (status === 'aborted' && jobAbortController.signal.reason === 'automation-pause' && !this.cancelledJobIds.has(jobId) && !batchSignal.aborted) payload = { ...payload, error: 'Warteschlange angehalten' };
|
||||
@@ -576,6 +576,53 @@ class UploadManager extends EventEmitter {
|
||||
});
|
||||
};
|
||||
|
||||
const releaseSlots = () => {
|
||||
if (globalSlotAcquired && globalSemaphore) globalSemaphore.release();
|
||||
if (hosterSlotAcquired) hosterSemaphore.release();
|
||||
globalSlotAcquired = false;
|
||||
hosterSlotAcquired = false;
|
||||
};
|
||||
|
||||
const acquireSlots = async () => {
|
||||
await hosterSemaphore.acquire(signal);
|
||||
hosterSlotAcquired = true;
|
||||
if (globalSemaphore) {
|
||||
await globalSemaphore.acquire(signal);
|
||||
globalSlotAcquired = true;
|
||||
}
|
||||
};
|
||||
|
||||
const finishDeferredUpload = async (deferred) => {
|
||||
try {
|
||||
const result = await this._awaitDeferredUpload(task, deferred, {
|
||||
uploadId, jobId, fileName, fileSize, signal, fileProbe: deferred.fileProbe, maxAttempts, releaseSlots, acquireSlots
|
||||
});
|
||||
if (signal.aborted || this.cancelledJobIds.has(jobId)) throw new Error('Aborted');
|
||||
emitFinalStatus('done', {
|
||||
result,
|
||||
speedKbs: deferred.speedKbs,
|
||||
elapsed: Math.round((Date.now() - deferred.startedAt) / 1000),
|
||||
attempt: deferred.attempt
|
||||
});
|
||||
recordFinalResult('done', { result, attempt: deferred.attempt });
|
||||
this._emitAccountSucceeded(task);
|
||||
} catch (err) {
|
||||
if (signal.aborted || this.cancelledJobIds.has(jobId)) {
|
||||
const error = 'Abgebrochen';
|
||||
emitFinalStatus('aborted', { error, attempt: deferred.attempt });
|
||||
recordFinalResult('aborted', { error, attempt: deferred.attempt });
|
||||
return;
|
||||
}
|
||||
const error = err && err.message ? err.message : 'Unbekannter Fehler';
|
||||
this._rotLog('deferred-upload-failure', {
|
||||
jobId, hoster: task.hoster, accountId: task.accountId, fileName, error,
|
||||
code: err && err.code ? err.code : null
|
||||
});
|
||||
emitFinalStatus('error', { error, attempt: deferred.attempt });
|
||||
recordFinalResult('error', { error, attempt: deferred.attempt });
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
if (signal.aborted || this.cancelledJobIds.has(jobId)) {
|
||||
const error = 'Abgebrochen';
|
||||
@@ -815,6 +862,11 @@ class UploadManager extends EventEmitter {
|
||||
this.sessionBytes += fileSize;
|
||||
this.activeJobs.delete(uploadId);
|
||||
|
||||
if (result.clouddropJob) {
|
||||
deferredUpload = { result, speedKbs: currentSpeedKbs, startedAt: jobStart, attempt, throttle, fileProbe };
|
||||
break;
|
||||
}
|
||||
|
||||
emitFinalStatus('done', {
|
||||
result,
|
||||
speedKbs: currentSpeedKbs,
|
||||
@@ -910,6 +962,8 @@ class UploadManager extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
if (deferredUpload) return await finishDeferredUpload(deferredUpload);
|
||||
|
||||
const wasStopped = this.stopAfterActive && !signal.aborted;
|
||||
const wasAborted = signal.aborted || this.cancelledJobIds.has(jobId);
|
||||
if (wasStopped || wasAborted) {
|
||||
@@ -1138,6 +1192,10 @@ class UploadManager extends EventEmitter {
|
||||
if (signal.aborted || this.cancelledJobIds.has(jobId)) throw new Error('Aborted');
|
||||
this.activeJobs.delete(uploadId);
|
||||
this.sessionBytes += fileSize;
|
||||
if (result.clouddropJob) {
|
||||
deferredUpload = { result, speedKbs: currentSpeedKbs, startedAt: jobStart, attempt, throttle, fileProbe };
|
||||
break;
|
||||
}
|
||||
emitFinalStatus('done', { result, speedKbs: currentSpeedKbs, elapsed: Math.round((Date.now() - jobStart) / 1000), attempt });
|
||||
recordFinalResult('done', { result });
|
||||
this._emitAccountSucceeded(task);
|
||||
@@ -1171,8 +1229,11 @@ class UploadManager extends EventEmitter {
|
||||
if (attempt >= maxAttempts) break;
|
||||
}
|
||||
}
|
||||
if (deferredUpload) break;
|
||||
}
|
||||
|
||||
if (deferredUpload) return await finishDeferredUpload(deferredUpload);
|
||||
|
||||
const stoppedLate = this.stopAfterActive && !signal.aborted;
|
||||
const abortedLate = signal.aborted || this.cancelledJobIds.has(jobId);
|
||||
if (stoppedLate || abortedLate) {
|
||||
@@ -1348,9 +1409,67 @@ class UploadManager extends EventEmitter {
|
||||
|
||||
async _executeUpload(task, progressCb, signal, throttle, fileProbe) {
|
||||
const result = await this._executeUploadUnchecked(task, progressCb, signal, throttle, fileProbe);
|
||||
if (task.hoster === 'clouddrop.cc' && result && result.clouddropJob) return result;
|
||||
return assertUploadConfirmation(result, task.hoster);
|
||||
}
|
||||
|
||||
async _awaitDeferredUpload(task, deferred, ctx) {
|
||||
const { uploadId, jobId, fileName, fileSize, signal, fileProbe, maxAttempts, releaseSlots, acquireSlots } = ctx;
|
||||
let pendingJob = deferred.result.clouddropJob;
|
||||
let reuploaded = false;
|
||||
for (;;) {
|
||||
releaseSlots();
|
||||
const emitServerState = (state) => this._emitProgress(uploadId, fileName, task.hoster, { accountId: task.accountId,
|
||||
jobId, status: 'uploading', progress: 1, bytesUploaded: fileSize, bytesTotal: fileSize,
|
||||
speedKbs: 0, elapsed: 0, remaining: 0, error: null, result: null,
|
||||
statusDetail: state && state.retrying ? 'Wird automatisch wiederholt' : 'Verarbeitung auf Clouddrop',
|
||||
attempt: deferred.attempt, maxAttempts
|
||||
});
|
||||
emitServerState(null);
|
||||
try {
|
||||
return assertUploadConfirmation(await pendingJob.wait(signal, emitServerState), task.hoster);
|
||||
} catch (err) {
|
||||
if (reuploaded || !err || err.expressReupload !== true || signal.aborted) throw err;
|
||||
reuploaded = true;
|
||||
this._rotLog('express-reupload', {
|
||||
jobId, hoster: task.hoster, accountId: task.accountId, fileName, error: err.message
|
||||
});
|
||||
this._emitProgress(uploadId, fileName, task.hoster, { accountId: task.accountId,
|
||||
jobId, status: 'retrying', progress: 0, bytesUploaded: 0, bytesTotal: fileSize,
|
||||
speedKbs: 0, elapsed: 0, remaining: 0,
|
||||
error: 'Express-Upload fehlgeschlagen, neuer Upload aus der Quelldatei', result: null, attempt: 1, maxAttempts: 1
|
||||
});
|
||||
await acquireSlots();
|
||||
const result = await this._reuploadFromSource(task, { uploadId, jobId, fileName, fileSize, signal, fileProbe, throttle: deferred.throttle });
|
||||
if (!result.clouddropJob) return result;
|
||||
pendingJob = result.clouddropJob;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async _reuploadFromSource(task, ctx) {
|
||||
const { uploadId, jobId, fileName, fileSize, signal, fileProbe, throttle } = ctx;
|
||||
const activeEntry = { jobId, speedKbs: 0, bytesUploaded: 0, hoster: task.hoster };
|
||||
this.activeJobs.set(uploadId, activeEntry);
|
||||
const progressCb = (bytesUploaded, bytesTotal) => {
|
||||
this._recordTransferred(activeEntry, bytesUploaded, fileSize);
|
||||
this._emitProgress(uploadId, fileName, task.hoster, { accountId: task.accountId,
|
||||
jobId, status: 'uploading',
|
||||
progress: bytesTotal > 0 ? Math.min(1, bytesUploaded / bytesTotal) : 0,
|
||||
bytesUploaded, bytesTotal, speedKbs: 0, elapsed: 0, remaining: 0,
|
||||
error: null, result: null, attempt: 1, maxAttempts: 1
|
||||
});
|
||||
};
|
||||
try {
|
||||
const result = await this._executeUpload(task, progressCb, signal, throttle, fileProbe);
|
||||
if (signal.aborted || this.cancelledJobIds.has(jobId)) throw new Error('Aborted');
|
||||
this.sessionBytes += fileSize;
|
||||
return result;
|
||||
} finally {
|
||||
this.activeJobs.delete(uploadId);
|
||||
}
|
||||
}
|
||||
|
||||
async _executeUploadUnchecked(task, progressCb, signal, throttle, fileProbe) {
|
||||
if (task.hoster === 'vidmoly.me' && task.username) {
|
||||
const vidmoly = new VidmolyUploader();
|
||||
@@ -1568,7 +1687,6 @@ class UploadManager extends EventEmitter {
|
||||
this._additionalPromises.push(this._runJob(task, results, signal));
|
||||
this._batchTaskCount++;
|
||||
addResult.added++;
|
||||
this._batchTaskCount++;
|
||||
}
|
||||
return addResult;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user