Fix Debrid-Link retry recovery
This commit is contained in:
@@ -76,6 +76,21 @@ function readSupportHistory() {
|
||||
return loadHistory(getStoragePaths());
|
||||
}
|
||||
|
||||
function extractDebugClientIp(req: http.IncomingMessage): string {
|
||||
const forwarded = req.headers["x-forwarded-for"];
|
||||
const forwardedValue = Array.isArray(forwarded) ? forwarded[0] : forwarded;
|
||||
const forwardedIp = String(forwardedValue || "").split(",")[0]?.trim();
|
||||
if (forwardedIp) {
|
||||
return forwardedIp;
|
||||
}
|
||||
const realIp = String(req.headers["x-real-ip"] || "").trim();
|
||||
if (realIp) {
|
||||
return realIp;
|
||||
}
|
||||
const remote = String(req.socket.remoteAddress || req.socket.address()?.address || "").trim();
|
||||
return remote.replace(/^::ffff:/i, "");
|
||||
}
|
||||
|
||||
function getAiManifestPath(baseDir: string = runtimeBaseDir): string {
|
||||
return path.join(baseDir, AI_MANIFEST_FILE);
|
||||
}
|
||||
@@ -431,7 +446,8 @@ function handleRequest(req: http.IncomingMessage, res: http.ServerResponse): voi
|
||||
if (traceConfig.enabled && traceConfig.logDebugRequests) {
|
||||
logTraceEvent("INFO", "debug-http", "Request", {
|
||||
method: req.method || "GET",
|
||||
url: sanitizeRequestUrlForTrace(req.url || "/")
|
||||
url: sanitizeRequestUrlForTrace(req.url || "/"),
|
||||
clientIp: extractDebugClientIp(req)
|
||||
});
|
||||
}
|
||||
|
||||
@@ -449,7 +465,8 @@ function handleRequest(req: http.IncomingMessage, res: http.ServerResponse): voi
|
||||
if (traceConfig.enabled && traceConfig.logDebugRequests) {
|
||||
logTraceEvent("WARN", "debug-http", "Unauthorized request", {
|
||||
method: req.method || "GET",
|
||||
url: sanitizeRequestUrlForTrace(req.url || "/")
|
||||
url: sanitizeRequestUrlForTrace(req.url || "/"),
|
||||
clientIp: extractDebugClientIp(req)
|
||||
});
|
||||
}
|
||||
jsonResponse(res, 401, { error: "Unauthorized" });
|
||||
|
||||
@@ -434,6 +434,11 @@ function shouldPreflightFinalizeItemFromDisk(item: DownloadItem): boolean {
|
||||
const text = `${item.fullStatus || ""} ${item.lastError || ""}`.toLowerCase();
|
||||
return text.includes("resume-link erneuern")
|
||||
|| text.includes("resume link erneuern")
|
||||
|| text.includes("direktlink erneuern")
|
||||
|| text.includes("direktlink erschöpft")
|
||||
|| text.includes("direct_link_retry_exhausted")
|
||||
|| text.includes("download_underflow")
|
||||
|| text.includes("resume_download_underflow")
|
||||
|| text.includes("range_ignored_on_resume")
|
||||
|| text.includes("server ignorierte range");
|
||||
}
|
||||
@@ -8142,16 +8147,21 @@ export class DownloadManager extends EventEmitter {
|
||||
if (response.status === 416 && existingBytes > 0) {
|
||||
await response.arrayBuffer().catch(() => undefined);
|
||||
const rangeTotal = parseContentRangeTotal(response.headers.get("content-range"));
|
||||
const expectedTotal = knownTotal && knownTotal > 0 ? knownTotal : rangeTotal;
|
||||
if (expectedTotal && existingBytes === expectedTotal) {
|
||||
item.totalBytes = expectedTotal;
|
||||
const expectedTotal = rangeTotal && rangeTotal > 0
|
||||
? rangeTotal
|
||||
: (knownTotal && knownTotal > 0 ? knownTotal : null);
|
||||
const closeEnoughToExpected = expectedTotal != null
|
||||
&& Math.abs(existingBytes - expectedTotal) <= ALLOCATION_UNIT_SIZE;
|
||||
if (expectedTotal != null && closeEnoughToExpected) {
|
||||
const finalizedTotal = Math.max(existingBytes, expectedTotal);
|
||||
item.totalBytes = finalizedTotal;
|
||||
item.downloadedBytes = existingBytes;
|
||||
item.progressPercent = 100;
|
||||
item.speedBps = 0;
|
||||
item.updatedAt = nowMs();
|
||||
logAttemptEvent("INFO", "HTTP 416 als vollständig behandelt", {
|
||||
existingBytes,
|
||||
expectedTotal
|
||||
expectedTotal: finalizedTotal
|
||||
});
|
||||
return { resumable: true };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user