Report CloudDrop direct upload progress and stop when the server ends an upload

The lease client reports progress every five seconds, stops with a clear
message when the upload was closed on the server and falls back to the
server path when no direct target is available before anything was sent.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
SucukdeluxeandClaude Fable 5.2 committed 2026-11-22 14:27:15 +01:00
1 parent 953501df10
commit 456346d5ee
3 files changed
+44 -2

No files matched your search

+41 -2
View File
@@ -23,6 +23,7 @@ const DEFAULTS = Object.freeze({
warmupMs: 5000, warmupMs: 5000,
windowMs: 4000, windowMs: 4000,
requestTimeoutMs: 120000, requestTimeoutMs: 120000,
heartbeatMs: 5000,
apiTimeoutMs: 180000, apiTimeoutMs: 180000,
maxInflightChunks: 64, maxInflightChunks: 64,
}); });
@@ -175,6 +176,7 @@ function leaseError(prefix, reply) {
const error = new Error(`Clouddrop: ${prefix}${payload && payload.error ? `: ${payload.error}` : ` (HTTP ${reply.status})`}`); const error = new Error(`Clouddrop: ${prefix}${payload && payload.error ? `: ${payload.error}` : ` (HTTP ${reply.status})`}`);
error.status = reply.status; error.status = reply.status;
if (payload && typeof payload.code === 'string') error.code = payload.code; if (payload && typeof payload.code === 'string') error.code = payload.code;
if (payload && typeof payload.reason === 'string') error.reason = payload.reason;
return error; return error;
} }
@@ -256,6 +258,8 @@ async function uploadViaLease({ apiKey, baseUrl, dispatcher, userAgent, filePath
client: { tool: 'multi-hoster-uploader', version: options.appVersion || null, host: os.hostname(), settings: { connections: settings.connections, chunkSize: settings.chunkSize } }, client: { tool: 'multi-hoster-uploader', version: options.appVersion || null, host: os.hostname(), settings: { connections: settings.connections, chunkSize: settings.chunkSize } },
}, { signal, retries: 2 }); }, { signal, retries: 2 });
const leaseId = lease.leaseId; const leaseId = lease.leaseId;
const control = new AbortController();
signal = signal ? AbortSignal.any([signal, control.signal]) : control.signal;
const events = []; const events = [];
const event = (type, data) => events.push({ kind: 'event', type, t: Date.now(), ms: Math.round(performance.now() - started), ...data }); const event = (type, data) => events.push({ kind: 'event', type, t: Date.now(), ms: Math.round(performance.now() - started), ...data });
const handle = await fs.promises.open(filePath, 'r'); const handle = await fs.promises.open(filePath, 'r');
@@ -267,7 +271,34 @@ async function uploadViaLease({ apiKey, baseUrl, dispatcher, userAgent, filePath
let doneBytes = 0; let doneBytes = 0;
let slowRestarts = 0; let slowRestarts = 0;
let retries = 0; let retries = 0;
const report = (partAcked) => { if (progressCb) progressCb(Math.min(fileSize, doneBytes + partAcked), fileSize); }; let reportedBytes = 0;
const report = (partAcked) => {
reportedBytes = Math.min(fileSize, doneBytes + partAcked);
if (progressCb) progressCb(reportedBytes, fileSize);
};
let heartbeatBusy = false;
let heartbeatPrevious = { at: performance.now(), bytes: 0 };
const heartbeat = setInterval(async () => {
if (heartbeatBusy) return;
heartbeatBusy = true;
const at = performance.now();
const bytes = reportedBytes;
const seconds = (at - heartbeatPrevious.at) / 1000;
const bytesPerSecond = seconds > 0 ? Math.max(0, Math.round((bytes - heartbeatPrevious.bytes) / seconds)) : 0;
heartbeatPrevious = { at, bytes };
try {
await api.call('POST', `/upload/${leaseId}/progress`, { bytesUploaded: bytes, bytesPerSecond }, { retries: 0, timeoutMs: 15000 });
} catch (error) {
if (error && error.status === 410) {
control.abort(new Error(error.reason === 'cancelled_by_admin'
? 'Clouddrop: Upload wurde vom Administrator abgebrochen'
: 'Clouddrop: Upload wurde auf dem Server beendet'));
}
} finally {
heartbeatBusy = false;
}
}, settings.heartbeatMs);
heartbeat.unref?.();
async function sendPart(part, target) { async function sendPart(part, target) {
const key = d64(target.fileKey); const key = d64(target.fileKey);
@@ -412,7 +443,14 @@ async function uploadViaLease({ apiKey, baseUrl, dispatcher, userAgent, filePath
for (let attempt = 1; ; attempt++) { for (let attempt = 1; ; attempt++) {
const body = { avoidHosts: [...avoidHosts] }; const body = { avoidHosts: [...avoidHosts] };
if (reason) body.reason = reason; if (reason) body.reason = reason;
const target = await api.call('POST', `/upload/${leaseId}/parts/${part.index}/target`, body, { signal, retries: 2 }); let target;
try {
target = await api.call('POST', `/upload/${leaseId}/parts/${part.index}/target`, body, { signal, retries: 2 });
} catch (error) {
const nothingSent = doneBytes === 0 && attempt === 1;
if (nothingSent && !signal.aborted && error && (error.status === 507 || error.status === 503)) error.leaseFallback = true;
throw error;
}
target.host = new URL(target.uploadUrl).host; target.host = new URL(target.uploadUrl).host;
event('target', { part: part.index, attempt: target.attempt, host: target.host, server: target.timings }); event('target', { part: part.index, attempt: target.attempt, host: target.host, server: target.timings });
try { try {
@@ -465,6 +503,7 @@ async function uploadViaLease({ apiKey, baseUrl, dispatcher, userAgent, filePath
api.call('POST', `/upload/${leaseId}/abort`, { reason: String(error.message || error).slice(0, 180) }, { retries: 1 }).catch(() => {}); api.call('POST', `/upload/${leaseId}/abort`, { reason: String(error.message || error).slice(0, 180) }, { retries: 1 }).catch(() => {});
throw error; throw error;
} finally { } finally {
clearInterval(heartbeat);
await handle.close().catch(() => {}); await handle.close().catch(() => {});
} }
} }
+1
View File
@@ -157,6 +157,7 @@ class ClouddropUploader {
leaseAvailability.set(this._leaseCacheKey(), { enabled: false, until: this.now() + LEASE_DISABLED_CACHE_MS }); leaseAvailability.set(this._leaseCacheKey(), { enabled: false, until: this.now() + LEASE_DISABLED_CACHE_MS });
return null; return null;
} }
if (error && error.leaseFallback) return null;
throw error; throw error;
} }
} }
+2
View File
@@ -829,6 +829,8 @@
['Kein Ordnerpfad angegeben', 'No folder path was provided'], ['Kein Ordnerpfad angegeben', 'No folder path was provided'],
['Clouddrop: Datei ist leer', 'Clouddrop: The file is empty'], ['Clouddrop: Datei ist leer', 'Clouddrop: The file is empty'],
['Clouddrop: MEGA hat keine Abschluss-Kennung geliefert', 'Clouddrop: MEGA did not return a completion handle'], ['Clouddrop: MEGA hat keine Abschluss-Kennung geliefert', 'Clouddrop: MEGA did not return a completion handle'],
['Clouddrop: Upload wurde vom Administrator abgebrochen', 'Clouddrop: The upload was cancelled by the administrator'],
['Clouddrop: Upload wurde auf dem Server beendet', 'Clouddrop: The upload was ended on the server'],
['Clouddrop: Keine fileId in Upload-Antwort', 'Clouddrop: No fileId in the upload response'], ['Clouddrop: Keine fileId in Upload-Antwort', 'Clouddrop: No fileId in the upload response'],
['Clouddrop: Keine sessionId von /upload/init', 'Clouddrop: No sessionId from /upload/init'], ['Clouddrop: Keine sessionId von /upload/init', 'Clouddrop: No sessionId from /upload/init'],
['Clouddrop: Keine fileId im Job-Ergebnis', 'Clouddrop: No fileId in the job result'], ['Clouddrop: Keine fileId im Job-Ergebnis', 'Clouddrop: No fileId in the job result'],