feat(hosters): resolve 1Fichier and DDownload metadata
Resolve public filenames, exact sizes, availability, aliases, and offline states for 1Fichier and DDownload without replacing the existing link collector. Preserve resolved names when debrid responses return generic filenames, protect partial-download resume paths, validate redirect identity, and journal final metadata renames for crash-safe recovery.
This commit is contained in:
+248
-17
@@ -25,8 +25,11 @@ const ALL_DEBRID_API_BASE_V41 = "https://api.alldebrid.com/v4.1";
|
||||
|
||||
const MEGA_DEBRID_API_BASE = "https://www.mega-debrid.eu/api.php";
|
||||
|
||||
const ONEFICHIER_API_BASE = "https://api.1fichier.com/v1";
|
||||
const ONEFICHIER_URL_RE = /^https?:\/\/(?:www\.)?(?:1fichier\.com|alterupload\.com|cjoint\.net|desfichiers\.com|dfichiers\.com|megadl\.fr|mesfichiers\.org|piecejointe\.net|pjointe\.com|tenvoi\.com|dl4free\.com)\/\?([a-z0-9]{5,20})$/i;
|
||||
const ONEFICHIER_API_BASE = "https://api.1fichier.com/v1";
|
||||
const ONEFICHIER_CHECK_URL = "https://1fichier.com/check_links.pl";
|
||||
const ONEFICHIER_CHECK_BATCH_SIZE = 100;
|
||||
const ONEFICHIER_CHECK_BATCH_DELAY_MS = 1000;
|
||||
const ONEFICHIER_URL_RE = /^https?:\/\/(?:www\.)?(?:1fichier\.com|alterupload\.com|cjoint\.net|desfichiers\.(?:com|net)|dfichiers\.com|megadl\.fr|mesfichiers\.org|piecejointe\.net|pjointe\.com|tenvoi\.com|dl4free\.com)\/\?([a-z0-9]{5,20})$/i;
|
||||
|
||||
const DEBRID_LINK_API_BASE = "https://debrid-link.com/api/v2";
|
||||
const DEBRID_LINK_KEY_QUOTA_ERRORS = new Set(["maxLink", "maxData"]);
|
||||
@@ -1675,7 +1678,7 @@ function looksLikeFileName(value: string): boolean {
|
||||
return /\.(?:part\d+\.rar|r\d{2}|rar|zip|7z|tar|gz|bz2|xz|iso|mkv|mp4|avi|mov|wmv|m4v|m2ts|ts|webm|mp3|flac|aac|srt|ass|sub)$/i.test(value);
|
||||
}
|
||||
|
||||
export function normalizeResolvedFilename(value: string): string {
|
||||
export function normalizeResolvedFilename(value: string): string {
|
||||
const candidate = decodeHtmlEntities(String(value || ""))
|
||||
.replace(/<[^>]*>/g, " ")
|
||||
.replace(/\s+/g, " ")
|
||||
@@ -1686,8 +1689,20 @@ export function normalizeResolvedFilename(value: string): string {
|
||||
if (!candidate || candidate.length > 260 || !looksLikeFileName(candidate) || looksLikeOpaqueFilename(candidate)) {
|
||||
return "";
|
||||
}
|
||||
return candidate;
|
||||
}
|
||||
return candidate;
|
||||
}
|
||||
|
||||
function normalizePublicHosterFilename(value: string): string {
|
||||
const candidate = decodeHtmlEntities(String(value || ""))
|
||||
.replace(/<[^>]*>/g, " ")
|
||||
.replace(/[\u0000-\u001f\u007f]/g, "")
|
||||
.replace(/\s+/g, " ")
|
||||
.replace(/^['"]+|['"]+$/g, "")
|
||||
.trim();
|
||||
const fileName = candidate.split(/[\\/]/).pop()?.trim() || "";
|
||||
if (!fileName || fileName === "." || fileName === ".." || fileName.length > 260 || looksLikeOpaqueFilename(fileName)) return "";
|
||||
return fileName;
|
||||
}
|
||||
|
||||
export function filenameFromRapidgatorUrlPath(link: string): string {
|
||||
try {
|
||||
@@ -1901,7 +1916,7 @@ export function parseRapidgatorFileSize(value: string | null | undefined): numbe
|
||||
return Number.isSafeInteger(bytes) ? bytes : null;
|
||||
}
|
||||
|
||||
export async function checkRapidgatorOnline(
|
||||
export async function checkRapidgatorOnline(
|
||||
link: string,
|
||||
signal?: AbortSignal
|
||||
): Promise<RapidgatorCheckResult | null> {
|
||||
@@ -1975,10 +1990,106 @@ export async function checkRapidgatorOnline(
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function buildBestDebridRequests(link: string, token: string): BestDebridRequest[] {
|
||||
return null;
|
||||
}
|
||||
|
||||
export interface OneFichierCheckResult {
|
||||
online: boolean;
|
||||
fileName: string;
|
||||
fileSizeBytes: number | null;
|
||||
accessRestricted: boolean;
|
||||
}
|
||||
|
||||
export function isOneFichierLink(link: string): boolean {
|
||||
return ONEFICHIER_URL_RE.test(String(link || "").trim());
|
||||
}
|
||||
|
||||
function getOneFichierLinkId(link: string): string {
|
||||
return String(link || "").trim().match(ONEFICHIER_URL_RE)?.[1]?.toLowerCase() || "";
|
||||
}
|
||||
|
||||
function parseOneFichierCheckResponse(responseText: string, linksById: Map<string, string[]>): Map<string, OneFichierCheckResult> {
|
||||
const results = new Map<string, OneFichierCheckResult>();
|
||||
for (const rawLine of String(responseText || "").split(/\r?\n/)) {
|
||||
const line = rawLine.trim();
|
||||
if (!line) continue;
|
||||
const id = line.match(/\?([a-z0-9]{5,20})(?:;|$)/i)?.[1]?.toLowerCase() || "";
|
||||
const requestedLinks = linksById.get(id);
|
||||
if (!requestedLinks?.length) continue;
|
||||
|
||||
let result: OneFichierCheckResult | null = null;
|
||||
if (/;;;(?:NOT FOUND|BAD LINK)\s*$/i.test(line)) {
|
||||
result = { online: false, fileName: "", fileSizeBytes: null, accessRestricted: false };
|
||||
} else if (/;;;PRIVATE\s*$/i.test(line)) {
|
||||
result = { online: true, fileName: "", fileSizeBytes: null, accessRestricted: true };
|
||||
} else {
|
||||
const firstSeparator = line.indexOf(";");
|
||||
const lastSeparator = line.lastIndexOf(";");
|
||||
const fileName = decodeHtmlEntities(firstSeparator >= 0 && lastSeparator > firstSeparator ? line.slice(firstSeparator + 1, lastSeparator) : "").trim();
|
||||
const fileSizeBytes = Number(lastSeparator >= 0 ? line.slice(lastSeparator + 1).trim() : NaN);
|
||||
if (fileName && Number.isSafeInteger(fileSizeBytes) && fileSizeBytes >= 0) {
|
||||
result = { online: true, fileName, fileSizeBytes, accessRestricted: false };
|
||||
}
|
||||
}
|
||||
|
||||
if (result) {
|
||||
for (const link of requestedLinks) results.set(link, result);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
export async function checkOneFichierLinks(links: string[], signal?: AbortSignal): Promise<Map<string, OneFichierCheckResult>> {
|
||||
const supportedLinks = Array.from(new Set(links.map((link) => String(link || "").trim()).filter(isOneFichierLink)));
|
||||
const results = new Map<string, OneFichierCheckResult>();
|
||||
|
||||
for (let offset = 0; offset < supportedLinks.length; offset += ONEFICHIER_CHECK_BATCH_SIZE) {
|
||||
if (offset > 0) await sleepWithSignal(ONEFICHIER_CHECK_BATCH_DELAY_MS, signal);
|
||||
const batch = supportedLinks.slice(offset, offset + ONEFICHIER_CHECK_BATCH_SIZE);
|
||||
const linksById = new Map<string, string[]>();
|
||||
const body = new URLSearchParams();
|
||||
for (const link of batch) {
|
||||
body.append("links[]", link);
|
||||
const id = getOneFichierLinkId(link);
|
||||
const existing = linksById.get(id) ?? [];
|
||||
existing.push(link);
|
||||
linksById.set(id, existing);
|
||||
}
|
||||
|
||||
for (let attempt = 1; attempt <= REQUEST_RETRIES + 1; attempt += 1) {
|
||||
try {
|
||||
if (signal?.aborted) throw new Error("aborted:debrid");
|
||||
const response = await fetch(ONEFICHIER_CHECK_URL, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
||||
body,
|
||||
signal: withTimeoutSignal(signal, API_TIMEOUT_MS)
|
||||
});
|
||||
if (!response.ok) {
|
||||
try { await response.body?.cancel(); } catch { }
|
||||
if (response.status === 429) break;
|
||||
if (shouldRetryStatus(response.status) && attempt <= REQUEST_RETRIES) {
|
||||
await sleepWithSignal(retryDelayForResponse(response, attempt), signal);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
const parsed = parseOneFichierCheckResponse(await readResponseTextLimited(response, RAPIDGATOR_SCAN_MAX_BYTES, signal), linksById);
|
||||
for (const [link, result] of parsed) results.set(link, result);
|
||||
break;
|
||||
} catch (error) {
|
||||
const errorText = compactErrorText(error);
|
||||
if (signal?.aborted || (/aborted/i.test(errorText) && !/timeout/i.test(errorText))) throw error;
|
||||
if (attempt > REQUEST_RETRIES || !isRetryableErrorText(errorText)) break;
|
||||
await sleepWithSignal(retryDelay(attempt), signal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
function buildBestDebridRequests(link: string, token: string): BestDebridRequest[] {
|
||||
const linkParam = encodeURIComponent(link);
|
||||
const safeToken = String(token || "").trim();
|
||||
const useAuthHeader = Boolean(safeToken);
|
||||
@@ -3672,11 +3783,132 @@ class OneFichierClient {
|
||||
}
|
||||
}
|
||||
|
||||
const DDOWNLOAD_URL_RE = /^https?:\/\/(?:www\.)?(?:ddownload\.com|ddl\.to)\/([a-z0-9]+)/i;
|
||||
const DDOWNLOAD_WEB_BASE = "https://ddownload.com";
|
||||
const DDOWNLOAD_WEB_UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36";
|
||||
|
||||
class DdownloadClient {
|
||||
const DDOWNLOAD_URL_RE = /^https?:\/\/(?:www\.)?(?:ddownload\.com|ddl\.to)\/([a-z0-9]{8,20})(?:\/|$)/i;
|
||||
const DDOWNLOAD_WEB_BASE = "https://ddownload.com";
|
||||
const DDOWNLOAD_WEB_UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36";
|
||||
const DDOWNLOAD_SCAN_MAX_BYTES = 512 * 1024;
|
||||
const DDOWNLOAD_FILE_NOT_FOUND_RE = /(?:File Not Found|No such file|file was removed|file was banned|Unavailable for legal reasons)/i;
|
||||
|
||||
export interface DdownloadCheckResult {
|
||||
online: boolean;
|
||||
fileName: string;
|
||||
fileSizeBytes: number | null;
|
||||
}
|
||||
|
||||
export function isDdownloadLink(link: string): boolean {
|
||||
return DDOWNLOAD_URL_RE.test(String(link || "").trim());
|
||||
}
|
||||
|
||||
function getDdownloadFileCode(link: string): string {
|
||||
return String(link || "").trim().match(DDOWNLOAD_URL_RE)?.[1]?.toLowerCase() || "";
|
||||
}
|
||||
|
||||
export function filenameFromDdownloadUrlPath(link: string): string {
|
||||
if (!isDdownloadLink(link)) return "";
|
||||
try {
|
||||
const parts = new URL(link).pathname.split("/").filter(Boolean);
|
||||
for (let index = parts.length - 1; index >= 1; index -= 1) {
|
||||
const normalized = normalizePublicHosterFilename(safeDecode(parts[index]).replace(/\.html?$/i, ""));
|
||||
if (normalized) return normalized;
|
||||
}
|
||||
} catch {
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
export function extractDdownloadFilenameFromHtml(html: string): string {
|
||||
const patterns = [
|
||||
/class=["'][^"']*dk-dl-icon[^"']*["'][^>]*data-fn=["']([^"']+)["']/i,
|
||||
/data-fn=["']([^"']+)["'][^>]*class=["'][^"']*dk-dl-icon[^"']*["']/i,
|
||||
/<h2[^>]*class=["'][^"']*dk-dl-name[^"']*["'][^>]*>([^<]+)<\/h2>/i,
|
||||
/class=["'][^"']*file-info-name[^"']*["'][^>]*>([^<]+)</i
|
||||
];
|
||||
for (const pattern of patterns) {
|
||||
const normalized = normalizePublicHosterFilename(html.match(pattern)?.[1] || "");
|
||||
if (normalized) return normalized;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
export function parseDdownloadFileSize(value: string | null | undefined): number | null {
|
||||
return parseRapidgatorFileSize(value);
|
||||
}
|
||||
|
||||
export async function checkDdownloadOnline(link: string, signal?: AbortSignal): Promise<DdownloadCheckResult | null> {
|
||||
if (!isDdownloadLink(link)) return null;
|
||||
const originalFileCode = getDdownloadFileCode(link);
|
||||
const originalProtocol = new URL(link).protocol.toLowerCase();
|
||||
const headers = {
|
||||
"User-Agent": DDOWNLOAD_WEB_UA,
|
||||
Accept: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
||||
"Accept-Language": "en-US,en;q=0.9,de;q=0.8"
|
||||
};
|
||||
|
||||
let requestUrl = link;
|
||||
let redirectCount = 0;
|
||||
for (let attempt = 1; attempt <= REQUEST_RETRIES + 1; attempt += 1) {
|
||||
try {
|
||||
if (signal?.aborted) throw new Error("aborted:debrid");
|
||||
const response = await fetch(requestUrl, { method: "GET", redirect: "manual", headers, signal: withTimeoutSignal(signal, API_TIMEOUT_MS) });
|
||||
if (response.status >= 300 && response.status < 400) {
|
||||
const location = response.headers.get("location");
|
||||
try { await response.body?.cancel(); } catch { }
|
||||
if (!location || redirectCount >= 3) return null;
|
||||
let nextUrl = "";
|
||||
try {
|
||||
nextUrl = new URL(location, requestUrl).toString();
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
if (!isDdownloadLink(nextUrl) || getDdownloadFileCode(nextUrl) !== originalFileCode) return null;
|
||||
if (originalProtocol === "https:" && new URL(nextUrl).protocol.toLowerCase() !== "https:") return null;
|
||||
requestUrl = nextUrl;
|
||||
redirectCount += 1;
|
||||
attempt -= 1;
|
||||
continue;
|
||||
}
|
||||
if (response.status === 404) {
|
||||
try { await response.body?.cancel(); } catch { }
|
||||
return { online: false, fileName: "", fileSizeBytes: null };
|
||||
}
|
||||
if (!response.ok) {
|
||||
try { await response.body?.cancel(); } catch { }
|
||||
if (response.status === 429) return null;
|
||||
if (shouldRetryStatus(response.status) && attempt <= REQUEST_RETRIES) {
|
||||
await sleepWithSignal(retryDelayForResponse(response, attempt), signal);
|
||||
continue;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
const contentType = String(response.headers.get("content-type") || "").toLowerCase();
|
||||
const contentLength = Number(response.headers.get("content-length") || NaN);
|
||||
if (contentType && !contentType.includes("text/html") && !contentType.includes("application/xhtml") && !contentType.includes("text/plain")) {
|
||||
try { await response.body?.cancel(); } catch { }
|
||||
return null;
|
||||
}
|
||||
if (!contentType && Number.isFinite(contentLength) && contentLength > DDOWNLOAD_SCAN_MAX_BYTES) {
|
||||
try { await response.body?.cancel(); } catch { }
|
||||
return null;
|
||||
}
|
||||
const html = await readResponseTextLimited(response, DDOWNLOAD_SCAN_MAX_BYTES, signal);
|
||||
const pageName = extractDdownloadFilenameFromHtml(html);
|
||||
const hasFilePage = Boolean(pageName) || /\bdk-dl-(?:icon|name|size)\b/i.test(html) || /Your file is ready to download|Regular Download via DDownload/i.test(html);
|
||||
if (!hasFilePage && DDOWNLOAD_FILE_NOT_FOUND_RE.test(html)) return { online: false, fileName: "", fileSizeBytes: null };
|
||||
if (!hasFilePage) return null;
|
||||
const sizeMatch = html.match(/class=["'][^"']*dk-dl-size[^"']*["'][^>]*>([^<]+)</i)
|
||||
|| html.match(/(?:File\s*size|Dateigröße)\s*[:\-]?\s*<[^>]*>([^<]+)</i);
|
||||
return { online: true, fileName: pageName || filenameFromDdownloadUrlPath(link), fileSizeBytes: parseDdownloadFileSize(sizeMatch?.[1]) };
|
||||
} catch (error) {
|
||||
const errorText = compactErrorText(error);
|
||||
if (signal?.aborted || (/aborted/i.test(errorText) && !/timeout/i.test(errorText))) throw error;
|
||||
if (attempt > REQUEST_RETRIES || !isRetryableErrorText(errorText)) return null;
|
||||
}
|
||||
if (attempt <= REQUEST_RETRIES) await sleepWithSignal(retryDelay(attempt), signal);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
class DdownloadClient {
|
||||
private login: string;
|
||||
private password: string;
|
||||
private cookies: string = "";
|
||||
@@ -3774,8 +4006,7 @@ class DdownloadClient {
|
||||
|
||||
const idVal = html.match(/name="id" value="([^"]+)"/)?.[1] || fileCode;
|
||||
const randVal = html.match(/name="rand" value="([^"]+)"/)?.[1] || "";
|
||||
const fileNameMatch = html.match(/class="file-info-name"[^>]*>([^<]+)</);
|
||||
const fileName = fileNameMatch?.[1]?.trim() || filenameFromUrl(link);
|
||||
const fileName = extractDdownloadFilenameFromHtml(html) || filenameFromDdownloadUrlPath(link) || filenameFromUrl(link);
|
||||
|
||||
const dlBody = new URLSearchParams({
|
||||
op: "download2",
|
||||
|
||||
+293
-28
@@ -58,7 +58,7 @@ function releaseTlsSkip(): void {
|
||||
}
|
||||
import { cleanupCancelledPackageArtifactsAsync, removeDownloadLinkArtifacts, removeSampleArtifacts } from "./cleanup";
|
||||
import { planDownloadCompletion, reconcileFinalizedSize, validateDownloadedFileCompletion } from "./download-completion";
|
||||
import { AllDebridWebUnrestrictor, BestDebridWebUnrestrictor, DebridService, MegaWebUnrestrictor, RealDebridWebUnrestrictor, checkRapidgatorOnline, fetchAllDebridHostInfo, getAvailableDebridLinkApiKeys, getAvailableMegaDebridAccounts, getAvailableRealDebridAccounts, getMegaDebridAccountCooldownState, getMegaDebridInFlightCountForMode, getRealDebridAccountAttemptTimeoutMs, pruneExpiredDebridLinkRuntimeState, pruneExpiredMegaDebridRuntimeState, pruneExpiredRealDebridRuntimeState, releaseRealDebridAccountCooldown } from "./debrid";
|
||||
import { AllDebridWebUnrestrictor, BestDebridWebUnrestrictor, DebridService, MegaWebUnrestrictor, RealDebridWebUnrestrictor, checkDdownloadOnline, checkOneFichierLinks, checkRapidgatorOnline, fetchAllDebridHostInfo, filenameFromDdownloadUrlPath, getAvailableDebridLinkApiKeys, getAvailableMegaDebridAccounts, getAvailableRealDebridAccounts, getMegaDebridAccountCooldownState, getMegaDebridInFlightCountForMode, getRealDebridAccountAttemptTimeoutMs, isDdownloadLink, isOneFichierLink, pruneExpiredDebridLinkRuntimeState, pruneExpiredMegaDebridRuntimeState, pruneExpiredRealDebridRuntimeState, releaseRealDebridAccountCooldown, type DdownloadCheckResult, type OneFichierCheckResult } from "./debrid";
|
||||
import { cleanupArchives, clearExtractResumeState, collectArchiveCleanupTargets, detectArchiveSignature, extractPackageArchives, findArchiveCandidates, hasAnyFilesRecursive, removeEmptyDirectoryTree, resetExtractorCachesForPasswordChange, type ExtractArchiveFailureInfo } from "./extractor";
|
||||
import { validateFileAgainstManifest } from "./integrity";
|
||||
import { classifyDiskError } from "./fs-error";
|
||||
@@ -2002,14 +2002,17 @@ export class DownloadManager extends EventEmitter {
|
||||
});
|
||||
}
|
||||
this.applyOnStartCleanupPolicy();
|
||||
this.normalizeSessionStatuses();
|
||||
this.restoreTargetPathReservations();
|
||||
this.resolveExistingQueuedOpaqueFilenames();
|
||||
this.normalizeSessionStatuses();
|
||||
this.restoreTargetPathReservations();
|
||||
this.finalizeExistingResolvedMetadataTargets();
|
||||
this.resolveExistingQueuedOpaqueFilenames();
|
||||
this.revalidateCompletedItems();
|
||||
void this.recoverRetryableItems("startup").catch((err) => logger.warn(`recoverRetryableItems Fehler (startup): ${compactErrorText(err)}`));
|
||||
this.recoverPostProcessingOnStartup();
|
||||
this.checkExistingRapidgatorLinks();
|
||||
void this.cleanupExistingExtractedArchives().catch((err) => logger.warn(`cleanupExistingExtractedArchives Fehler (constructor): ${compactErrorText(err)}`));
|
||||
this.recoverPostProcessingOnStartup();
|
||||
this.checkExistingRapidgatorLinks();
|
||||
this.checkExistingDdownloadLinks();
|
||||
this.checkExistingOneFichierLinks();
|
||||
void this.cleanupExistingExtractedArchives().catch((err) => logger.warn(`cleanupExistingExtractedArchives Fehler (constructor): ${compactErrorText(err)}`));
|
||||
setRotationEventListener(() => {
|
||||
if (this.rotationListenerActive === false) {
|
||||
return;
|
||||
@@ -2021,7 +2024,9 @@ export class DownloadManager extends EventEmitter {
|
||||
});
|
||||
}
|
||||
|
||||
private rotationListenerActive = true;
|
||||
private rotationListenerActive = true;
|
||||
|
||||
private metadataChecksActive = true;
|
||||
|
||||
public getPackageLogPath(packageId: string): string | null {
|
||||
const pkg = this.session.packages[packageId];
|
||||
@@ -3231,9 +3236,11 @@ export class DownloadManager extends EventEmitter {
|
||||
if (unresolvedByLink.size > 0) {
|
||||
void this.resolveQueuedFilenames(unresolvedByLink).catch((err) => logger.warn(`resolveQueuedFilenames Fehler (addPackages): ${compactErrorText(err)}`));
|
||||
}
|
||||
if (newItemIds.length > 0) {
|
||||
void this.checkRapidgatorLinks(newItemIds).catch((err) => logger.warn(`checkRapidgatorLinks Fehler: ${compactErrorText(err)}`));
|
||||
}
|
||||
if (newItemIds.length > 0) {
|
||||
void this.checkRapidgatorLinks(newItemIds).catch((err) => logger.warn(`checkRapidgatorLinks Fehler: ${compactErrorText(err)}`));
|
||||
void this.checkDdownloadItems(newItemIds).catch((err) => logger.warn(`checkDdownloadItems Fehler: ${compactErrorText(err)}`));
|
||||
void this.checkOneFichierItems(newItemIds).catch((err) => logger.warn(`checkOneFichierItems Fehler: ${compactErrorText(err)}`));
|
||||
}
|
||||
return { addedPackages, addedLinks };
|
||||
}
|
||||
|
||||
@@ -3558,7 +3565,7 @@ export class DownloadManager extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
private applyRapidgatorCheckResult(item: DownloadItem, result: Awaited<ReturnType<typeof checkRapidgatorOnline>>): void {
|
||||
private applyRapidgatorCheckResult(item: DownloadItem, result: Awaited<ReturnType<typeof checkRapidgatorOnline>>): void {
|
||||
if (!result) {
|
||||
if (item.onlineStatus === "checking") {
|
||||
item.onlineStatus = undefined;
|
||||
@@ -3592,10 +3599,227 @@ export class DownloadManager extends EventEmitter {
|
||||
}
|
||||
item.onlineStatus = "online";
|
||||
item.updatedAt = nowMs();
|
||||
}
|
||||
}
|
||||
|
||||
private checkExistingRapidgatorLinks(): void {
|
||||
}
|
||||
}
|
||||
|
||||
private async checkDdownloadItems(itemIds: string[]): Promise<void> {
|
||||
const itemsToCheck: Array<{ itemId: string; url: string }> = [];
|
||||
for (const itemId of itemIds) {
|
||||
const item = this.session.items[itemId];
|
||||
if (!item || !isDdownloadLink(item.url)) continue;
|
||||
if (item.status !== "queued" && item.status !== "reconnect_wait" && item.status !== "completed") continue;
|
||||
item.onlineStatus = "checking";
|
||||
itemsToCheck.push({ itemId, url: item.url });
|
||||
}
|
||||
if (itemsToCheck.length === 0) return;
|
||||
this.emitState();
|
||||
const checkedUrls = new Map<string, Promise<DdownloadCheckResult | null>>();
|
||||
await runWithLimitedConcurrency(itemsToCheck, 4, async ({ itemId, url }) => {
|
||||
let pending = checkedUrls.get(url);
|
||||
if (!pending) {
|
||||
pending = checkDdownloadOnline(url);
|
||||
checkedUrls.set(url, pending);
|
||||
}
|
||||
let result: DdownloadCheckResult | null = null;
|
||||
try {
|
||||
result = await pending;
|
||||
} catch (error) {
|
||||
logger.warn(`DDownload-Linkprüfung fehlgeschlagen: ${compactErrorText(error)}`);
|
||||
}
|
||||
if (!this.metadataChecksActive) return;
|
||||
const item = this.session.items[itemId];
|
||||
if (item) this.applyDdownloadCheckResult(item, result);
|
||||
this.persistSoon();
|
||||
this.emitState();
|
||||
});
|
||||
this.persistSoon();
|
||||
}
|
||||
|
||||
private applyDdownloadCheckResult(item: DownloadItem, result: DdownloadCheckResult | null): void {
|
||||
if (!result) {
|
||||
if (item.onlineStatus === "checking") item.onlineStatus = undefined;
|
||||
return;
|
||||
}
|
||||
if (!result.online) {
|
||||
item.onlineStatus = "offline";
|
||||
item.updatedAt = nowMs();
|
||||
if (item.status === "queued" || item.status === "reconnect_wait") {
|
||||
item.status = "failed";
|
||||
item.fullStatus = "Offline";
|
||||
item.lastError = "Datei nicht gefunden auf DDownload";
|
||||
if (this.runItemIds.has(item.id)) this.recordRunOutcome(item.id, "failed");
|
||||
const pkg = this.session.packages[item.packageId];
|
||||
if (pkg) this.refreshPackageStatus(pkg);
|
||||
}
|
||||
return;
|
||||
}
|
||||
const unresolvedFileName = looksLikeOpaqueFilename(item.fileName)
|
||||
|| (!filenameFromDdownloadUrlPath(item.url) && item.fileName === filenameFromUrl(item.url));
|
||||
if (result.fileName && unresolvedFileName) this.applyResolvedMetadataName(item, result.fileName);
|
||||
if (result.fileSizeBytes !== null && result.fileSizeBytes > 0 && (!item.totalBytes || item.totalBytes <= 0)) item.totalBytes = result.fileSizeBytes;
|
||||
item.onlineStatus = "online";
|
||||
item.updatedAt = nowMs();
|
||||
if (item.status === "completed") this.finalizeResolvedMetadataTargetPath(item);
|
||||
}
|
||||
|
||||
private async checkOneFichierItems(itemIds: string[]): Promise<void> {
|
||||
const itemIdsByUrl = new Map<string, string[]>();
|
||||
for (const itemId of itemIds) {
|
||||
const item = this.session.items[itemId];
|
||||
if (!item || !isOneFichierLink(item.url)) continue;
|
||||
if (item.status !== "queued" && item.status !== "reconnect_wait" && item.status !== "completed") continue;
|
||||
item.onlineStatus = "checking";
|
||||
const existing = itemIdsByUrl.get(item.url) ?? [];
|
||||
existing.push(itemId);
|
||||
itemIdsByUrl.set(item.url, existing);
|
||||
}
|
||||
if (itemIdsByUrl.size === 0) return;
|
||||
|
||||
this.emitState();
|
||||
let results: Map<string, OneFichierCheckResult>;
|
||||
try {
|
||||
results = await checkOneFichierLinks(Array.from(itemIdsByUrl.keys()));
|
||||
} catch (error) {
|
||||
logger.warn(`1Fichier-Linkprüfung fehlgeschlagen: ${compactErrorText(error)}`);
|
||||
results = new Map();
|
||||
}
|
||||
if (!this.metadataChecksActive) return;
|
||||
|
||||
for (const [url, ids] of itemIdsByUrl) {
|
||||
const result = results.get(url) ?? null;
|
||||
for (const itemId of ids) {
|
||||
const item = this.session.items[itemId];
|
||||
if (item) this.applyOneFichierCheckResult(item, result);
|
||||
}
|
||||
}
|
||||
this.persistSoon();
|
||||
this.emitState();
|
||||
}
|
||||
|
||||
private applyOneFichierCheckResult(item: DownloadItem, result: OneFichierCheckResult | null): void {
|
||||
if (!result) {
|
||||
if (item.onlineStatus === "checking") item.onlineStatus = undefined;
|
||||
return;
|
||||
}
|
||||
if (!result.online) {
|
||||
item.onlineStatus = "offline";
|
||||
item.updatedAt = nowMs();
|
||||
if (item.status === "queued" || item.status === "reconnect_wait") {
|
||||
item.status = "failed";
|
||||
item.fullStatus = "Offline";
|
||||
item.lastError = "Datei nicht gefunden auf 1Fichier";
|
||||
if (this.runItemIds.has(item.id)) this.recordRunOutcome(item.id, "failed");
|
||||
const pkg = this.session.packages[item.packageId];
|
||||
if (pkg) this.refreshPackageStatus(pkg);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (result.fileName && looksLikeOpaqueFilename(item.fileName)) this.applyResolvedMetadataName(item, result.fileName);
|
||||
if (result.fileSizeBytes !== null && result.fileSizeBytes > 0 && (!item.totalBytes || item.totalBytes <= 0)) item.totalBytes = result.fileSizeBytes;
|
||||
item.onlineStatus = "online";
|
||||
item.updatedAt = nowMs();
|
||||
if (item.status === "completed") this.finalizeResolvedMetadataTargetPath(item);
|
||||
}
|
||||
|
||||
private applyResolvedMetadataName(item: DownloadItem, resolvedFileName: string): void {
|
||||
const normalized = sanitizeFilename(resolvedFileName);
|
||||
if (!normalized || looksLikeOpaqueFilename(normalized)) return;
|
||||
item.fileName = normalized;
|
||||
const targetPath = String(item.targetPath || "").trim();
|
||||
const hasExistingData = item.downloadedBytes > 0 || Boolean(targetPath && fs.existsSync(targetPath));
|
||||
const active = this.activeTasks.has(item.id)
|
||||
|| item.status === "validating"
|
||||
|| item.status === "downloading"
|
||||
|| item.status === "integrity_check";
|
||||
if (!hasExistingData && !active) {
|
||||
this.assignItemTargetPath(item, path.join(this.session.packages[item.packageId]?.outputDir || this.settings.outputDir, normalized));
|
||||
}
|
||||
}
|
||||
|
||||
private finalizeResolvedMetadataTargetPath(item: DownloadItem): void {
|
||||
const pkg = this.session.packages[item.packageId];
|
||||
if (pkg && this.recoverPendingMetadataRename(item, pkg)) return;
|
||||
const currentPath = String(item.targetPath || "").trim();
|
||||
const fileName = sanitizeFilename(item.fileName || "");
|
||||
if (!pkg || !currentPath || !fileName || looksLikeOpaqueFilename(fileName)) return;
|
||||
const preferredPath = path.join(pkg.outputDir, fileName);
|
||||
if (pathKey(currentPath) === pathKey(preferredPath)) return;
|
||||
if (!fs.existsSync(currentPath)) return;
|
||||
const nextPath = this.claimTargetPath(item.id, preferredPath);
|
||||
item.metadataRenameTargetPath = nextPath;
|
||||
try {
|
||||
saveSession(this.storagePaths, this.session);
|
||||
} catch (error) {
|
||||
delete item.metadataRenameTargetPath;
|
||||
this.releaseTargetPath(item.id);
|
||||
item.targetPath = this.claimTargetPath(item.id, currentPath, true);
|
||||
logger.warn(`Metadaten-Umbenennung nicht vorgemerkt ${currentPath}: ${compactErrorText(error)}`);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
fs.renameSync(currentPath, nextPath);
|
||||
} catch (error) {
|
||||
this.releaseTargetPath(item.id);
|
||||
item.targetPath = this.claimTargetPath(item.id, currentPath, true);
|
||||
delete item.metadataRenameTargetPath;
|
||||
try { saveSession(this.storagePaths, this.session); } catch { }
|
||||
logger.warn(`Metadaten-Umbenennung fehlgeschlagen ${currentPath}: ${compactErrorText(error)}`);
|
||||
return;
|
||||
}
|
||||
item.targetPath = nextPath;
|
||||
delete item.metadataRenameTargetPath;
|
||||
try {
|
||||
saveSession(this.storagePaths, this.session);
|
||||
} catch (error) {
|
||||
item.metadataRenameTargetPath = nextPath;
|
||||
logger.warn(`Metadaten-Umbenennung gespeichert, Session-Abschluss fehlgeschlagen ${nextPath}: ${compactErrorText(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
private recoverPendingMetadataRename(item: DownloadItem, pkg: PackageEntry): boolean {
|
||||
const pendingPath = String(item.metadataRenameTargetPath || "").trim();
|
||||
if (!pendingPath || !isPathInsideDir(pendingPath, pkg.outputDir)) return false;
|
||||
const currentPath = String(item.targetPath || "").trim();
|
||||
const pendingOwner = this.reservedTargetPaths.get(pathKey(pendingPath));
|
||||
if (pendingOwner && pendingOwner !== item.id) return false;
|
||||
try {
|
||||
const currentExists = Boolean(currentPath && fs.existsSync(currentPath));
|
||||
const pendingExists = fs.existsSync(pendingPath);
|
||||
if (currentExists && pendingExists && pathKey(currentPath) !== pathKey(pendingPath)) {
|
||||
delete item.metadataRenameTargetPath;
|
||||
saveSession(this.storagePaths, this.session);
|
||||
return false;
|
||||
}
|
||||
if (!pendingExists) {
|
||||
if (!currentExists) return false;
|
||||
this.releaseTargetPath(item.id);
|
||||
const claimedPath = this.claimTargetPath(item.id, pendingPath);
|
||||
if (pathKey(claimedPath) !== pathKey(pendingPath)) return false;
|
||||
fs.renameSync(currentPath, pendingPath);
|
||||
} else {
|
||||
this.releaseTargetPath(item.id);
|
||||
const claimedPath = this.claimTargetPath(item.id, pendingPath, true);
|
||||
if (pathKey(claimedPath) !== pathKey(pendingPath)) return false;
|
||||
}
|
||||
item.targetPath = pendingPath;
|
||||
delete item.metadataRenameTargetPath;
|
||||
saveSession(this.storagePaths, this.session);
|
||||
return true;
|
||||
} catch (error) {
|
||||
logger.warn(`Metadaten-Umbenennung konnte nicht rekonstruiert werden ${pendingPath}: ${compactErrorText(error)}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private finalizeExistingResolvedMetadataTargets(): void {
|
||||
for (const item of Object.values(this.session.items)) {
|
||||
if (item.status !== "completed") continue;
|
||||
if (!isOneFichierLink(item.url) && !isDdownloadLink(item.url)) continue;
|
||||
this.finalizeResolvedMetadataTargetPath(item);
|
||||
}
|
||||
}
|
||||
|
||||
private checkExistingRapidgatorLinks(): void {
|
||||
const uncheckedIds: string[] = [];
|
||||
for (const item of Object.values(this.session.items)) {
|
||||
if (item.status !== "queued") continue;
|
||||
@@ -6109,7 +6333,8 @@ export class DownloadManager extends EventEmitter {
|
||||
public prepareForShutdown(): void {
|
||||
logger.info(`Shutdown-Vorbereitung gestartet: active=${this.activeTasks.size}, running=${this.session.running}, paused=${this.session.paused}`);
|
||||
this.updateStatisticsActivity(nowMs());
|
||||
this.rotationListenerActive = false;
|
||||
this.rotationListenerActive = false;
|
||||
this.metadataChecksActive = false;
|
||||
this.clearPersistTimer();
|
||||
if (this.stateEmitTimer) {
|
||||
clearTimeout(this.stateEmitTimer);
|
||||
@@ -6121,9 +6346,13 @@ export class DownloadManager extends EventEmitter {
|
||||
this.session.reconnectReason = "";
|
||||
this.lastGlobalProgressBytes = this.session.totalDownloadedBytes;
|
||||
this.lastGlobalProgressAt = nowMs();
|
||||
this.abortPostProcessing("shutdown");
|
||||
|
||||
let requeuedItems = 0;
|
||||
this.abortPostProcessing("shutdown");
|
||||
|
||||
for (const item of Object.values(this.session.items)) {
|
||||
if (item.onlineStatus === "checking") item.onlineStatus = undefined;
|
||||
}
|
||||
|
||||
let requeuedItems = 0;
|
||||
for (const active of this.activeTasks.values()) {
|
||||
const item = this.session.items[active.itemId];
|
||||
if (item && !isFinishedStatus(item.status)) {
|
||||
@@ -8351,6 +8580,34 @@ export class DownloadManager extends EventEmitter {
|
||||
throw new Error("Kein aktiver Download-Account verfügbar");
|
||||
}
|
||||
}
|
||||
|
||||
private checkExistingDdownloadLinks(): void {
|
||||
const uncheckedIds: string[] = [];
|
||||
for (const item of Object.values(this.session.items)) {
|
||||
if (item.status !== "queued" && item.status !== "reconnect_wait" && item.status !== "completed") continue;
|
||||
if (!isDdownloadLink(item.url) || item.onlineStatus === "offline") continue;
|
||||
const unresolvedFileName = looksLikeOpaqueFilename(item.fileName)
|
||||
|| (!filenameFromDdownloadUrlPath(item.url) && item.fileName === filenameFromUrl(item.url));
|
||||
if (item.onlineStatus === "online" && item.totalBytes !== null && item.totalBytes > 0 && !unresolvedFileName) continue;
|
||||
uncheckedIds.push(item.id);
|
||||
}
|
||||
if (uncheckedIds.length > 0) {
|
||||
void this.checkDdownloadItems(uncheckedIds).catch((err) => logger.warn(`checkDdownloadItems Fehler (startup): ${compactErrorText(err)}`));
|
||||
}
|
||||
}
|
||||
|
||||
private checkExistingOneFichierLinks(): void {
|
||||
const uncheckedIds: string[] = [];
|
||||
for (const item of Object.values(this.session.items)) {
|
||||
if (item.status !== "queued" && item.status !== "reconnect_wait" && item.status !== "completed") continue;
|
||||
if (!isOneFichierLink(item.url) || item.onlineStatus === "offline") continue;
|
||||
if (item.onlineStatus === "online" && !looksLikeOpaqueFilename(item.fileName) && item.totalBytes !== null && item.totalBytes > 0) continue;
|
||||
uncheckedIds.push(item.id);
|
||||
}
|
||||
if (uncheckedIds.length > 0) {
|
||||
void this.checkOneFichierItems(uncheckedIds).catch((err) => logger.warn(`checkOneFichierItems Fehler (startup): ${compactErrorText(err)}`));
|
||||
}
|
||||
}
|
||||
|
||||
private getProviderOrder(): DebridProvider[] {
|
||||
if (this.settings.providerOrder && this.settings.providerOrder.length > 0) {
|
||||
@@ -9412,7 +9669,10 @@ export class DownloadManager extends EventEmitter {
|
||||
item.providerAccountId = unrestricted.sourceAccountId;
|
||||
item.providerAccountLabel = unrestricted.sourceAccountLabel;
|
||||
item.retries += unrestricted.retriesUsed;
|
||||
item.fileName = sanitizeFilename(unrestricted.fileName || filenameFromUrl(item.url));
|
||||
const unrestrictedFileName = sanitizeFilename(unrestricted.fileName || filenameFromUrl(item.url));
|
||||
if (!looksLikeOpaqueFilename(unrestrictedFileName) || looksLikeOpaqueFilename(item.fileName)) {
|
||||
item.fileName = unrestrictedFileName;
|
||||
}
|
||||
let directHost = "";
|
||||
try {
|
||||
directHost = new URL(unrestricted.directUrl).host;
|
||||
@@ -9584,13 +9844,18 @@ export class DownloadManager extends EventEmitter {
|
||||
done = true;
|
||||
}
|
||||
|
||||
if (active.abortController.signal.aborted) {
|
||||
throw new Error(`aborted:${active.abortReason}`);
|
||||
}
|
||||
|
||||
const completedAt = nowMs();
|
||||
item.status = "completed";
|
||||
item.fullStatus = this.settings.autoExtract
|
||||
if (active.abortController.signal.aborted) {
|
||||
throw new Error(`aborted:${active.abortReason}`);
|
||||
}
|
||||
|
||||
if (isOneFichierLink(item.url) || isDdownloadLink(item.url)) {
|
||||
this.finalizeResolvedMetadataTargetPath(item);
|
||||
}
|
||||
|
||||
const completedAt = nowMs();
|
||||
item.status = "completed";
|
||||
if (isOneFichierLink(item.url) || isDdownloadLink(item.url)) item.onlineStatus = "online";
|
||||
item.fullStatus = this.settings.autoExtract
|
||||
? "Entpacken - Ausstehend"
|
||||
: `Fertig (${humanSize(item.downloadedBytes)})`;
|
||||
item.progressPercent = 100;
|
||||
|
||||
@@ -56,6 +56,7 @@ export function formatHosterLabel(hoster: string): { compact: string; title: str
|
||||
const normalized = hoster.trim().toLowerCase();
|
||||
if (normalized === "rapidgator") return { compact: "RG", title: "RapidGator", iconSrc: hosterIconSources.rapidgator };
|
||||
if (normalized === "ddownload") return { compact: "DD", title: "DDownload", iconSrc: hosterIconSources.ddownload };
|
||||
if (normalized === "1fichier") return { compact: "1F", title: "1Fichier" };
|
||||
return { compact: hoster, title: hoster };
|
||||
}
|
||||
|
||||
|
||||
+15
-1
@@ -1,7 +1,21 @@
|
||||
const DOMAIN_ALIASES: Readonly<Record<string, string>> = Object.freeze({
|
||||
"rapidgator.net": "rapidgator",
|
||||
"rapidgator.asia": "rapidgator",
|
||||
"rg.to": "rapidgator"
|
||||
"rg.to": "rapidgator",
|
||||
"ddownload.com": "ddownload",
|
||||
"ddl.to": "ddownload",
|
||||
"1fichier.com": "1fichier",
|
||||
"alterupload.com": "1fichier",
|
||||
"cjoint.net": "1fichier",
|
||||
"desfichiers.com": "1fichier",
|
||||
"desfichiers.net": "1fichier",
|
||||
"dfichiers.com": "1fichier",
|
||||
"megadl.fr": "1fichier",
|
||||
"mesfichiers.org": "1fichier",
|
||||
"piecejointe.net": "1fichier",
|
||||
"pjointe.com": "1fichier",
|
||||
"tenvoi.com": "1fichier",
|
||||
"dl4free.com": "1fichier"
|
||||
});
|
||||
|
||||
export function normalizeHosterHostname(hostname: string): string {
|
||||
|
||||
+4
-3
@@ -436,9 +436,10 @@ export interface DownloadItem {
|
||||
downloadedBytes: number;
|
||||
totalBytes: number | null;
|
||||
progressPercent: number;
|
||||
fileName: string;
|
||||
targetPath: string;
|
||||
resumable: boolean;
|
||||
fileName: string;
|
||||
targetPath: string;
|
||||
metadataRenameTargetPath?: string;
|
||||
resumable: boolean;
|
||||
attempts: number;
|
||||
lastError: string;
|
||||
fullStatus: string;
|
||||
|
||||
Reference in New Issue
Block a user