Recover stalled extraction and add optional fallback providers
Build and Release / build (push) Has been cancelled
Build and Release / build (push) Has been cancelled
This commit is contained in:
@@ -3,7 +3,7 @@ import os from "node:os";
|
||||
import { AppSettings } from "../shared/types";
|
||||
|
||||
export const APP_NAME = "Debrid Download Manager";
|
||||
export const APP_VERSION = "1.1.25";
|
||||
export const APP_VERSION = "1.1.26";
|
||||
export const API_BASE_URL = "https://api.real-debrid.com/rest/1.0";
|
||||
|
||||
export const DCRYPT_UPLOAD_URL = "https://dcrypt.it/decrypt/upload";
|
||||
|
||||
+14
-3
@@ -1,4 +1,4 @@
|
||||
import { AppSettings, DebridProvider } from "../shared/types";
|
||||
import { AppSettings, DebridFallbackProvider, DebridProvider } from "../shared/types";
|
||||
import { REQUEST_RETRIES } from "./constants";
|
||||
import { RealDebridClient, UnrestrictedLink } from "./realdebrid";
|
||||
import { compactErrorText, filenameFromUrl, looksLikeOpaqueFilename, sleep } from "./utils";
|
||||
@@ -113,6 +113,17 @@ function uniqueProviderOrder(order: DebridProvider[]): DebridProvider[] {
|
||||
return result;
|
||||
}
|
||||
|
||||
function toProviderOrder(primary: DebridProvider, secondary: DebridFallbackProvider, tertiary: DebridFallbackProvider): DebridProvider[] {
|
||||
const order: DebridProvider[] = [primary];
|
||||
if (secondary !== "none") {
|
||||
order.push(secondary);
|
||||
}
|
||||
if (tertiary !== "none") {
|
||||
order.push(tertiary);
|
||||
}
|
||||
return uniqueProviderOrder(order);
|
||||
}
|
||||
|
||||
function isRapidgatorLink(link: string): boolean {
|
||||
try {
|
||||
return new URL(link).hostname.toLowerCase().includes("rapidgator.net");
|
||||
@@ -492,11 +503,11 @@ export class DebridService {
|
||||
}
|
||||
|
||||
public async unrestrictLink(link: string): Promise<ProviderUnrestrictedLink> {
|
||||
const order = uniqueProviderOrder([
|
||||
const order = toProviderOrder(
|
||||
this.settings.providerPrimary,
|
||||
this.settings.providerSecondary,
|
||||
this.settings.providerTertiary
|
||||
]);
|
||||
);
|
||||
|
||||
let configuredFound = false;
|
||||
const attempts: string[] = [];
|
||||
|
||||
+155
-19
@@ -87,6 +87,31 @@ function isPathInsideDir(filePath: string, dirPath: string): boolean {
|
||||
return file.startsWith(withSep);
|
||||
}
|
||||
|
||||
function directoryHasFiles(dirPath: string): boolean {
|
||||
if (!fs.existsSync(dirPath)) {
|
||||
return false;
|
||||
}
|
||||
const stack = [dirPath];
|
||||
while (stack.length > 0) {
|
||||
const current = stack.pop() as string;
|
||||
let entries: fs.Dirent[] = [];
|
||||
try {
|
||||
entries = fs.readdirSync(current, { withFileTypes: true });
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
for (const entry of entries) {
|
||||
if (entry.isFile()) {
|
||||
return true;
|
||||
}
|
||||
if (entry.isDirectory()) {
|
||||
stack.push(path.join(current, entry.name));
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export class DownloadManager extends EventEmitter {
|
||||
private settings: AppSettings;
|
||||
|
||||
@@ -114,6 +139,10 @@ export class DownloadManager extends EventEmitter {
|
||||
|
||||
private cleanupQueue: Promise<void> = Promise.resolve();
|
||||
|
||||
private packagePostProcessQueue: Promise<void> = Promise.resolve();
|
||||
|
||||
private packagePostProcessTasks = new Map<string, Promise<void>>();
|
||||
|
||||
private reservedTargetPaths = new Map<string, string>();
|
||||
|
||||
private claimedTargetPathByItem = new Map<string, string>();
|
||||
@@ -134,6 +163,7 @@ export class DownloadManager extends EventEmitter {
|
||||
this.debridService = new DebridService(settings, { megaWebUnrestrict: options.megaWebUnrestrict });
|
||||
this.applyOnStartCleanupPolicy();
|
||||
this.normalizeSessionStatuses();
|
||||
this.recoverPostProcessingOnStartup();
|
||||
}
|
||||
|
||||
public setSettings(next: AppSettings): void {
|
||||
@@ -157,7 +187,8 @@ export class DownloadManager extends EventEmitter {
|
||||
public getSnapshot(): UiSnapshot {
|
||||
const now = nowMs();
|
||||
this.pruneSpeedEvents(now);
|
||||
const speedBps = this.speedBytesLastWindow / 3;
|
||||
const paused = this.session.running && this.session.paused;
|
||||
const speedBps = paused ? 0 : this.speedBytesLastWindow / 3;
|
||||
|
||||
let totalItems = Object.keys(this.session.items).length;
|
||||
let doneItems = Object.values(this.session.items).filter((item) => isFinishedStatus(item.status)).length;
|
||||
@@ -185,7 +216,7 @@ export class DownloadManager extends EventEmitter {
|
||||
session: this.getSession(),
|
||||
summary: this.summary,
|
||||
speedText: `Geschwindigkeit: ${humanSize(Math.max(0, Math.floor(speedBps)))}/s`,
|
||||
etaText: `ETA: ${formatEta(eta)}`,
|
||||
etaText: paused ? "ETA: --" : `ETA: ${formatEta(eta)}`,
|
||||
canStart: !this.session.running,
|
||||
canStop: this.session.running,
|
||||
canPause: this.session.running
|
||||
@@ -204,6 +235,8 @@ export class DownloadManager extends EventEmitter {
|
||||
this.runCompletedPackages.clear();
|
||||
this.reservedTargetPaths.clear();
|
||||
this.claimedTargetPathByItem.clear();
|
||||
this.packagePostProcessTasks.clear();
|
||||
this.packagePostProcessQueue = Promise.resolve();
|
||||
this.summary = null;
|
||||
this.persistNow();
|
||||
this.emitState(true);
|
||||
@@ -592,6 +625,95 @@ export class DownloadManager extends EventEmitter {
|
||||
this.claimedTargetPathByItem.delete(itemId);
|
||||
}
|
||||
|
||||
private runPackagePostProcessing(packageId: string): Promise<void> {
|
||||
const existing = this.packagePostProcessTasks.get(packageId);
|
||||
if (existing) {
|
||||
return existing;
|
||||
}
|
||||
|
||||
const task = this.packagePostProcessQueue
|
||||
.catch(() => undefined)
|
||||
.then(async () => {
|
||||
await this.handlePackagePostProcessing(packageId);
|
||||
})
|
||||
.catch((error) => {
|
||||
logger.warn(`Post-Processing für Paket fehlgeschlagen: ${compactErrorText(error)}`);
|
||||
})
|
||||
.finally(() => {
|
||||
this.packagePostProcessTasks.delete(packageId);
|
||||
this.persistSoon();
|
||||
this.emitState();
|
||||
});
|
||||
|
||||
this.packagePostProcessTasks.set(packageId, task);
|
||||
this.packagePostProcessQueue = task;
|
||||
return task;
|
||||
}
|
||||
|
||||
private recoverPostProcessingOnStartup(): void {
|
||||
const packageIds = [...this.session.packageOrder];
|
||||
if (packageIds.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
let changed = false;
|
||||
for (const packageId of packageIds) {
|
||||
const pkg = this.session.packages[packageId];
|
||||
if (!pkg || pkg.cancelled) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const items = pkg.itemIds.map((id) => this.session.items[id]).filter(Boolean) as DownloadItem[];
|
||||
if (items.length === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const success = items.filter((item) => item.status === "completed").length;
|
||||
const failed = items.filter((item) => item.status === "failed").length;
|
||||
const cancelled = items.filter((item) => item.status === "cancelled").length;
|
||||
if (success + failed + cancelled < items.length) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (this.settings.autoExtract && failed === 0 && success > 0) {
|
||||
if (this.settings.createExtractSubfolder && directoryHasFiles(pkg.extractDir)) {
|
||||
for (const item of items) {
|
||||
if (item.status === "completed" && item.fullStatus !== "Entpackt") {
|
||||
item.fullStatus = "Entpackt";
|
||||
item.updatedAt = nowMs();
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (pkg.status !== "completed") {
|
||||
pkg.status = "completed";
|
||||
pkg.updatedAt = nowMs();
|
||||
changed = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
const needsPostProcess = pkg.status !== "completed"
|
||||
|| items.some((item) => item.status === "completed" && item.fullStatus !== "Entpackt");
|
||||
if (needsPostProcess) {
|
||||
void this.runPackagePostProcessing(packageId);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
const targetStatus = failed > 0 ? "failed" : cancelled > 0 && success === 0 ? "cancelled" : "completed";
|
||||
if (pkg.status !== targetStatus) {
|
||||
pkg.status = targetStatus;
|
||||
pkg.updatedAt = nowMs();
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
this.persistSoon();
|
||||
this.emitState();
|
||||
}
|
||||
}
|
||||
|
||||
private removePackageFromSession(packageId: string, itemIds: string[]): void {
|
||||
for (const itemId of itemIds) {
|
||||
delete this.session.items[itemId];
|
||||
@@ -814,7 +936,7 @@ export class DownloadManager extends EventEmitter {
|
||||
pkg.updatedAt = nowMs();
|
||||
this.recordRunOutcome(item.id, "completed");
|
||||
|
||||
await this.handlePackagePostProcessing(pkg.id);
|
||||
await this.runPackagePostProcessing(pkg.id);
|
||||
this.applyCompletedCleanupPolicy(pkg.id, item.id);
|
||||
this.persistSoon();
|
||||
this.emitState();
|
||||
@@ -1140,29 +1262,43 @@ export class DownloadManager extends EventEmitter {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.settings.autoExtract && failed === 0 && success > 0) {
|
||||
const completedItems = items.filter((item) => item.status === "completed");
|
||||
const alreadyMarkedExtracted = completedItems.length > 0 && completedItems.every((item) => item.fullStatus === "Entpackt");
|
||||
|
||||
if (this.settings.autoExtract && failed === 0 && success > 0 && !alreadyMarkedExtracted) {
|
||||
pkg.status = "extracting";
|
||||
this.emitState();
|
||||
const result = await extractPackageArchives({
|
||||
packageDir: pkg.outputDir,
|
||||
targetDir: pkg.extractDir,
|
||||
cleanupMode: this.settings.cleanupMode,
|
||||
conflictMode: this.settings.extractConflictMode,
|
||||
removeLinks: this.settings.removeLinkFilesAfterExtract,
|
||||
removeSamples: this.settings.removeSamplesAfterExtract
|
||||
});
|
||||
if (result.failed > 0) {
|
||||
pkg.status = "failed";
|
||||
} else {
|
||||
if (result.extracted > 0) {
|
||||
for (const entry of items) {
|
||||
if (entry.status === "completed") {
|
||||
try {
|
||||
const result = await extractPackageArchives({
|
||||
packageDir: pkg.outputDir,
|
||||
targetDir: pkg.extractDir,
|
||||
cleanupMode: this.settings.cleanupMode,
|
||||
conflictMode: this.settings.extractConflictMode,
|
||||
removeLinks: this.settings.removeLinkFilesAfterExtract,
|
||||
removeSamples: this.settings.removeSamplesAfterExtract
|
||||
});
|
||||
if (result.failed > 0) {
|
||||
for (const entry of completedItems) {
|
||||
entry.fullStatus = "Entpack-Fehler";
|
||||
entry.updatedAt = nowMs();
|
||||
}
|
||||
pkg.status = "failed";
|
||||
} else {
|
||||
if (result.extracted > 0) {
|
||||
for (const entry of completedItems) {
|
||||
entry.fullStatus = "Entpackt";
|
||||
entry.updatedAt = nowMs();
|
||||
}
|
||||
}
|
||||
pkg.status = "completed";
|
||||
}
|
||||
pkg.status = "completed";
|
||||
} catch (error) {
|
||||
const reason = compactErrorText(error);
|
||||
for (const entry of completedItems) {
|
||||
entry.fullStatus = `Entpack-Fehler: ${reason}`;
|
||||
entry.updatedAt = nowMs();
|
||||
}
|
||||
pkg.status = "failed";
|
||||
}
|
||||
} else if (failed > 0) {
|
||||
pkg.status = "failed";
|
||||
|
||||
+7
-6
@@ -4,7 +4,8 @@ import { AppSettings, SessionState } from "../shared/types";
|
||||
import { defaultSettings } from "./constants";
|
||||
import { logger } from "./logger";
|
||||
|
||||
const VALID_PROVIDERS = new Set(["realdebrid", "megadebrid", "bestdebrid", "alldebrid"]);
|
||||
const VALID_PRIMARY_PROVIDERS = new Set(["realdebrid", "megadebrid", "bestdebrid", "alldebrid"]);
|
||||
const VALID_FALLBACK_PROVIDERS = new Set(["none", "realdebrid", "megadebrid", "bestdebrid", "alldebrid"]);
|
||||
const VALID_CLEANUP_MODES = new Set(["none", "trash", "delete"]);
|
||||
const VALID_CONFLICT_MODES = new Set(["overwrite", "skip", "rename", "ask"]);
|
||||
const VALID_FINISHED_POLICIES = new Set(["never", "immediate", "on_start", "package_done"]);
|
||||
@@ -53,14 +54,14 @@ export function normalizeSettings(settings: AppSettings): AppSettings {
|
||||
updateRepo: asText(settings.updateRepo) || defaults.updateRepo
|
||||
};
|
||||
|
||||
if (!VALID_PROVIDERS.has(normalized.providerPrimary)) {
|
||||
if (!VALID_PRIMARY_PROVIDERS.has(normalized.providerPrimary)) {
|
||||
normalized.providerPrimary = defaults.providerPrimary;
|
||||
}
|
||||
if (!VALID_PROVIDERS.has(normalized.providerSecondary)) {
|
||||
normalized.providerSecondary = defaults.providerSecondary;
|
||||
if (!VALID_FALLBACK_PROVIDERS.has(normalized.providerSecondary)) {
|
||||
normalized.providerSecondary = "none";
|
||||
}
|
||||
if (!VALID_PROVIDERS.has(normalized.providerTertiary)) {
|
||||
normalized.providerTertiary = defaults.providerTertiary;
|
||||
if (!VALID_FALLBACK_PROVIDERS.has(normalized.providerTertiary)) {
|
||||
normalized.providerTertiary = "none";
|
||||
}
|
||||
if (!VALID_CLEANUP_MODES.has(normalized.cleanupMode)) {
|
||||
normalized.cleanupMode = defaults.cleanupMode;
|
||||
|
||||
+13
-5
@@ -1,5 +1,5 @@
|
||||
import { DragEvent, ReactElement, useEffect, useMemo, useRef, useState } from "react";
|
||||
import type { AppSettings, DebridProvider, DownloadItem, PackageEntry, UiSnapshot, UpdateCheckResult } from "../shared/types";
|
||||
import type { AppSettings, DebridFallbackProvider, DebridProvider, DownloadItem, PackageEntry, UiSnapshot, UpdateCheckResult } from "../shared/types";
|
||||
|
||||
type Tab = "collector" | "downloads" | "settings";
|
||||
|
||||
@@ -73,6 +73,14 @@ const providerLabels: Record<DebridProvider, string> = {
|
||||
alldebrid: "AllDebrid"
|
||||
};
|
||||
|
||||
const fallbackProviderOptions: Array<{ value: DebridFallbackProvider; label: string }> = [
|
||||
{ value: "none", label: "Kein Fallback" },
|
||||
{ value: "realdebrid", label: providerLabels.realdebrid },
|
||||
{ value: "megadebrid", label: providerLabels.megadebrid },
|
||||
{ value: "bestdebrid", label: providerLabels.bestdebrid },
|
||||
{ value: "alldebrid", label: providerLabels.alldebrid }
|
||||
];
|
||||
|
||||
function formatSpeedMbps(speedBps: number): string {
|
||||
const mbps = Math.max(0, speedBps) / (1024 * 1024);
|
||||
return `${mbps.toFixed(2)} MB/s`;
|
||||
@@ -397,16 +405,16 @@ export function App(): ReactElement {
|
||||
<div>
|
||||
<label>Sekundär</label>
|
||||
<select value={settingsDraft.providerSecondary} onChange={(event) => setText("providerSecondary", event.target.value)}>
|
||||
{Object.entries(providerLabels).map(([key, label]) => (
|
||||
<option key={key} value={key}>{label}</option>
|
||||
{fallbackProviderOptions.map((option) => (
|
||||
<option key={option.value} value={option.value}>{option.label}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label>Tertiär</label>
|
||||
<select value={settingsDraft.providerTertiary} onChange={(event) => setText("providerTertiary", event.target.value)}>
|
||||
{Object.entries(providerLabels).map(([key, label]) => (
|
||||
<option key={key} value={key}>{label}</option>
|
||||
{fallbackProviderOptions.map((option) => (
|
||||
<option key={option.value} value={option.value}>{option.label}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
+3
-2
@@ -15,6 +15,7 @@ export type ConflictMode = "overwrite" | "skip" | "rename" | "ask";
|
||||
export type SpeedMode = "global" | "per_download";
|
||||
export type FinishedCleanupPolicy = "never" | "immediate" | "on_start" | "package_done";
|
||||
export type DebridProvider = "realdebrid" | "megadebrid" | "bestdebrid" | "alldebrid";
|
||||
export type DebridFallbackProvider = DebridProvider | "none";
|
||||
|
||||
export interface AppSettings {
|
||||
token: string;
|
||||
@@ -24,8 +25,8 @@ export interface AppSettings {
|
||||
allDebridToken: string;
|
||||
rememberToken: boolean;
|
||||
providerPrimary: DebridProvider;
|
||||
providerSecondary: DebridProvider;
|
||||
providerTertiary: DebridProvider;
|
||||
providerSecondary: DebridFallbackProvider;
|
||||
providerTertiary: DebridFallbackProvider;
|
||||
autoProviderFallback: boolean;
|
||||
outputDir: string;
|
||||
packageName: string;
|
||||
|
||||
Reference in New Issue
Block a user