Compare commits
58 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
49e62c1f83 | ||
|
|
4c67455c67 | ||
|
|
5a5e3d2960 | ||
|
|
11da8b6e9a | ||
|
|
265e6a72be | ||
|
|
7816dc9488 | ||
|
|
678d642683 | ||
|
|
0f4174d153 | ||
|
|
babcd8edb7 | ||
|
|
6e00bbab53 | ||
|
|
72642351d0 | ||
|
|
51a01ea03f | ||
|
|
d9a78ea837 | ||
|
|
5b221d5bd5 | ||
|
|
c36549ca69 | ||
|
|
7e79bef8da | ||
|
|
e3b4a4ba19 | ||
|
|
30d216c7ca | ||
|
|
d80483adc2 | ||
|
|
1cda391dfe | ||
|
|
375ec36781 | ||
|
|
4ad1c05444 | ||
|
|
c88eeb0b12 | ||
|
|
c6261aba6a | ||
|
|
a010b967b9 | ||
|
|
af6547f254 | ||
|
|
ba235b0b93 | ||
|
|
1bfde96e46 | ||
|
|
e1f9b4b6d3 | ||
|
|
95cf4fbed8 | ||
|
|
9ddc7d31bb | ||
|
|
83626017b9 | ||
|
|
b9372f0ef0 | ||
|
|
db97a7df14 | ||
|
|
575fca3806 | ||
|
|
a1c8f42435 | ||
|
|
a3c2680fec | ||
|
|
12dade0240 | ||
|
|
2a528a126c | ||
|
|
8839080069 | ||
|
|
8f66d75eb3 | ||
|
|
56ee681aec | ||
|
|
6db03f05a9 | ||
|
|
068da94e2a | ||
|
|
4b824b2d9f | ||
|
|
284c5e7aa6 | ||
|
|
036cd3e066 | ||
|
|
479c7a3f3f | ||
|
|
0404d870ad | ||
|
|
93a53763e0 | ||
|
|
c20d743286 | ||
|
|
ba938f64c5 | ||
|
|
af00d69e5c | ||
|
|
bc47da504c | ||
|
|
5a24c891c0 | ||
|
|
1103df98c1 | ||
|
|
74920e2e2f | ||
|
|
75775f2798 |
9
.gitignore
vendored
9
.gitignore
vendored
@ -28,3 +28,12 @@ coverage/
|
|||||||
npm-debug.log*
|
npm-debug.log*
|
||||||
yarn-debug.log*
|
yarn-debug.log*
|
||||||
yarn-error.log*
|
yarn-error.log*
|
||||||
|
|
||||||
|
# Forgejo deployment runtime files
|
||||||
|
deploy/forgejo/.env
|
||||||
|
deploy/forgejo/forgejo/
|
||||||
|
deploy/forgejo/postgres/
|
||||||
|
deploy/forgejo/caddy/data/
|
||||||
|
deploy/forgejo/caddy/config/
|
||||||
|
deploy/forgejo/caddy/logs/
|
||||||
|
deploy/forgejo/backups/
|
||||||
|
|||||||
23
CLAUDE.md
Normal file
23
CLAUDE.md
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
## Release + Update Source (Wichtig)
|
||||||
|
|
||||||
|
- Primäre Plattform ist `https://git.24-music.de`
|
||||||
|
- Standard-Repo: `Administrator/real-debrid-downloader`
|
||||||
|
- Nicht mehr primär über Codeberg/GitHub releasen
|
||||||
|
|
||||||
|
## Releasen
|
||||||
|
|
||||||
|
1. Token setzen:
|
||||||
|
- PowerShell: `$env:GITEA_TOKEN="<token>"`
|
||||||
|
2. Release ausführen:
|
||||||
|
- `npm run release:gitea -- <version> [notes]`
|
||||||
|
|
||||||
|
Das Script:
|
||||||
|
- bumped `package.json`
|
||||||
|
- baut Windows-Artefakte
|
||||||
|
- pusht `main` + Tag
|
||||||
|
- erstellt Release auf `git.24-music.de`
|
||||||
|
- lädt Assets hoch
|
||||||
|
|
||||||
|
## Auto-Update
|
||||||
|
|
||||||
|
- Updater nutzt aktuell `git.24-music.de` als Standardquelle
|
||||||
58
README.md
58
README.md
@ -1,6 +1,6 @@
|
|||||||
# Multi Debrid Downloader
|
# Multi Debrid Downloader
|
||||||
|
|
||||||
Desktop downloader for **Real-Debrid, Mega-Debrid, BestDebrid, and AllDebrid** with fast queue management, automatic extraction, and robust error handling.
|
Desktop downloader with fast queue management, automatic extraction, and robust error handling.
|
||||||
|
|
||||||

|

|
||||||

|

|
||||||
@ -65,18 +65,18 @@ Desktop downloader for **Real-Debrid, Mega-Debrid, BestDebrid, and AllDebrid** w
|
|||||||
- Minimize-to-tray with tray menu controls.
|
- Minimize-to-tray with tray menu controls.
|
||||||
- Speed limits globally or per download.
|
- Speed limits globally or per download.
|
||||||
- Bandwidth schedules for time-based speed profiles.
|
- Bandwidth schedules for time-based speed profiles.
|
||||||
- Built-in auto-updater via Codeberg Releases.
|
- Built-in auto-updater via `git.24-music.de` Releases.
|
||||||
- Long path support (>260 characters) on Windows.
|
- Long path support (>260 characters) on Windows.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
### Option A: prebuilt releases (recommended)
|
### Option A: prebuilt releases (recommended)
|
||||||
|
|
||||||
1. Download a release from the Codeberg Releases page.
|
1. Download a release from the `git.24-music.de` Releases page.
|
||||||
2. Run the installer or portable build.
|
2. Run the installer or portable build.
|
||||||
3. Add your debrid tokens in Settings.
|
3. Add your debrid tokens in Settings.
|
||||||
|
|
||||||
Releases: `https://codeberg.org/Sucukdeluxe/real-debrid-downloader/releases`
|
Releases: `https://git.24-music.de/Administrator/real-debrid-downloader/releases`
|
||||||
|
|
||||||
### Option B: build from source
|
### Option B: build from source
|
||||||
|
|
||||||
@ -103,21 +103,34 @@ npm run dev
|
|||||||
| `npm test` | Runs Vitest unit tests |
|
| `npm test` | Runs Vitest unit tests |
|
||||||
| `npm run self-check` | Runs integrated end-to-end self-checks |
|
| `npm run self-check` | Runs integrated end-to-end self-checks |
|
||||||
| `npm run release:win` | Creates Windows installer and portable build |
|
| `npm run release:win` | Creates Windows installer and portable build |
|
||||||
| `npm run release:codeberg -- <version> [notes]` | One-command version bump + build + tag + Codeberg release upload |
|
| `npm run release:gitea -- <version> [notes]` | One-command version bump + build + tag + release upload to `git.24-music.de` |
|
||||||
|
| `npm run release:codeberg -- <version> [notes]` | Legacy path for old Codeberg workflow |
|
||||||
|
|
||||||
### One-command Codeberg release
|
### One-command git.24-music release
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm run release:codeberg -- 1.4.42 "- Maintenance update"
|
npm run release:gitea -- 1.6.31 "- Maintenance update"
|
||||||
```
|
```
|
||||||
|
|
||||||
This command will:
|
This command will:
|
||||||
|
|
||||||
1. Bump `package.json` version.
|
1. Bump `package.json` version.
|
||||||
2. Build setup/portable artifacts (`npm run release:win`).
|
2. Build setup/portable artifacts (`npm run release:win`).
|
||||||
3. Commit and push `main` to your Codeberg remote.
|
3. Commit and push `main` to your `git.24-music.de` remote.
|
||||||
4. Create and push tag `v<version>`.
|
4. Create and push tag `v<version>`.
|
||||||
5. Create/update the Codeberg release and upload required assets.
|
5. Create/update the Gitea release and upload required assets.
|
||||||
|
|
||||||
|
Required once before release:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git remote add gitea https://git.24-music.de/<user>/<repo>.git
|
||||||
|
```
|
||||||
|
|
||||||
|
PowerShell token setup:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
$env:GITEA_TOKEN="<dein-token>"
|
||||||
|
```
|
||||||
|
|
||||||
## Typical workflow
|
## Typical workflow
|
||||||
|
|
||||||
@ -147,14 +160,37 @@ The app stores runtime files in Electron's `userData` directory, including:
|
|||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
- Download does not start: verify token and selected provider in Settings.
|
- Download does not start: verify token and selected provider in Settings.
|
||||||
- Extraction fails: check archive passwords, JVM runtime (`resources/extractor-jvm`), or force legacy mode with `RD_EXTRACT_BACKEND=legacy`.
|
- Extraction fails: check archive passwords and native extractor installation (7-Zip/WinRAR). Optional JVM extractor can be forced with `RD_EXTRACT_BACKEND=jvm`.
|
||||||
- Very slow downloads: check active speed limit and bandwidth schedules.
|
- Very slow downloads: check active speed limit and bandwidth schedules.
|
||||||
- Unexpected interruptions: enable reconnect and fallback providers.
|
- Unexpected interruptions: enable reconnect and fallback providers.
|
||||||
- Stalled downloads: the app auto-detects stalls within 10 seconds and retries automatically.
|
- Stalled downloads: the app auto-detects stalls within 10 seconds and retries automatically.
|
||||||
|
|
||||||
## Changelog
|
## Changelog
|
||||||
|
|
||||||
Release history is available on [Codeberg Releases](https://codeberg.org/Sucukdeluxe/real-debrid-downloader/releases).
|
Release history is available on [git.24-music.de Releases](https://git.24-music.de/Administrator/real-debrid-downloader/releases).
|
||||||
|
|
||||||
|
### v1.6.60 (2026-03-05)
|
||||||
|
|
||||||
|
- Added package-scoped password cache for extraction: once the first archive in a package is solved, following archives in the same package reuse that password first.
|
||||||
|
- Kept fallback behavior intact (`""` and other candidates are still tested), but moved empty-password probing behind the learned password to reduce per-archive delays.
|
||||||
|
- Added cache invalidation on real `wrong_password` failures so stale passwords are automatically discarded.
|
||||||
|
|
||||||
|
### v1.6.59 (2026-03-05)
|
||||||
|
|
||||||
|
- Switched default extraction backend to native tools (`legacy`) for more stable archive-to-archive flow.
|
||||||
|
- Prioritized 7-Zip as primary native extractor, with WinRAR/UnRAR as fallback.
|
||||||
|
- JVM extractor remains available as opt-in via `RD_EXTRACT_BACKEND=jvm`.
|
||||||
|
|
||||||
|
### v1.6.58 (2026-03-05)
|
||||||
|
|
||||||
|
- Fixed extraction progress oscillation (`1% -> 100% -> 1%` loops) during password retries.
|
||||||
|
- Kept strict archive completion logic, but normalized in-progress archive percent to avoid false visual done states before real completion.
|
||||||
|
|
||||||
|
### v1.6.57 (2026-03-05)
|
||||||
|
|
||||||
|
- Fixed extraction flow so archives are marked done only on real completion, not on temporary `100%` progress spikes.
|
||||||
|
- Improved password handling: after the first successful archive, the discovered password is prioritized for subsequent archives.
|
||||||
|
- Fixed progress parsing for password retries (reset/restart handling), reducing visible and real gaps between archive extractions.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
@ -1,75 +0,0 @@
|
|||||||
import fs from "node:fs";
|
|
||||||
import path from "node:path";
|
|
||||||
import { spawnSync } from "node:child_process";
|
|
||||||
|
|
||||||
const credResult = spawnSync("git", ["credential", "fill"], {
|
|
||||||
input: "protocol=https\nhost=codeberg.org\n\n",
|
|
||||||
encoding: "utf8",
|
|
||||||
stdio: ["pipe", "pipe", "pipe"]
|
|
||||||
});
|
|
||||||
const creds = new Map();
|
|
||||||
for (const line of credResult.stdout.split(/\r?\n/)) {
|
|
||||||
if (line.includes("=")) {
|
|
||||||
const [k, v] = line.split("=", 2);
|
|
||||||
creds.set(k, v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const auth = "Basic " + Buffer.from(creds.get("username") + ":" + creds.get("password")).toString("base64");
|
|
||||||
const owner = "Sucukdeluxe";
|
|
||||||
const repo = "real-debrid-downloader";
|
|
||||||
const tag = "v1.5.35";
|
|
||||||
const baseApi = `https://codeberg.org/api/v1/repos/${owner}/${repo}`;
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
await fetch(baseApi, {
|
|
||||||
method: "PATCH",
|
|
||||||
headers: { Authorization: auth, "Content-Type": "application/json" },
|
|
||||||
body: JSON.stringify({ has_releases: true })
|
|
||||||
});
|
|
||||||
|
|
||||||
const createRes = await fetch(`${baseApi}/releases`, {
|
|
||||||
method: "POST",
|
|
||||||
headers: { Authorization: auth, "Content-Type": "application/json", Accept: "application/json" },
|
|
||||||
body: JSON.stringify({
|
|
||||||
tag_name: tag,
|
|
||||||
target_commitish: "main",
|
|
||||||
name: tag,
|
|
||||||
body: "- Fix: Fortschritt zeigt jetzt kombinierten Wert (Download + Entpacken)\n- Fix: Pausieren zeigt nicht mehr 'Warte auf Daten'\n- Pixel-perfekte Dual-Layer Progress-Bar Texte (clip-path)",
|
|
||||||
draft: false,
|
|
||||||
prerelease: false
|
|
||||||
})
|
|
||||||
});
|
|
||||||
const release = await createRes.json();
|
|
||||||
if (!createRes.ok) {
|
|
||||||
console.error("Create failed:", JSON.stringify(release));
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
console.log("Release created:", release.id);
|
|
||||||
|
|
||||||
const files = [
|
|
||||||
"Real-Debrid-Downloader Setup 1.5.35.exe",
|
|
||||||
"Real-Debrid-Downloader 1.5.35.exe",
|
|
||||||
"latest.yml",
|
|
||||||
"Real-Debrid-Downloader Setup 1.5.35.exe.blockmap"
|
|
||||||
];
|
|
||||||
for (const f of files) {
|
|
||||||
const filePath = path.join("release", f);
|
|
||||||
const data = fs.readFileSync(filePath);
|
|
||||||
const uploadUrl = `${baseApi}/releases/${release.id}/assets?name=${encodeURIComponent(f)}`;
|
|
||||||
const res = await fetch(uploadUrl, {
|
|
||||||
method: "POST",
|
|
||||||
headers: { Authorization: auth, "Content-Type": "application/octet-stream" },
|
|
||||||
body: data
|
|
||||||
});
|
|
||||||
if (res.ok) {
|
|
||||||
console.log("Uploaded:", f);
|
|
||||||
} else if (res.status === 409 || res.status === 422) {
|
|
||||||
console.log("Skipped existing:", f);
|
|
||||||
} else {
|
|
||||||
console.error("Upload failed for", f, ":", res.status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
console.log(`Done! https://codeberg.org/${owner}/${repo}/releases/tag/${tag}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
main().catch(e => { console.error(e.message); process.exit(1); });
|
|
||||||
@ -25,11 +25,11 @@ AppPublisher=Sucukdeluxe
|
|||||||
DefaultDirName={autopf}\{#MyAppName}
|
DefaultDirName={autopf}\{#MyAppName}
|
||||||
DefaultGroupName={#MyAppName}
|
DefaultGroupName={#MyAppName}
|
||||||
OutputDir={#MyOutputDir}
|
OutputDir={#MyOutputDir}
|
||||||
OutputBaseFilename=Real-Debrid-Downloader-Setup-{#MyAppVersion}
|
OutputBaseFilename=Real-Debrid-Downloader Setup {#MyAppVersion}
|
||||||
Compression=lzma
|
Compression=lzma
|
||||||
SolidCompression=yes
|
SolidCompression=yes
|
||||||
WizardStyle=modern
|
WizardStyle=modern
|
||||||
PrivilegesRequired=admin
|
PrivilegesRequired=lowest
|
||||||
ArchitecturesInstallIn64BitMode=x64compatible
|
ArchitecturesInstallIn64BitMode=x64compatible
|
||||||
UninstallDisplayIcon={app}\{#MyAppExeName}
|
UninstallDisplayIcon={app}\{#MyAppExeName}
|
||||||
SetupIconFile={#MyIconFile}
|
SetupIconFile={#MyIconFile}
|
||||||
@ -39,8 +39,8 @@ Name: "german"; MessagesFile: "compiler:Languages\German.isl"
|
|||||||
Name: "english"; MessagesFile: "compiler:Default.isl"
|
Name: "english"; MessagesFile: "compiler:Default.isl"
|
||||||
|
|
||||||
[Files]
|
[Files]
|
||||||
Source: "{#MySourceDir}\\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
|
Source: "{#MySourceDir}\\*"; DestDir: "{app}"; Flags: recursesubdirs createallsubdirs
|
||||||
Source: "{#MyIconFile}"; DestDir: "{app}"; DestName: "app_icon.ico"; Flags: ignoreversion
|
Source: "{#MyIconFile}"; DestDir: "{app}"; DestName: "app_icon.ico"
|
||||||
|
|
||||||
[Icons]
|
[Icons]
|
||||||
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; IconFilename: "{app}\app_icon.ico"
|
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; IconFilename: "{app}\app_icon.ico"
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "real-debrid-downloader",
|
"name": "real-debrid-downloader",
|
||||||
"version": "1.6.30",
|
"version": "1.6.60",
|
||||||
"description": "Real-Debrid Downloader Desktop (Electron + React + TypeScript)",
|
"description": "Desktop downloader",
|
||||||
"main": "build/main/main/main.js",
|
"main": "build/main/main/main.js",
|
||||||
"author": "Sucukdeluxe",
|
"author": "Sucukdeluxe",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@ -17,7 +17,8 @@
|
|||||||
"test": "vitest run",
|
"test": "vitest run",
|
||||||
"self-check": "tsx tests/self-check.ts",
|
"self-check": "tsx tests/self-check.ts",
|
||||||
"release:win": "npm run build && electron-builder --publish never --win nsis portable",
|
"release:win": "npm run build && electron-builder --publish never --win nsis portable",
|
||||||
"release:codeberg": "node scripts/release_codeberg.mjs"
|
"release:gitea": "node scripts/release_gitea.mjs",
|
||||||
|
"release:forgejo": "node scripts/release_gitea.mjs"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"adm-zip": "^0.5.16",
|
"adm-zip": "^0.5.16",
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -3,7 +3,9 @@ package com.sucukdeluxe.extractor;
|
|||||||
import net.lingala.zip4j.ZipFile;
|
import net.lingala.zip4j.ZipFile;
|
||||||
import net.lingala.zip4j.exception.ZipException;
|
import net.lingala.zip4j.exception.ZipException;
|
||||||
import net.lingala.zip4j.model.FileHeader;
|
import net.lingala.zip4j.model.FileHeader;
|
||||||
|
import net.sf.sevenzipjbinding.ExtractAskMode;
|
||||||
import net.sf.sevenzipjbinding.ExtractOperationResult;
|
import net.sf.sevenzipjbinding.ExtractOperationResult;
|
||||||
|
import net.sf.sevenzipjbinding.IArchiveExtractCallback;
|
||||||
import net.sf.sevenzipjbinding.IArchiveOpenCallback;
|
import net.sf.sevenzipjbinding.IArchiveOpenCallback;
|
||||||
import net.sf.sevenzipjbinding.IArchiveOpenVolumeCallback;
|
import net.sf.sevenzipjbinding.IArchiveOpenVolumeCallback;
|
||||||
import net.sf.sevenzipjbinding.IInArchive;
|
import net.sf.sevenzipjbinding.IInArchive;
|
||||||
@ -26,6 +28,7 @@ import java.io.InputStream;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.RandomAccessFile;
|
import java.io.RandomAccessFile;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -42,12 +45,18 @@ public final class JBindExtractorMain {
|
|||||||
private static final Pattern NUMBERED_ZIP_SPLIT_RE = Pattern.compile("(?i).*\\.zip\\.\\d{3}$");
|
private static final Pattern NUMBERED_ZIP_SPLIT_RE = Pattern.compile("(?i).*\\.zip\\.\\d{3}$");
|
||||||
private static final Pattern OLD_ZIP_SPLIT_RE = Pattern.compile("(?i).*\\.z\\d{2,3}$");
|
private static final Pattern OLD_ZIP_SPLIT_RE = Pattern.compile("(?i).*\\.z\\d{2,3}$");
|
||||||
private static final Pattern SEVEN_ZIP_SPLIT_RE = Pattern.compile("(?i).*\\.7z\\.001$");
|
private static final Pattern SEVEN_ZIP_SPLIT_RE = Pattern.compile("(?i).*\\.7z\\.001$");
|
||||||
|
private static final Pattern DIGIT_SUFFIX_RE = Pattern.compile("\\d{2,3}");
|
||||||
|
private static final Pattern WINDOWS_SPECIAL_CHARS_RE = Pattern.compile("[:<>*?\"\\|]");
|
||||||
private static volatile boolean sevenZipInitialized = false;
|
private static volatile boolean sevenZipInitialized = false;
|
||||||
|
|
||||||
private JBindExtractorMain() {
|
private JBindExtractorMain() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
if (args.length == 1 && "--daemon".equals(args[0])) {
|
||||||
|
runDaemon();
|
||||||
|
return;
|
||||||
|
}
|
||||||
int exit = 1;
|
int exit = 1;
|
||||||
try {
|
try {
|
||||||
ExtractionRequest request = parseArgs(args);
|
ExtractionRequest request = parseArgs(args);
|
||||||
@ -62,6 +71,127 @@ public final class JBindExtractorMain {
|
|||||||
System.exit(exit);
|
System.exit(exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void runDaemon() {
|
||||||
|
System.out.println("RD_DAEMON_READY");
|
||||||
|
System.out.flush();
|
||||||
|
java.io.BufferedReader reader = new java.io.BufferedReader(
|
||||||
|
new java.io.InputStreamReader(System.in, StandardCharsets.UTF_8));
|
||||||
|
try {
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
line = line.trim();
|
||||||
|
if (line.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int exitCode = 1;
|
||||||
|
try {
|
||||||
|
ExtractionRequest request = parseDaemonRequest(line);
|
||||||
|
exitCode = runExtraction(request);
|
||||||
|
} catch (IllegalArgumentException error) {
|
||||||
|
emitError("Argumentfehler: " + safeMessage(error));
|
||||||
|
exitCode = 2;
|
||||||
|
} catch (Throwable error) {
|
||||||
|
emitError(safeMessage(error));
|
||||||
|
exitCode = 1;
|
||||||
|
}
|
||||||
|
System.out.println("RD_REQUEST_DONE " + exitCode);
|
||||||
|
System.out.flush();
|
||||||
|
}
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
// stdin closed — parent process exited
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ExtractionRequest parseDaemonRequest(String jsonLine) {
|
||||||
|
// Minimal JSON parsing without external dependencies.
|
||||||
|
// Expected format: {"archive":"...","target":"...","conflict":"...","backend":"...","passwords":["...","..."]}
|
||||||
|
ExtractionRequest request = new ExtractionRequest();
|
||||||
|
request.archiveFile = new File(extractJsonString(jsonLine, "archive"));
|
||||||
|
request.targetDir = new File(extractJsonString(jsonLine, "target"));
|
||||||
|
String conflict = extractJsonString(jsonLine, "conflict");
|
||||||
|
if (conflict.length() > 0) {
|
||||||
|
request.conflictMode = ConflictMode.fromValue(conflict);
|
||||||
|
}
|
||||||
|
String backend = extractJsonString(jsonLine, "backend");
|
||||||
|
if (backend.length() > 0) {
|
||||||
|
request.backend = Backend.fromValue(backend);
|
||||||
|
}
|
||||||
|
// Parse passwords array
|
||||||
|
int pwStart = jsonLine.indexOf("\"passwords\"");
|
||||||
|
if (pwStart >= 0) {
|
||||||
|
int arrStart = jsonLine.indexOf('[', pwStart);
|
||||||
|
int arrEnd = jsonLine.indexOf(']', arrStart);
|
||||||
|
if (arrStart >= 0 && arrEnd > arrStart) {
|
||||||
|
String arrContent = jsonLine.substring(arrStart + 1, arrEnd);
|
||||||
|
int idx = 0;
|
||||||
|
while (idx < arrContent.length()) {
|
||||||
|
int qStart = arrContent.indexOf('"', idx);
|
||||||
|
if (qStart < 0) break;
|
||||||
|
int qEnd = findClosingQuote(arrContent, qStart + 1);
|
||||||
|
if (qEnd < 0) break;
|
||||||
|
request.passwords.add(unescapeJsonString(arrContent.substring(qStart + 1, qEnd)));
|
||||||
|
idx = qEnd + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (request.archiveFile == null || !request.archiveFile.exists() || !request.archiveFile.isFile()) {
|
||||||
|
throw new IllegalArgumentException("Archiv nicht gefunden: " +
|
||||||
|
(request.archiveFile == null ? "null" : request.archiveFile.getAbsolutePath()));
|
||||||
|
}
|
||||||
|
if (request.targetDir == null) {
|
||||||
|
throw new IllegalArgumentException("--target fehlt");
|
||||||
|
}
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String extractJsonString(String json, String key) {
|
||||||
|
String search = "\"" + key + "\"";
|
||||||
|
int keyIdx = json.indexOf(search);
|
||||||
|
if (keyIdx < 0) return "";
|
||||||
|
int colonIdx = json.indexOf(':', keyIdx + search.length());
|
||||||
|
if (colonIdx < 0) return "";
|
||||||
|
int qStart = json.indexOf('"', colonIdx + 1);
|
||||||
|
if (qStart < 0) return "";
|
||||||
|
int qEnd = findClosingQuote(json, qStart + 1);
|
||||||
|
if (qEnd < 0) return "";
|
||||||
|
return unescapeJsonString(json.substring(qStart + 1, qEnd));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int findClosingQuote(String s, int from) {
|
||||||
|
for (int i = from; i < s.length(); i++) {
|
||||||
|
char c = s.charAt(i);
|
||||||
|
if (c == '\\') {
|
||||||
|
i++; // skip escaped character
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (c == '"') return i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String unescapeJsonString(String s) {
|
||||||
|
if (s.indexOf('\\') < 0) return s;
|
||||||
|
StringBuilder sb = new StringBuilder(s.length());
|
||||||
|
for (int i = 0; i < s.length(); i++) {
|
||||||
|
char c = s.charAt(i);
|
||||||
|
if (c == '\\' && i + 1 < s.length()) {
|
||||||
|
char next = s.charAt(i + 1);
|
||||||
|
switch (next) {
|
||||||
|
case '"': sb.append('"'); i++; break;
|
||||||
|
case '\\': sb.append('\\'); i++; break;
|
||||||
|
case '/': sb.append('/'); i++; break;
|
||||||
|
case 'n': sb.append('\n'); i++; break;
|
||||||
|
case 'r': sb.append('\r'); i++; break;
|
||||||
|
case 't': sb.append('\t'); i++; break;
|
||||||
|
default: sb.append(c); break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sb.append(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
private static int runExtraction(ExtractionRequest request) throws Exception {
|
private static int runExtraction(ExtractionRequest request) throws Exception {
|
||||||
List<String> passwords = normalizePasswords(request.passwords);
|
List<String> passwords = normalizePasswords(request.passwords);
|
||||||
Exception lastError = null;
|
Exception lastError = null;
|
||||||
@ -152,9 +282,12 @@ public final class JBindExtractorMain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ensureDirectory(output.getParentFile());
|
ensureDirectory(output.getParentFile());
|
||||||
|
rejectSymlink(output);
|
||||||
long[] remaining = new long[] { itemUnits };
|
long[] remaining = new long[] { itemUnits };
|
||||||
|
boolean extractionSuccess = false;
|
||||||
try {
|
try {
|
||||||
InputStream in = zipFile.getInputStream(header);
|
InputStream in = zipFile.getInputStream(header);
|
||||||
|
try {
|
||||||
OutputStream out = new FileOutputStream(output);
|
OutputStream out = new FileOutputStream(output);
|
||||||
try {
|
try {
|
||||||
byte[] buffer = new byte[BUFFER_SIZE];
|
byte[] buffer = new byte[BUFFER_SIZE];
|
||||||
@ -176,6 +309,8 @@ public final class JBindExtractorMain {
|
|||||||
out.close();
|
out.close();
|
||||||
} catch (Throwable ignored) {
|
} catch (Throwable ignored) {
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
try {
|
try {
|
||||||
in.close();
|
in.close();
|
||||||
} catch (Throwable ignored) {
|
} catch (Throwable ignored) {
|
||||||
@ -188,11 +323,19 @@ public final class JBindExtractorMain {
|
|||||||
if (modified > 0) {
|
if (modified > 0) {
|
||||||
output.setLastModified(modified);
|
output.setLastModified(modified);
|
||||||
}
|
}
|
||||||
|
extractionSuccess = true;
|
||||||
} catch (ZipException error) {
|
} catch (ZipException error) {
|
||||||
if (isWrongPassword(error, encrypted)) {
|
if (isWrongPassword(error, encrypted)) {
|
||||||
throw new WrongPasswordException(error);
|
throw new WrongPasswordException(error);
|
||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
|
} finally {
|
||||||
|
if (!extractionSuccess && output.exists()) {
|
||||||
|
try {
|
||||||
|
output.delete();
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,98 +362,99 @@ public final class JBindExtractorMain {
|
|||||||
try {
|
try {
|
||||||
context = openSevenZipArchive(request.archiveFile, password);
|
context = openSevenZipArchive(request.archiveFile, password);
|
||||||
IInArchive archive = context.archive;
|
IInArchive archive = context.archive;
|
||||||
ISimpleInArchive simple = archive.getSimpleInterface();
|
int itemCount = archive.getNumberOfItems();
|
||||||
ISimpleInArchiveItem[] items = simple.getArchiveItems();
|
if (itemCount <= 0) {
|
||||||
|
throw new IOException("Archiv enthalt keine Eintrage oder konnte nicht gelesen werden: " + request.archiveFile.getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pre-scan: collect file indices, sizes, output paths, and detect encryption
|
||||||
long totalUnits = 0;
|
long totalUnits = 0;
|
||||||
boolean encrypted = false;
|
boolean encrypted = false;
|
||||||
for (ISimpleInArchiveItem item : items) {
|
List<Integer> fileIndices = new ArrayList<Integer>();
|
||||||
if (item == null || item.isFolder()) {
|
List<File> outputFiles = new ArrayList<File>();
|
||||||
continue;
|
List<Long> fileSizes = new ArrayList<Long>();
|
||||||
}
|
|
||||||
try {
|
|
||||||
encrypted = encrypted || item.isEncrypted();
|
|
||||||
} catch (Throwable ignored) {
|
|
||||||
// ignore encrypted flag read issues
|
|
||||||
}
|
|
||||||
totalUnits += safeSize(item.getSize());
|
|
||||||
}
|
|
||||||
ProgressTracker progress = new ProgressTracker(totalUnits);
|
|
||||||
progress.emitStart();
|
|
||||||
|
|
||||||
Set<String> reserved = new HashSet<String>();
|
Set<String> reserved = new HashSet<String>();
|
||||||
for (ISimpleInArchiveItem item : items) {
|
|
||||||
if (item == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
String entryName = normalizeEntryName(item.getPath(), "item-" + item.getItemIndex());
|
for (int i = 0; i < itemCount; i++) {
|
||||||
if (item.isFolder()) {
|
Boolean isFolder = (Boolean) archive.getProperty(i, PropID.IS_FOLDER);
|
||||||
|
String entryPath = (String) archive.getProperty(i, PropID.PATH);
|
||||||
|
String entryName = normalizeEntryName(entryPath, "item-" + i);
|
||||||
|
|
||||||
|
if (Boolean.TRUE.equals(isFolder)) {
|
||||||
File dir = resolveDirectory(request.targetDir, entryName);
|
File dir = resolveDirectory(request.targetDir, entryName);
|
||||||
ensureDirectory(dir);
|
ensureDirectory(dir);
|
||||||
reserved.add(pathKey(dir));
|
reserved.add(pathKey(dir));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
long itemUnits = safeSize(item.getSize());
|
try {
|
||||||
|
Boolean isEncrypted = (Boolean) archive.getProperty(i, PropID.ENCRYPTED);
|
||||||
|
encrypted = encrypted || Boolean.TRUE.equals(isEncrypted);
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
// ignore encrypted flag read issues
|
||||||
|
}
|
||||||
|
|
||||||
|
Long rawSize = (Long) archive.getProperty(i, PropID.SIZE);
|
||||||
|
long itemSize = safeSize(rawSize);
|
||||||
|
totalUnits += itemSize;
|
||||||
|
|
||||||
File output = resolveOutputFile(request.targetDir, entryName, request.conflictMode, reserved);
|
File output = resolveOutputFile(request.targetDir, entryName, request.conflictMode, reserved);
|
||||||
if (output == null) {
|
fileIndices.add(i);
|
||||||
progress.advance(itemUnits);
|
outputFiles.add(output); // null if skipped
|
||||||
continue;
|
fileSizes.add(itemSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
ensureDirectory(output.getParentFile());
|
if (fileIndices.isEmpty()) {
|
||||||
final FileOutputStream out = new FileOutputStream(output);
|
// All items are folders or skipped
|
||||||
final long[] remaining = new long[] { itemUnits };
|
ProgressTracker progress = new ProgressTracker(1);
|
||||||
|
progress.emitStart();
|
||||||
|
progress.emitDone();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProgressTracker progress = new ProgressTracker(totalUnits);
|
||||||
|
progress.emitStart();
|
||||||
|
|
||||||
|
// Build index array for bulk extract
|
||||||
|
int[] indices = new int[fileIndices.size()];
|
||||||
|
for (int i = 0; i < fileIndices.size(); i++) {
|
||||||
|
indices[i] = fileIndices.get(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Map from archive index to our position in fileIndices/outputFiles
|
||||||
|
Map<Integer, Integer> indexToPos = new HashMap<Integer, Integer>();
|
||||||
|
for (int i = 0; i < fileIndices.size(); i++) {
|
||||||
|
indexToPos.put(fileIndices.get(i), i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bulk extraction state
|
||||||
|
final boolean encryptedFinal = encrypted;
|
||||||
|
final String effectivePassword = password == null ? "" : password;
|
||||||
|
final File[] currentOutput = new File[1];
|
||||||
|
final FileOutputStream[] currentStream = new FileOutputStream[1];
|
||||||
|
final boolean[] currentSuccess = new boolean[1];
|
||||||
|
final long[] currentRemaining = new long[1];
|
||||||
|
final Throwable[] firstError = new Throwable[1];
|
||||||
|
final int[] currentPos = new int[] { -1 };
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ExtractOperationResult result = item.extractSlow(new ISequentialOutStream() {
|
archive.extract(indices, false, new BulkExtractCallback(
|
||||||
@Override
|
archive, indexToPos, fileIndices, outputFiles, fileSizes,
|
||||||
public int write(byte[] data) throws SevenZipException {
|
progress, encryptedFinal, effectivePassword, currentOutput,
|
||||||
if (data == null || data.length == 0) {
|
currentStream, currentSuccess, currentRemaining, currentPos, firstError
|
||||||
return 0;
|
));
|
||||||
}
|
|
||||||
try {
|
|
||||||
out.write(data);
|
|
||||||
} catch (IOException error) {
|
|
||||||
throw new SevenZipException("Fehler beim Schreiben: " + error.getMessage(), error);
|
|
||||||
}
|
|
||||||
long accounted = Math.min(remaining[0], (long) data.length);
|
|
||||||
remaining[0] -= accounted;
|
|
||||||
progress.advance(accounted);
|
|
||||||
return data.length;
|
|
||||||
}
|
|
||||||
}, password == null ? "" : password);
|
|
||||||
|
|
||||||
if (remaining[0] > 0) {
|
|
||||||
progress.advance(remaining[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result != ExtractOperationResult.OK) {
|
|
||||||
if (isPasswordFailure(result, encrypted)) {
|
|
||||||
throw new WrongPasswordException(new IOException("Falsches Passwort"));
|
|
||||||
}
|
|
||||||
throw new IOException("7z-Fehler: " + result.name());
|
|
||||||
}
|
|
||||||
} catch (SevenZipException error) {
|
} catch (SevenZipException error) {
|
||||||
if (looksLikeWrongPassword(error, encrypted)) {
|
if (looksLikeWrongPassword(error, encryptedFinal)) {
|
||||||
throw new WrongPasswordException(error);
|
throw new WrongPasswordException(error);
|
||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
out.close();
|
|
||||||
} catch (Throwable ignored) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
if (firstError[0] != null) {
|
||||||
java.util.Date modified = item.getLastWriteTime();
|
if (firstError[0] instanceof WrongPasswordException) {
|
||||||
if (modified != null) {
|
throw (WrongPasswordException) firstError[0];
|
||||||
output.setLastModified(modified.getTime());
|
|
||||||
}
|
|
||||||
} catch (Throwable ignored) {
|
|
||||||
// best effort
|
|
||||||
}
|
}
|
||||||
|
throw (Exception) firstError[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
progress.emitDone();
|
progress.emitDone();
|
||||||
@ -328,14 +472,31 @@ public final class JBindExtractorMain {
|
|||||||
|
|
||||||
if (SEVEN_ZIP_SPLIT_RE.matcher(nameLower).matches()) {
|
if (SEVEN_ZIP_SPLIT_RE.matcher(nameLower).matches()) {
|
||||||
VolumedArchiveInStream volumed = new VolumedArchiveInStream(archiveFile.getName(), callback);
|
VolumedArchiveInStream volumed = new VolumedArchiveInStream(archiveFile.getName(), callback);
|
||||||
|
try {
|
||||||
IInArchive archive = SevenZip.openInArchive(null, volumed, callback);
|
IInArchive archive = SevenZip.openInArchive(null, volumed, callback);
|
||||||
return new SevenZipArchiveContext(archive, null, volumed, callback);
|
return new SevenZipArchiveContext(archive, null, volumed, callback);
|
||||||
|
} catch (Exception error) {
|
||||||
|
callback.close();
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RandomAccessFile raf = new RandomAccessFile(archiveFile, "r");
|
RandomAccessFile raf = new RandomAccessFile(archiveFile, "r");
|
||||||
RandomAccessFileInStream stream = new RandomAccessFileInStream(raf);
|
RandomAccessFileInStream stream = new RandomAccessFileInStream(raf);
|
||||||
|
try {
|
||||||
IInArchive archive = SevenZip.openInArchive(null, stream, callback);
|
IInArchive archive = SevenZip.openInArchive(null, stream, callback);
|
||||||
return new SevenZipArchiveContext(archive, stream, null, callback);
|
return new SevenZipArchiveContext(archive, stream, null, callback);
|
||||||
|
} catch (Exception error) {
|
||||||
|
try {
|
||||||
|
stream.close();
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
raf.close();
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isWrongPassword(ZipException error, boolean encrypted) {
|
private static boolean isWrongPassword(ZipException error, boolean encrypted) {
|
||||||
@ -396,7 +557,7 @@ public final class JBindExtractorMain {
|
|||||||
}
|
}
|
||||||
if (siblingName.startsWith(prefix) && siblingName.length() >= prefix.length() + 2) {
|
if (siblingName.startsWith(prefix) && siblingName.length() >= prefix.length() + 2) {
|
||||||
String suffix = siblingName.substring(prefix.length());
|
String suffix = siblingName.substring(prefix.length());
|
||||||
if (suffix.matches("\\d{2,3}")) {
|
if (DIGIT_SUFFIX_RE.matcher(suffix).matches()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -480,6 +641,12 @@ public final class JBindExtractorMain {
|
|||||||
}
|
}
|
||||||
if (normalized.matches("^[a-zA-Z]:.*")) {
|
if (normalized.matches("^[a-zA-Z]:.*")) {
|
||||||
normalized = normalized.substring(2);
|
normalized = normalized.substring(2);
|
||||||
|
while (normalized.startsWith("/")) {
|
||||||
|
normalized = normalized.substring(1);
|
||||||
|
}
|
||||||
|
while (normalized.startsWith("\\")) {
|
||||||
|
normalized = normalized.substring(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
File targetCanonical = targetDir.getCanonicalFile();
|
File targetCanonical = targetDir.getCanonicalFile();
|
||||||
File output = new File(targetCanonical, normalized);
|
File output = new File(targetCanonical, normalized);
|
||||||
@ -488,7 +655,8 @@ public final class JBindExtractorMain {
|
|||||||
String outputPath = outputCanonical.getPath();
|
String outputPath = outputCanonical.getPath();
|
||||||
String targetPathNorm = isWindows() ? targetPath.toLowerCase(Locale.ROOT) : targetPath;
|
String targetPathNorm = isWindows() ? targetPath.toLowerCase(Locale.ROOT) : targetPath;
|
||||||
String outputPathNorm = isWindows() ? outputPath.toLowerCase(Locale.ROOT) : outputPath;
|
String outputPathNorm = isWindows() ? outputPath.toLowerCase(Locale.ROOT) : outputPath;
|
||||||
if (!outputPathNorm.equals(targetPathNorm) && !outputPathNorm.startsWith(targetPathNorm + File.separator)) {
|
String targetPrefix = targetPathNorm.endsWith(File.separator) ? targetPathNorm : targetPathNorm + File.separator;
|
||||||
|
if (!outputPathNorm.equals(targetPathNorm) && !outputPathNorm.startsWith(targetPrefix)) {
|
||||||
throw new IOException("Path Traversal blockiert: " + entryName);
|
throw new IOException("Path Traversal blockiert: " + entryName);
|
||||||
}
|
}
|
||||||
return outputCanonical;
|
return outputCanonical;
|
||||||
@ -506,20 +674,50 @@ public final class JBindExtractorMain {
|
|||||||
if (entry.length() == 0) {
|
if (entry.length() == 0) {
|
||||||
return fallback;
|
return fallback;
|
||||||
}
|
}
|
||||||
|
// Sanitize Windows special characters from each path segment
|
||||||
|
String[] segments = entry.split("/", -1);
|
||||||
|
StringBuilder sanitized = new StringBuilder();
|
||||||
|
for (int i = 0; i < segments.length; i++) {
|
||||||
|
if (i > 0) {
|
||||||
|
sanitized.append('/');
|
||||||
|
}
|
||||||
|
sanitized.append(WINDOWS_SPECIAL_CHARS_RE.matcher(segments[i]).replaceAll("_"));
|
||||||
|
}
|
||||||
|
entry = sanitized.toString();
|
||||||
|
if (entry.length() == 0) {
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static long safeSize(Long value) {
|
private static long safeSize(Long value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
long size = value.longValue();
|
long size = value.longValue();
|
||||||
if (size <= 0) {
|
if (size <= 0) {
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void rejectSymlink(File file) throws IOException {
|
||||||
|
if (file == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Files.isSymbolicLink(file.toPath())) {
|
||||||
|
throw new IOException("Zieldatei ist ein Symlink, Schreiben verweigert: " + file.getAbsolutePath());
|
||||||
|
}
|
||||||
|
// Also check parent directories for symlinks
|
||||||
|
File parent = file.getParentFile();
|
||||||
|
while (parent != null) {
|
||||||
|
if (Files.isSymbolicLink(parent.toPath())) {
|
||||||
|
throw new IOException("Elternverzeichnis ist ein Symlink, Schreiben verweigert: " + parent.getAbsolutePath());
|
||||||
|
}
|
||||||
|
parent = parent.getParentFile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void ensureDirectory(File dir) throws IOException {
|
private static void ensureDirectory(File dir) throws IOException {
|
||||||
if (dir == null) {
|
if (dir == null) {
|
||||||
return;
|
return;
|
||||||
@ -681,6 +879,176 @@ public final class JBindExtractorMain {
|
|||||||
private final List<String> passwords = new ArrayList<String>();
|
private final List<String> passwords = new ArrayList<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bulk extraction callback that implements both IArchiveExtractCallback and
|
||||||
|
* ICryptoGetTextPassword. Using the bulk IInArchive.extract() API instead of
|
||||||
|
* per-item extractSlow() is critical for performance — solid RAR archives
|
||||||
|
* otherwise re-decode from the beginning for every single item.
|
||||||
|
*/
|
||||||
|
private static final class BulkExtractCallback implements IArchiveExtractCallback, ICryptoGetTextPassword {
|
||||||
|
private final IInArchive archive;
|
||||||
|
private final Map<Integer, Integer> indexToPos;
|
||||||
|
private final List<Integer> fileIndices;
|
||||||
|
private final List<File> outputFiles;
|
||||||
|
private final List<Long> fileSizes;
|
||||||
|
private final ProgressTracker progress;
|
||||||
|
private final boolean encrypted;
|
||||||
|
private final String password;
|
||||||
|
private final File[] currentOutput;
|
||||||
|
private final FileOutputStream[] currentStream;
|
||||||
|
private final boolean[] currentSuccess;
|
||||||
|
private final long[] currentRemaining;
|
||||||
|
private final int[] currentPos;
|
||||||
|
private final Throwable[] firstError;
|
||||||
|
|
||||||
|
BulkExtractCallback(IInArchive archive, Map<Integer, Integer> indexToPos,
|
||||||
|
List<Integer> fileIndices, List<File> outputFiles, List<Long> fileSizes,
|
||||||
|
ProgressTracker progress, boolean encrypted, String password,
|
||||||
|
File[] currentOutput, FileOutputStream[] currentStream,
|
||||||
|
boolean[] currentSuccess, long[] currentRemaining, int[] currentPos,
|
||||||
|
Throwable[] firstError) {
|
||||||
|
this.archive = archive;
|
||||||
|
this.indexToPos = indexToPos;
|
||||||
|
this.fileIndices = fileIndices;
|
||||||
|
this.outputFiles = outputFiles;
|
||||||
|
this.fileSizes = fileSizes;
|
||||||
|
this.progress = progress;
|
||||||
|
this.encrypted = encrypted;
|
||||||
|
this.password = password;
|
||||||
|
this.currentOutput = currentOutput;
|
||||||
|
this.currentStream = currentStream;
|
||||||
|
this.currentSuccess = currentSuccess;
|
||||||
|
this.currentRemaining = currentRemaining;
|
||||||
|
this.currentPos = currentPos;
|
||||||
|
this.firstError = firstError;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String cryptoGetTextPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setTotal(long total) {
|
||||||
|
// 7z reports total compressed bytes; we track uncompressed via ProgressTracker
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCompleted(long complete) {
|
||||||
|
// Not used — we track per-write progress
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ISequentialOutStream getStream(int index, ExtractAskMode extractAskMode) throws SevenZipException {
|
||||||
|
closeCurrentStream();
|
||||||
|
|
||||||
|
Integer pos = indexToPos.get(index);
|
||||||
|
if (pos == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
currentPos[0] = pos;
|
||||||
|
currentOutput[0] = outputFiles.get(pos);
|
||||||
|
currentSuccess[0] = false;
|
||||||
|
currentRemaining[0] = fileSizes.get(pos);
|
||||||
|
|
||||||
|
if (extractAskMode != ExtractAskMode.EXTRACT) {
|
||||||
|
currentOutput[0] = null;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentOutput[0] == null) {
|
||||||
|
progress.advance(currentRemaining[0]);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
ensureDirectory(currentOutput[0].getParentFile());
|
||||||
|
rejectSymlink(currentOutput[0]);
|
||||||
|
currentStream[0] = new FileOutputStream(currentOutput[0]);
|
||||||
|
} catch (IOException error) {
|
||||||
|
throw new SevenZipException("Fehler beim Erstellen: " + error.getMessage(), error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ISequentialOutStream() {
|
||||||
|
@Override
|
||||||
|
public int write(byte[] data) throws SevenZipException {
|
||||||
|
if (data == null || data.length == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
currentStream[0].write(data);
|
||||||
|
} catch (IOException error) {
|
||||||
|
throw new SevenZipException("Fehler beim Schreiben: " + error.getMessage(), error);
|
||||||
|
}
|
||||||
|
long accounted = Math.min(currentRemaining[0], (long) data.length);
|
||||||
|
currentRemaining[0] -= accounted;
|
||||||
|
progress.advance(accounted);
|
||||||
|
return data.length;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void prepareOperation(ExtractAskMode extractAskMode) {
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOperationResult(ExtractOperationResult result) throws SevenZipException {
|
||||||
|
if (currentRemaining[0] > 0) {
|
||||||
|
progress.advance(currentRemaining[0]);
|
||||||
|
currentRemaining[0] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result == ExtractOperationResult.OK) {
|
||||||
|
currentSuccess[0] = true;
|
||||||
|
closeCurrentStream();
|
||||||
|
if (currentPos[0] >= 0 && currentOutput[0] != null) {
|
||||||
|
try {
|
||||||
|
int archiveIndex = fileIndices.get(currentPos[0]);
|
||||||
|
java.util.Date modified = (java.util.Date) archive.getProperty(archiveIndex, PropID.LAST_MODIFICATION_TIME);
|
||||||
|
if (modified != null) {
|
||||||
|
currentOutput[0].setLastModified(modified.getTime());
|
||||||
|
}
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
// best effort
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
closeCurrentStream();
|
||||||
|
if (currentOutput[0] != null && currentOutput[0].exists()) {
|
||||||
|
try {
|
||||||
|
currentOutput[0].delete();
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (firstError[0] == null) {
|
||||||
|
if (isPasswordFailure(result, encrypted)) {
|
||||||
|
firstError[0] = new WrongPasswordException(new IOException("Falsches Passwort"));
|
||||||
|
} else {
|
||||||
|
firstError[0] = new IOException("7z-Fehler: " + result.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void closeCurrentStream() {
|
||||||
|
if (currentStream[0] != null) {
|
||||||
|
try {
|
||||||
|
currentStream[0].close();
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
|
currentStream[0] = null;
|
||||||
|
}
|
||||||
|
if (!currentSuccess[0] && currentOutput[0] != null && currentOutput[0].exists()) {
|
||||||
|
try {
|
||||||
|
currentOutput[0].delete();
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static final class WrongPasswordException extends Exception {
|
private static final class WrongPasswordException extends Exception {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@ -828,12 +1196,11 @@ public final class JBindExtractorMain {
|
|||||||
if (filename == null || filename.trim().length() == 0) {
|
if (filename == null || filename.trim().length() == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
File direct = new File(filename);
|
// Always resolve relative to the archive's parent directory.
|
||||||
if (direct.isAbsolute() && direct.exists()) {
|
// Never accept absolute paths to prevent path traversal.
|
||||||
return direct;
|
String baseName = new File(filename).getName();
|
||||||
}
|
|
||||||
if (archiveDir != null) {
|
if (archiveDir != null) {
|
||||||
File relative = new File(archiveDir, filename);
|
File relative = new File(archiveDir, baseName);
|
||||||
if (relative.exists()) {
|
if (relative.exists()) {
|
||||||
return relative;
|
return relative;
|
||||||
}
|
}
|
||||||
@ -843,13 +1210,13 @@ public final class JBindExtractorMain {
|
|||||||
if (!sibling.isFile()) {
|
if (!sibling.isFile()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (sibling.getName().equalsIgnoreCase(filename)) {
|
if (sibling.getName().equalsIgnoreCase(baseName)) {
|
||||||
return sibling;
|
return sibling;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return direct.exists() ? direct : null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -2,8 +2,17 @@ const path = require("path");
|
|||||||
const { rcedit } = require("rcedit");
|
const { rcedit } = require("rcedit");
|
||||||
|
|
||||||
module.exports = async function afterPack(context) {
|
module.exports = async function afterPack(context) {
|
||||||
const exePath = path.join(context.appOutDir, `${context.packager.appInfo.productFilename}.exe`);
|
const productFilename = context.packager?.appInfo?.productFilename;
|
||||||
|
if (!productFilename) {
|
||||||
|
console.warn(" • rcedit: skipped — productFilename not available");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const exePath = path.join(context.appOutDir, `${productFilename}.exe`);
|
||||||
const iconPath = path.resolve(__dirname, "..", "assets", "app_icon.ico");
|
const iconPath = path.resolve(__dirname, "..", "assets", "app_icon.ico");
|
||||||
console.log(` • rcedit: patching icon → ${exePath}`);
|
console.log(` • rcedit: patching icon → ${exePath}`);
|
||||||
|
try {
|
||||||
await rcedit(exePath, { icon: iconPath });
|
await rcedit(exePath, { icon: iconPath });
|
||||||
|
} catch (error) {
|
||||||
|
console.warn(` • rcedit: failed — ${String(error)}`);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -31,6 +31,7 @@ async function main(): Promise<void> {
|
|||||||
login: settings.megaLogin,
|
login: settings.megaLogin,
|
||||||
password: settings.megaPassword
|
password: settings.megaPassword
|
||||||
}));
|
}));
|
||||||
|
try {
|
||||||
const service = new DebridService(settings, {
|
const service = new DebridService(settings, {
|
||||||
megaWebUnrestrict: (link) => megaWeb.unrestrict(link)
|
megaWebUnrestrict: (link) => megaWeb.unrestrict(link)
|
||||||
});
|
});
|
||||||
@ -42,7 +43,9 @@ async function main(): Promise<void> {
|
|||||||
console.log(`[FAIL] ${String(error)}`);
|
console.log(`[FAIL] ${String(error)}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
megaWeb.dispose();
|
megaWeb.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void main();
|
main().catch(e => { console.error(e); process.exit(1); });
|
||||||
|
|||||||
@ -16,8 +16,8 @@ function sleep(ms) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function cookieFrom(headers) {
|
function cookieFrom(headers) {
|
||||||
const raw = headers.get("set-cookie") || "";
|
const cookies = headers.getSetCookie();
|
||||||
return raw.split(",").map((x) => x.split(";")[0].trim()).filter(Boolean).join("; ");
|
return cookies.map((x) => x.split(";")[0].trim()).filter(Boolean).join("; ");
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseDebridCodes(html) {
|
function parseDebridCodes(html) {
|
||||||
@ -47,6 +47,9 @@ async function resolveCode(cookie, code) {
|
|||||||
});
|
});
|
||||||
const text = (await res.text()).trim();
|
const text = (await res.text()).trim();
|
||||||
if (text === "reload") {
|
if (text === "reload") {
|
||||||
|
if (attempt % 5 === 0) {
|
||||||
|
console.log(` [retry] code=${code} attempt=${attempt}/50 (waiting for server)`);
|
||||||
|
}
|
||||||
await sleep(800);
|
await sleep(800);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -98,7 +101,13 @@ async function main() {
|
|||||||
redirect: "manual"
|
redirect: "manual"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (loginRes.status >= 400) {
|
||||||
|
throw new Error(`Login failed with HTTP ${loginRes.status}`);
|
||||||
|
}
|
||||||
const cookie = cookieFrom(loginRes.headers);
|
const cookie = cookieFrom(loginRes.headers);
|
||||||
|
if (!cookie) {
|
||||||
|
throw new Error("Login returned no session cookie");
|
||||||
|
}
|
||||||
console.log("login", loginRes.status, loginRes.headers.get("location") || "");
|
console.log("login", loginRes.status, loginRes.headers.get("location") || "");
|
||||||
|
|
||||||
const debridRes = await fetch("https://www.mega-debrid.eu/index.php?form=debrid", {
|
const debridRes = await fetch("https://www.mega-debrid.eu/index.php?form=debrid", {
|
||||||
@ -136,4 +145,4 @@ async function main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await main();
|
await main().catch((e) => { console.error(e); process.exit(1); });
|
||||||
|
|||||||
@ -66,6 +66,8 @@ async function callRealDebrid(link) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// megaCookie is intentionally cached at module scope so that multiple
|
||||||
|
// callMegaDebrid() invocations reuse the same session cookie.
|
||||||
async function callMegaDebrid(link) {
|
async function callMegaDebrid(link) {
|
||||||
if (!megaCookie) {
|
if (!megaCookie) {
|
||||||
const loginRes = await fetch("https://www.mega-debrid.eu/index.php?form=login", {
|
const loginRes = await fetch("https://www.mega-debrid.eu/index.php?form=login", {
|
||||||
@ -77,13 +79,15 @@ async function callMegaDebrid(link) {
|
|||||||
body: new URLSearchParams({ login: megaLogin, password: megaPassword, remember: "on" }),
|
body: new URLSearchParams({ login: megaLogin, password: megaPassword, remember: "on" }),
|
||||||
redirect: "manual"
|
redirect: "manual"
|
||||||
});
|
});
|
||||||
megaCookie = (loginRes.headers.get("set-cookie") || "")
|
if (loginRes.status >= 400) {
|
||||||
.split(",")
|
return { ok: false, error: `Mega-Web login failed with HTTP ${loginRes.status}` };
|
||||||
|
}
|
||||||
|
megaCookie = loginRes.headers.getSetCookie()
|
||||||
.map((chunk) => chunk.split(";")[0].trim())
|
.map((chunk) => chunk.split(";")[0].trim())
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.join("; ");
|
.join("; ");
|
||||||
if (!megaCookie) {
|
if (!megaCookie) {
|
||||||
return { ok: false, error: "Mega-Web login failed" };
|
return { ok: false, error: "Mega-Web login returned no session cookie" };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,4 +294,4 @@ async function main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await main();
|
await main().catch((e) => { console.error(e); process.exit(1); });
|
||||||
|
|||||||
@ -2,7 +2,15 @@ import fs from "node:fs";
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { spawnSync } from "node:child_process";
|
import { spawnSync } from "node:child_process";
|
||||||
|
|
||||||
const NPM_EXECUTABLE = process.platform === "win32" ? "npm.cmd" : "npm";
|
const NPM_RELEASE_WIN = process.platform === "win32"
|
||||||
|
? {
|
||||||
|
command: process.env.ComSpec || "cmd.exe",
|
||||||
|
args: ["/d", "/s", "/c", "npm run release:win"]
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
command: "npm",
|
||||||
|
args: ["run", "release:win"]
|
||||||
|
};
|
||||||
|
|
||||||
function run(command, args, options = {}) {
|
function run(command, args, options = {}) {
|
||||||
const result = spawnSync(command, args, {
|
const result = spawnSync(command, args, {
|
||||||
@ -37,7 +45,8 @@ function runWithInput(command, args, input) {
|
|||||||
cwd: process.cwd(),
|
cwd: process.cwd(),
|
||||||
encoding: "utf8",
|
encoding: "utf8",
|
||||||
input,
|
input,
|
||||||
stdio: ["pipe", "pipe", "pipe"]
|
stdio: ["pipe", "pipe", "pipe"],
|
||||||
|
timeout: 10000
|
||||||
});
|
});
|
||||||
if (result.status !== 0) {
|
if (result.status !== 0) {
|
||||||
const stderr = String(result.stderr || "").trim();
|
const stderr = String(result.stderr || "").trim();
|
||||||
@ -59,37 +68,74 @@ function parseArgs(argv) {
|
|||||||
return { help: false, dryRun, version, notes };
|
return { help: false, dryRun, version, notes };
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseCodebergRemote(url) {
|
function parseRemoteUrl(url) {
|
||||||
const raw = String(url || "").trim();
|
const raw = String(url || "").trim();
|
||||||
const httpsMatch = raw.match(/^https?:\/\/(?:www\.)?codeberg\.org\/([^/]+)\/([^/]+?)(?:\.git)?$/i);
|
const httpsMatch = raw.match(/^https?:\/\/([^/]+)\/([^/]+)\/([^/]+?)(?:\.git)?$/i);
|
||||||
if (httpsMatch) {
|
if (httpsMatch) {
|
||||||
return { owner: httpsMatch[1], repo: httpsMatch[2] };
|
return { host: httpsMatch[1], owner: httpsMatch[2], repo: httpsMatch[3] };
|
||||||
}
|
}
|
||||||
const sshMatch = raw.match(/^git@codeberg\.org:([^/]+)\/([^/]+?)(?:\.git)?$/i);
|
const sshMatch = raw.match(/^git@([^:]+):([^/]+)\/([^/]+?)(?:\.git)?$/i);
|
||||||
if (sshMatch) {
|
if (sshMatch) {
|
||||||
return { owner: sshMatch[1], repo: sshMatch[2] };
|
return { host: sshMatch[1], owner: sshMatch[2], repo: sshMatch[3] };
|
||||||
}
|
}
|
||||||
throw new Error(`Cannot parse Codeberg remote URL: ${raw}`);
|
const sshAltMatch = raw.match(/^ssh:\/\/git@([^/:]+)(?::\d+)?\/([^/]+)\/([^/]+?)(?:\.git)?$/i);
|
||||||
|
if (sshAltMatch) {
|
||||||
|
return { host: sshAltMatch[1], owner: sshAltMatch[2], repo: sshAltMatch[3] };
|
||||||
|
}
|
||||||
|
throw new Error(`Cannot parse remote URL: ${raw}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCodebergRepo() {
|
function normalizeBaseUrl(url) {
|
||||||
const remotes = ["codeberg", "origin"];
|
const raw = String(url || "").trim().replace(/\/+$/, "");
|
||||||
|
if (!raw) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
if (!/^https?:\/\//i.test(raw)) {
|
||||||
|
throw new Error("GITEA_BASE_URL must start with http:// or https://");
|
||||||
|
}
|
||||||
|
return raw;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getGiteaRepo() {
|
||||||
|
const forcedRemote = String(process.env.GITEA_REMOTE || process.env.FORGEJO_REMOTE || "").trim();
|
||||||
|
const remotes = forcedRemote
|
||||||
|
? [forcedRemote]
|
||||||
|
: ["gitea", "forgejo", "origin", "github-new", "codeberg"];
|
||||||
|
|
||||||
|
const preferredBase = normalizeBaseUrl(process.env.GITEA_BASE_URL || process.env.FORGEJO_BASE_URL || "https://git.24-music.de");
|
||||||
|
|
||||||
|
const preferredProtocol = preferredBase ? new URL(preferredBase).protocol : "https:";
|
||||||
|
|
||||||
for (const remote of remotes) {
|
for (const remote of remotes) {
|
||||||
try {
|
try {
|
||||||
const remoteUrl = runCapture("git", ["remote", "get-url", remote]);
|
const remoteUrl = runCapture("git", ["remote", "get-url", remote]);
|
||||||
if (/codeberg\.org/i.test(remoteUrl)) {
|
const parsed = parseRemoteUrl(remoteUrl);
|
||||||
const parsed = parseCodebergRemote(remoteUrl);
|
const remoteBase = `https://${parsed.host}`.toLowerCase();
|
||||||
return { remote, ...parsed };
|
if (preferredBase && remoteBase !== preferredBase.toLowerCase().replace(/^http:/, "https:")) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
return { remote, ...parsed, baseUrl: `${preferredProtocol}//${parsed.host}` };
|
||||||
} catch {
|
} catch {
|
||||||
// try next remote
|
// try next remote
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new Error("No Codeberg remote found. Add one with: git remote add codeberg https://codeberg.org/<owner>/<repo>.git");
|
|
||||||
|
if (preferredBase) {
|
||||||
|
throw new Error(
|
||||||
|
`No remote found for ${preferredBase}. Add one with: git remote add gitea ${preferredBase}/<owner>/<repo>.git`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error("No suitable remote found. Set GITEA_REMOTE or GITEA_BASE_URL.");
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCodebergAuthHeader() {
|
function getAuthHeader(host) {
|
||||||
const credentialText = runWithInput("git", ["credential", "fill"], "protocol=https\nhost=codeberg.org\n\n");
|
const explicitToken = String(process.env.GITEA_TOKEN || process.env.FORGEJO_TOKEN || "").trim();
|
||||||
|
if (explicitToken) {
|
||||||
|
return `token ${explicitToken}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const credentialText = runWithInput("git", ["credential", "fill"], `protocol=https\nhost=${host}\n\n`);
|
||||||
const map = new Map();
|
const map = new Map();
|
||||||
for (const line of credentialText.split(/\r?\n/)) {
|
for (const line of credentialText.split(/\r?\n/)) {
|
||||||
if (!line.includes("=")) {
|
if (!line.includes("=")) {
|
||||||
@ -101,7 +147,9 @@ function getCodebergAuthHeader() {
|
|||||||
const username = map.get("username") || "";
|
const username = map.get("username") || "";
|
||||||
const password = map.get("password") || "";
|
const password = map.get("password") || "";
|
||||||
if (!username || !password) {
|
if (!username || !password) {
|
||||||
throw new Error("Missing Codeberg credentials in git credential helper");
|
throw new Error(
|
||||||
|
`Missing credentials for ${host}. Set GITEA_TOKEN or store credentials for this host in git credential helper.`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
const token = Buffer.from(`${username}:${password}`, "utf8").toString("base64");
|
const token = Buffer.from(`${username}:${password}`, "utf8").toString("base64");
|
||||||
return `Basic ${token}`;
|
return `Basic ${token}`;
|
||||||
@ -142,7 +190,8 @@ function updatePackageVersion(rootDir, version) {
|
|||||||
const packagePath = path.join(rootDir, "package.json");
|
const packagePath = path.join(rootDir, "package.json");
|
||||||
const packageJson = JSON.parse(fs.readFileSync(packagePath, "utf8"));
|
const packageJson = JSON.parse(fs.readFileSync(packagePath, "utf8"));
|
||||||
if (String(packageJson.version || "") === version) {
|
if (String(packageJson.version || "") === version) {
|
||||||
throw new Error(`package.json is already at version ${version}`);
|
process.stdout.write(`package.json is already at version ${version}, skipping update.\n`);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
packageJson.version = version;
|
packageJson.version = version;
|
||||||
fs.writeFileSync(packagePath, `${JSON.stringify(packageJson, null, 2)}\n`, "utf8");
|
fs.writeFileSync(packagePath, `${JSON.stringify(packageJson, null, 2)}\n`, "utf8");
|
||||||
@ -197,8 +246,7 @@ function ensureTagMissing(tag) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createOrGetRelease(owner, repo, tag, authHeader, notes) {
|
async function createOrGetRelease(baseApi, tag, authHeader, notes) {
|
||||||
const baseApi = `https://codeberg.org/api/v1/repos/${owner}/${repo}`;
|
|
||||||
const byTag = await apiRequest("GET", `${baseApi}/releases/tags/${encodeURIComponent(tag)}`, authHeader);
|
const byTag = await apiRequest("GET", `${baseApi}/releases/tags/${encodeURIComponent(tag)}`, authHeader);
|
||||||
if (byTag.ok) {
|
if (byTag.ok) {
|
||||||
return byTag.body;
|
return byTag.body;
|
||||||
@ -218,13 +266,34 @@ async function createOrGetRelease(owner, repo, tag, authHeader, notes) {
|
|||||||
return created.body;
|
return created.body;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function uploadReleaseAssets(owner, repo, releaseId, authHeader, releaseDir, files) {
|
async function uploadReleaseAssets(baseApi, releaseId, authHeader, releaseDir, files) {
|
||||||
const baseApi = `https://codeberg.org/api/v1/repos/${owner}/${repo}`;
|
|
||||||
for (const fileName of files) {
|
for (const fileName of files) {
|
||||||
const filePath = path.join(releaseDir, fileName);
|
const filePath = path.join(releaseDir, fileName);
|
||||||
const fileData = fs.readFileSync(filePath);
|
const fileSize = fs.statSync(filePath).size;
|
||||||
const uploadUrl = `${baseApi}/releases/${releaseId}/assets?name=${encodeURIComponent(fileName)}`;
|
const uploadUrl = `${baseApi}/releases/${releaseId}/assets?name=${encodeURIComponent(fileName)}`;
|
||||||
const response = await apiRequest("POST", uploadUrl, authHeader, fileData, "application/octet-stream");
|
|
||||||
|
// Stream large files instead of loading them entirely into memory
|
||||||
|
const fileStream = fs.createReadStream(filePath);
|
||||||
|
const response = await fetch(uploadUrl, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
Accept: "application/json",
|
||||||
|
Authorization: authHeader,
|
||||||
|
"Content-Type": "application/octet-stream",
|
||||||
|
"Content-Length": String(fileSize)
|
||||||
|
},
|
||||||
|
body: fileStream,
|
||||||
|
duplex: "half"
|
||||||
|
});
|
||||||
|
|
||||||
|
const text = await response.text();
|
||||||
|
let parsed;
|
||||||
|
try {
|
||||||
|
parsed = text ? JSON.parse(text) : null;
|
||||||
|
} catch {
|
||||||
|
parsed = text;
|
||||||
|
}
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
process.stdout.write(`Uploaded: ${fileName}\n`);
|
process.stdout.write(`Uploaded: ${fileName}\n`);
|
||||||
continue;
|
continue;
|
||||||
@ -233,7 +302,7 @@ async function uploadReleaseAssets(owner, repo, releaseId, authHeader, releaseDi
|
|||||||
process.stdout.write(`Skipped existing asset: ${fileName}\n`);
|
process.stdout.write(`Skipped existing asset: ${fileName}\n`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
throw new Error(`Asset upload failed for ${fileName} (${response.status}): ${JSON.stringify(response.body)}`);
|
throw new Error(`Asset upload failed for ${fileName} (${response.status}): ${JSON.stringify(parsed)}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,46 +310,44 @@ async function main() {
|
|||||||
const rootDir = process.cwd();
|
const rootDir = process.cwd();
|
||||||
const args = parseArgs(process.argv);
|
const args = parseArgs(process.argv);
|
||||||
if (args.help) {
|
if (args.help) {
|
||||||
process.stdout.write("Usage: npm run release:codeberg -- <version> [release notes] [--dry-run]\n");
|
process.stdout.write("Usage: npm run release:gitea -- <version> [release notes] [--dry-run]\n");
|
||||||
process.stdout.write("Example: npm run release:codeberg -- 1.4.42 \"- Small fixes\"\n");
|
process.stdout.write("Env: GITEA_BASE_URL, GITEA_REMOTE, GITEA_TOKEN\n");
|
||||||
|
process.stdout.write("Compatibility envs still supported: FORGEJO_BASE_URL, FORGEJO_REMOTE, FORGEJO_TOKEN\n");
|
||||||
|
process.stdout.write("Example: npm run release:gitea -- 1.6.31 \"- Bugfixes\"\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const version = ensureVersionString(args.version);
|
const version = ensureVersionString(args.version);
|
||||||
const tag = `v${version}`;
|
const tag = `v${version}`;
|
||||||
const releaseNotes = args.notes || `- Release ${tag}`;
|
const releaseNotes = args.notes || `- Release ${tag}`;
|
||||||
const { remote, owner, repo } = getCodebergRepo();
|
const repo = getGiteaRepo();
|
||||||
|
|
||||||
ensureNoTrackedChanges();
|
ensureNoTrackedChanges();
|
||||||
ensureTagMissing(tag);
|
ensureTagMissing(tag);
|
||||||
updatePackageVersion(rootDir, version);
|
|
||||||
|
|
||||||
process.stdout.write(`Building release artifacts for ${tag}...\n`);
|
|
||||||
run(NPM_EXECUTABLE, ["run", "release:win"]);
|
|
||||||
const assets = ensureAssetsExist(rootDir, version);
|
|
||||||
|
|
||||||
if (args.dryRun) {
|
if (args.dryRun) {
|
||||||
process.stdout.write(`Dry run complete. Assets exist for ${tag}.\n`);
|
process.stdout.write(`Dry run: would release ${tag}. No changes made.\n`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updatePackageVersion(rootDir, version);
|
||||||
|
|
||||||
|
process.stdout.write(`Building release artifacts for ${tag}...\n`);
|
||||||
|
run(NPM_RELEASE_WIN.command, NPM_RELEASE_WIN.args);
|
||||||
|
const assets = ensureAssetsExist(rootDir, version);
|
||||||
|
|
||||||
run("git", ["add", "package.json"]);
|
run("git", ["add", "package.json"]);
|
||||||
run("git", ["commit", "-m", `Release ${tag}`]);
|
run("git", ["commit", "-m", `Release ${tag}`]);
|
||||||
run("git", ["push", remote, "main"]);
|
run("git", ["push", repo.remote, "main"]);
|
||||||
run("git", ["tag", tag]);
|
run("git", ["tag", tag]);
|
||||||
run("git", ["push", remote, tag]);
|
run("git", ["push", repo.remote, tag]);
|
||||||
|
|
||||||
const authHeader = getCodebergAuthHeader();
|
const authHeader = getAuthHeader(repo.host);
|
||||||
const baseRepoApi = `https://codeberg.org/api/v1/repos/${owner}/${repo}`;
|
const baseApi = `${repo.baseUrl}/api/v1/repos/${repo.owner}/${repo.repo}`;
|
||||||
const patchReleaseEnabled = await apiRequest("PATCH", baseRepoApi, authHeader, JSON.stringify({ has_releases: true }));
|
const release = await createOrGetRelease(baseApi, tag, authHeader, releaseNotes);
|
||||||
if (!patchReleaseEnabled.ok) {
|
await uploadReleaseAssets(baseApi, release.id, authHeader, assets.releaseDir, assets.files);
|
||||||
throw new Error(`Failed to enable releases (${patchReleaseEnabled.status}): ${JSON.stringify(patchReleaseEnabled.body)}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const release = await createOrGetRelease(owner, repo, tag, authHeader, releaseNotes);
|
process.stdout.write(`Release published: ${release.html_url || `${repo.baseUrl}/${repo.owner}/${repo.repo}/releases/tag/${tag}`}\n`);
|
||||||
await uploadReleaseAssets(owner, repo, release.id, authHeader, assets.releaseDir, assets.files);
|
|
||||||
|
|
||||||
process.stdout.write(`Release published: ${release.html_url}\n`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main().catch((error) => {
|
main().catch((error) => {
|
||||||
@ -1,24 +0,0 @@
|
|||||||
import fs from "node:fs";
|
|
||||||
import path from "node:path";
|
|
||||||
|
|
||||||
const version = process.argv[2];
|
|
||||||
if (!version) {
|
|
||||||
console.error("Usage: node scripts/set_version_node.mjs <version>");
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
const root = process.cwd();
|
|
||||||
|
|
||||||
const packageJsonPath = path.join(root, "package.json");
|
|
||||||
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
||||||
packageJson.version = version;
|
|
||||||
fs.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`, "utf8");
|
|
||||||
|
|
||||||
const constantsPath = path.join(root, "src", "main", "constants.ts");
|
|
||||||
const constants = fs.readFileSync(constantsPath, "utf8").replace(
|
|
||||||
/APP_VERSION = "[^"]+"/,
|
|
||||||
`APP_VERSION = "${version}"`
|
|
||||||
);
|
|
||||||
fs.writeFileSync(constantsPath, constants, "utf8");
|
|
||||||
|
|
||||||
console.log(`Set version to ${version}`);
|
|
||||||
@ -5,6 +5,7 @@ import {
|
|||||||
AppSettings,
|
AppSettings,
|
||||||
DuplicatePolicy,
|
DuplicatePolicy,
|
||||||
HistoryEntry,
|
HistoryEntry,
|
||||||
|
PackagePriority,
|
||||||
ParsedPackageInput,
|
ParsedPackageInput,
|
||||||
SessionStats,
|
SessionStats,
|
||||||
StartConflictEntry,
|
StartConflictEntry,
|
||||||
@ -104,6 +105,7 @@ export class AppController {
|
|||||||
|| (settings.megaLogin.trim() && settings.megaPassword.trim())
|
|| (settings.megaLogin.trim() && settings.megaPassword.trim())
|
||||||
|| settings.bestToken.trim()
|
|| settings.bestToken.trim()
|
||||||
|| settings.allDebridToken.trim()
|
|| settings.allDebridToken.trim()
|
||||||
|
|| (settings.ddownloadLogin.trim() && settings.ddownloadPassword.trim())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -283,7 +285,14 @@ export class AppController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public exportBackup(): string {
|
public exportBackup(): string {
|
||||||
const settings = this.settings;
|
const settings = { ...this.settings };
|
||||||
|
const SENSITIVE_KEYS: (keyof AppSettings)[] = ["token", "megaLogin", "megaPassword", "bestToken", "allDebridToken", "ddownloadLogin", "ddownloadPassword"];
|
||||||
|
for (const key of SENSITIVE_KEYS) {
|
||||||
|
const val = settings[key];
|
||||||
|
if (typeof val === "string" && val.length > 0) {
|
||||||
|
(settings as Record<string, unknown>)[key] = `***${val.slice(-4)}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
const session = this.manager.getSession();
|
const session = this.manager.getSession();
|
||||||
return JSON.stringify({ version: 1, settings, session }, null, 2);
|
return JSON.stringify({ version: 1, settings, session }, null, 2);
|
||||||
}
|
}
|
||||||
@ -298,7 +307,15 @@ export class AppController {
|
|||||||
if (!parsed || typeof parsed !== "object" || !parsed.settings || !parsed.session) {
|
if (!parsed || typeof parsed !== "object" || !parsed.settings || !parsed.session) {
|
||||||
return { restored: false, message: "Kein gültiges Backup (settings/session fehlen)" };
|
return { restored: false, message: "Kein gültiges Backup (settings/session fehlen)" };
|
||||||
}
|
}
|
||||||
const restoredSettings = normalizeSettings(parsed.settings as AppSettings);
|
const importedSettings = parsed.settings as AppSettings;
|
||||||
|
const SENSITIVE_KEYS: (keyof AppSettings)[] = ["token", "megaLogin", "megaPassword", "bestToken", "allDebridToken", "ddownloadLogin", "ddownloadPassword"];
|
||||||
|
for (const key of SENSITIVE_KEYS) {
|
||||||
|
const val = (importedSettings as Record<string, unknown>)[key];
|
||||||
|
if (typeof val === "string" && val.startsWith("***")) {
|
||||||
|
(importedSettings as Record<string, unknown>)[key] = (this.settings as Record<string, unknown>)[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const restoredSettings = normalizeSettings(importedSettings);
|
||||||
this.settings = restoredSettings;
|
this.settings = restoredSettings;
|
||||||
saveSettings(this.storagePaths, this.settings);
|
saveSettings(this.storagePaths, this.settings);
|
||||||
this.manager.setSettings(this.settings);
|
this.manager.setSettings(this.settings);
|
||||||
@ -317,6 +334,9 @@ export class AppController {
|
|||||||
// Prevent prepareForShutdown from overwriting the restored session file
|
// Prevent prepareForShutdown from overwriting the restored session file
|
||||||
// with the old in-memory session when the app quits after backup restore.
|
// with the old in-memory session when the app quits after backup restore.
|
||||||
this.manager.skipShutdownPersist = true;
|
this.manager.skipShutdownPersist = true;
|
||||||
|
// Block all persistence (including persistSoon from any IPC operations
|
||||||
|
// the user might trigger before restarting) to protect the restored backup.
|
||||||
|
this.manager.blockAllPersistence = true;
|
||||||
return { restored: true, message: "Backup wiederhergestellt. Bitte App neustarten." };
|
return { restored: true, message: "Backup wiederhergestellt. Bitte App neustarten." };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -341,8 +361,8 @@ export class AppController {
|
|||||||
clearHistory(this.storagePaths);
|
clearHistory(this.storagePaths);
|
||||||
}
|
}
|
||||||
|
|
||||||
public setPackagePriority(packageId: string, priority: string): void {
|
public setPackagePriority(packageId: string, priority: PackagePriority): void {
|
||||||
this.manager.setPackagePriority(packageId, priority as any);
|
this.manager.setPackagePriority(packageId, priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
public skipItems(itemIds: string[]): void {
|
public skipItems(itemIds: string[]): void {
|
||||||
|
|||||||
@ -35,7 +35,7 @@ export const MAX_LINK_ARTIFACT_BYTES = 256 * 1024;
|
|||||||
export const SPEED_WINDOW_SECONDS = 1;
|
export const SPEED_WINDOW_SECONDS = 1;
|
||||||
export const CLIPBOARD_POLL_INTERVAL_MS = 2000;
|
export const CLIPBOARD_POLL_INTERVAL_MS = 2000;
|
||||||
|
|
||||||
export const DEFAULT_UPDATE_REPO = "Sucukdeluxe/real-debrid-downloader";
|
export const DEFAULT_UPDATE_REPO = "Administrator/real-debrid-downloader";
|
||||||
|
|
||||||
export function defaultSettings(): AppSettings {
|
export function defaultSettings(): AppSettings {
|
||||||
const baseDir = path.join(os.homedir(), "Downloads", "RealDebrid");
|
const baseDir = path.join(os.homedir(), "Downloads", "RealDebrid");
|
||||||
@ -45,6 +45,8 @@ export function defaultSettings(): AppSettings {
|
|||||||
megaPassword: "",
|
megaPassword: "",
|
||||||
bestToken: "",
|
bestToken: "",
|
||||||
allDebridToken: "",
|
allDebridToken: "",
|
||||||
|
ddownloadLogin: "",
|
||||||
|
ddownloadPassword: "",
|
||||||
archivePasswordList: "",
|
archivePasswordList: "",
|
||||||
rememberToken: true,
|
rememberToken: true,
|
||||||
providerPrimary: "realdebrid",
|
providerPrimary: "realdebrid",
|
||||||
|
|||||||
@ -164,7 +164,7 @@ async function decryptDlcLocal(filePath: string): Promise<ParsedPackageInput[]>
|
|||||||
const dlcData = content.slice(0, -88);
|
const dlcData = content.slice(0, -88);
|
||||||
|
|
||||||
const rcUrl = DLC_SERVICE_URL.replace("{KEY}", encodeURIComponent(dlcKey));
|
const rcUrl = DLC_SERVICE_URL.replace("{KEY}", encodeURIComponent(dlcKey));
|
||||||
const rcResponse = await fetch(rcUrl, { method: "GET" });
|
const rcResponse = await fetch(rcUrl, { method: "GET", signal: AbortSignal.timeout(30000) });
|
||||||
if (!rcResponse.ok) {
|
if (!rcResponse.ok) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@ -217,7 +217,8 @@ async function tryDcryptUpload(fileContent: Buffer, fileName: string): Promise<s
|
|||||||
|
|
||||||
const response = await fetch(DCRYPT_UPLOAD_URL, {
|
const response = await fetch(DCRYPT_UPLOAD_URL, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: form
|
body: form,
|
||||||
|
signal: AbortSignal.timeout(30000)
|
||||||
});
|
});
|
||||||
if (response.status === 413) {
|
if (response.status === 413) {
|
||||||
return null;
|
return null;
|
||||||
@ -235,7 +236,8 @@ async function tryDcryptPaste(fileContent: Buffer): Promise<string[] | null> {
|
|||||||
|
|
||||||
const response = await fetch(DCRYPT_PASTE_URL, {
|
const response = await fetch(DCRYPT_PASTE_URL, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: form
|
body: form,
|
||||||
|
signal: AbortSignal.timeout(30000)
|
||||||
});
|
});
|
||||||
if (response.status === 413) {
|
if (response.status === 413) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@ -15,7 +15,8 @@ const PROVIDER_LABELS: Record<DebridProvider, string> = {
|
|||||||
realdebrid: "Real-Debrid",
|
realdebrid: "Real-Debrid",
|
||||||
megadebrid: "Mega-Debrid",
|
megadebrid: "Mega-Debrid",
|
||||||
bestdebrid: "BestDebrid",
|
bestdebrid: "BestDebrid",
|
||||||
alldebrid: "AllDebrid"
|
alldebrid: "AllDebrid",
|
||||||
|
ddownload: "DDownload"
|
||||||
};
|
};
|
||||||
|
|
||||||
interface ProviderUnrestrictedLink extends UnrestrictedLink {
|
interface ProviderUnrestrictedLink extends UnrestrictedLink {
|
||||||
@ -640,7 +641,7 @@ class MegaDebridClient {
|
|||||||
throw new Error("Mega-Web Antwort ohne Download-Link");
|
throw new Error("Mega-Web Antwort ohne Download-Link");
|
||||||
}
|
}
|
||||||
if (!lastError) {
|
if (!lastError) {
|
||||||
lastError = web ? "Mega-Web Antwort ohne Download-Link" : "Mega-Web Antwort leer";
|
lastError = "Mega-Web Antwort leer";
|
||||||
}
|
}
|
||||||
// Don't retry permanent hoster errors (dead link, file removed, etc.)
|
// Don't retry permanent hoster errors (dead link, file removed, etc.)
|
||||||
if (/permanent ungültig|hosternotavailable|file.?not.?found|file.?unavailable|link.?is.?dead/i.test(lastError)) {
|
if (/permanent ungültig|hosternotavailable|file.?not.?found|file.?unavailable|link.?is.?dead/i.test(lastError)) {
|
||||||
@ -958,11 +959,204 @@ class AllDebridClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
private login: string;
|
||||||
|
private password: string;
|
||||||
|
private cookies: string = "";
|
||||||
|
|
||||||
|
public constructor(login: string, password: string) {
|
||||||
|
this.login = login;
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async webLogin(signal?: AbortSignal): Promise<void> {
|
||||||
|
// Step 1: GET login page to extract form token
|
||||||
|
const loginPageRes = await fetch(`${DDOWNLOAD_WEB_BASE}/login.html`, {
|
||||||
|
headers: { "User-Agent": DDOWNLOAD_WEB_UA },
|
||||||
|
redirect: "manual",
|
||||||
|
signal: withTimeoutSignal(signal, API_TIMEOUT_MS)
|
||||||
|
});
|
||||||
|
const loginPageHtml = await loginPageRes.text();
|
||||||
|
const tokenMatch = loginPageHtml.match(/name="token" value="([^"]+)"/);
|
||||||
|
const pageCookies = (loginPageRes.headers.getSetCookie?.() || []).map((c: string) => c.split(";")[0]).join("; ");
|
||||||
|
|
||||||
|
// Step 2: POST login
|
||||||
|
const body = new URLSearchParams({
|
||||||
|
op: "login",
|
||||||
|
token: tokenMatch?.[1] || "",
|
||||||
|
rand: "",
|
||||||
|
redirect: "",
|
||||||
|
login: this.login,
|
||||||
|
password: this.password
|
||||||
|
});
|
||||||
|
const loginRes = await fetch(`${DDOWNLOAD_WEB_BASE}/`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"User-Agent": DDOWNLOAD_WEB_UA,
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
|
...(pageCookies ? { Cookie: pageCookies } : {})
|
||||||
|
},
|
||||||
|
body: body.toString(),
|
||||||
|
redirect: "manual",
|
||||||
|
signal: withTimeoutSignal(signal, API_TIMEOUT_MS)
|
||||||
|
});
|
||||||
|
|
||||||
|
// Drain body
|
||||||
|
try { await loginRes.text(); } catch { /* ignore */ }
|
||||||
|
|
||||||
|
const setCookies = loginRes.headers.getSetCookie?.() || [];
|
||||||
|
const xfss = setCookies.find((c: string) => c.startsWith("xfss="));
|
||||||
|
const loginCookie = setCookies.find((c: string) => c.startsWith("login="));
|
||||||
|
if (!xfss) {
|
||||||
|
throw new Error("DDownload Login fehlgeschlagen (kein Session-Cookie)");
|
||||||
|
}
|
||||||
|
this.cookies = [loginCookie, xfss].filter(Boolean).map((c: string) => c.split(";")[0]).join("; ");
|
||||||
|
}
|
||||||
|
|
||||||
|
public async unrestrictLink(link: string, signal?: AbortSignal): Promise<UnrestrictedLink> {
|
||||||
|
const match = link.match(DDOWNLOAD_URL_RE);
|
||||||
|
if (!match) {
|
||||||
|
throw new Error("Kein DDownload-Link");
|
||||||
|
}
|
||||||
|
const fileCode = match[1];
|
||||||
|
let lastError = "";
|
||||||
|
|
||||||
|
for (let attempt = 1; attempt <= REQUEST_RETRIES; attempt += 1) {
|
||||||
|
try {
|
||||||
|
if (signal?.aborted) throw new Error("aborted:debrid");
|
||||||
|
|
||||||
|
// Login if no session yet
|
||||||
|
if (!this.cookies) {
|
||||||
|
await this.webLogin(signal);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 1: GET file page to extract form fields
|
||||||
|
const filePageRes = await fetch(`${DDOWNLOAD_WEB_BASE}/${fileCode}`, {
|
||||||
|
headers: {
|
||||||
|
"User-Agent": DDOWNLOAD_WEB_UA,
|
||||||
|
Cookie: this.cookies
|
||||||
|
},
|
||||||
|
redirect: "manual",
|
||||||
|
signal: withTimeoutSignal(signal, API_TIMEOUT_MS)
|
||||||
|
});
|
||||||
|
|
||||||
|
// Premium with direct downloads enabled → redirect immediately
|
||||||
|
if (filePageRes.status >= 300 && filePageRes.status < 400) {
|
||||||
|
const directUrl = filePageRes.headers.get("location") || "";
|
||||||
|
try { await filePageRes.text(); } catch { /* drain */ }
|
||||||
|
if (directUrl) {
|
||||||
|
return {
|
||||||
|
fileName: filenameFromUrl(directUrl) || filenameFromUrl(link),
|
||||||
|
directUrl,
|
||||||
|
fileSize: null,
|
||||||
|
retriesUsed: attempt - 1,
|
||||||
|
skipTlsVerify: true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const html = await filePageRes.text();
|
||||||
|
|
||||||
|
// Check for file not found
|
||||||
|
if (/File Not Found|file was removed|file was banned/i.test(html)) {
|
||||||
|
throw new Error("DDownload: Datei nicht gefunden");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract form fields
|
||||||
|
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);
|
||||||
|
|
||||||
|
// Step 2: POST download2 for premium download
|
||||||
|
const dlBody = new URLSearchParams({
|
||||||
|
op: "download2",
|
||||||
|
id: idVal,
|
||||||
|
rand: randVal,
|
||||||
|
referer: "",
|
||||||
|
method_premium: "1",
|
||||||
|
adblock_detected: "0"
|
||||||
|
});
|
||||||
|
|
||||||
|
const dlRes = await fetch(`${DDOWNLOAD_WEB_BASE}/${fileCode}`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"User-Agent": DDOWNLOAD_WEB_UA,
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
|
Cookie: this.cookies,
|
||||||
|
Referer: `${DDOWNLOAD_WEB_BASE}/${fileCode}`
|
||||||
|
},
|
||||||
|
body: dlBody.toString(),
|
||||||
|
redirect: "manual",
|
||||||
|
signal: withTimeoutSignal(signal, API_TIMEOUT_MS)
|
||||||
|
});
|
||||||
|
|
||||||
|
if (dlRes.status >= 300 && dlRes.status < 400) {
|
||||||
|
const directUrl = dlRes.headers.get("location") || "";
|
||||||
|
try { await dlRes.text(); } catch { /* drain */ }
|
||||||
|
if (directUrl) {
|
||||||
|
return {
|
||||||
|
fileName: fileName || filenameFromUrl(directUrl),
|
||||||
|
directUrl,
|
||||||
|
fileSize: null,
|
||||||
|
retriesUsed: attempt - 1,
|
||||||
|
skipTlsVerify: true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const dlHtml = await dlRes.text();
|
||||||
|
// Try to find direct URL in response HTML
|
||||||
|
const directMatch = dlHtml.match(/https?:\/\/[a-z0-9]+\.(?:dstorage\.org|ddownload\.com|ddl\.to|ucdn\.to)[^\s"'<>]+/i);
|
||||||
|
if (directMatch) {
|
||||||
|
return {
|
||||||
|
fileName,
|
||||||
|
directUrl: directMatch[0],
|
||||||
|
fileSize: null,
|
||||||
|
retriesUsed: attempt - 1,
|
||||||
|
skipTlsVerify: true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for error messages
|
||||||
|
const errMatch = dlHtml.match(/class="err"[^>]*>([^<]+)</i);
|
||||||
|
if (errMatch) {
|
||||||
|
throw new Error(`DDownload: ${errMatch[1].trim()}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error("DDownload: Kein Download-Link erhalten");
|
||||||
|
} catch (error) {
|
||||||
|
lastError = compactErrorText(error);
|
||||||
|
if (signal?.aborted || (/aborted/i.test(lastError) && !/timeout/i.test(lastError))) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Re-login on auth errors
|
||||||
|
if (/login|session|cookie/i.test(lastError)) {
|
||||||
|
this.cookies = "";
|
||||||
|
}
|
||||||
|
if (attempt >= REQUEST_RETRIES || !isRetryableErrorText(lastError)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
await sleepWithSignal(retryDelay(attempt), signal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(String(lastError || "DDownload Unrestrict fehlgeschlagen").replace(/^Error:\s*/i, ""));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class DebridService {
|
export class DebridService {
|
||||||
private settings: AppSettings;
|
private settings: AppSettings;
|
||||||
|
|
||||||
private options: DebridServiceOptions;
|
private options: DebridServiceOptions;
|
||||||
|
|
||||||
|
private cachedDdownloadClient: DdownloadClient | null = null;
|
||||||
|
private cachedDdownloadKey = "";
|
||||||
|
|
||||||
public constructor(settings: AppSettings, options: DebridServiceOptions = {}) {
|
public constructor(settings: AppSettings, options: DebridServiceOptions = {}) {
|
||||||
this.settings = cloneSettings(settings);
|
this.settings = cloneSettings(settings);
|
||||||
this.options = options;
|
this.options = options;
|
||||||
@ -972,6 +1166,16 @@ export class DebridService {
|
|||||||
this.settings = cloneSettings(next);
|
this.settings = cloneSettings(next);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getDdownloadClient(login: string, password: string): DdownloadClient {
|
||||||
|
const key = `${login}\0${password}`;
|
||||||
|
if (this.cachedDdownloadClient && this.cachedDdownloadKey === key) {
|
||||||
|
return this.cachedDdownloadClient;
|
||||||
|
}
|
||||||
|
this.cachedDdownloadClient = new DdownloadClient(login, password);
|
||||||
|
this.cachedDdownloadKey = key;
|
||||||
|
return this.cachedDdownloadClient;
|
||||||
|
}
|
||||||
|
|
||||||
public async resolveFilenames(
|
public async resolveFilenames(
|
||||||
links: string[],
|
links: string[],
|
||||||
onResolved?: (link: string, fileName: string) => void,
|
onResolved?: (link: string, fileName: string) => void,
|
||||||
@ -1024,6 +1228,27 @@ export class DebridService {
|
|||||||
|
|
||||||
public async unrestrictLink(link: string, signal?: AbortSignal, settingsSnapshot?: AppSettings): Promise<ProviderUnrestrictedLink> {
|
public async unrestrictLink(link: string, signal?: AbortSignal, settingsSnapshot?: AppSettings): Promise<ProviderUnrestrictedLink> {
|
||||||
const settings = settingsSnapshot ? cloneSettings(settingsSnapshot) : cloneSettings(this.settings);
|
const settings = settingsSnapshot ? cloneSettings(settingsSnapshot) : cloneSettings(this.settings);
|
||||||
|
|
||||||
|
// DDownload is a direct file hoster, not a debrid service.
|
||||||
|
// If the link is a ddownload.com/ddl.to URL and the account is configured,
|
||||||
|
// use DDownload directly before trying any debrid providers.
|
||||||
|
if (DDOWNLOAD_URL_RE.test(link) && this.isProviderConfiguredFor(settings, "ddownload")) {
|
||||||
|
try {
|
||||||
|
const result = await this.unrestrictViaProvider(settings, "ddownload", link, signal);
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
provider: "ddownload",
|
||||||
|
providerLabel: PROVIDER_LABELS["ddownload"]
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
const errorText = compactErrorText(error);
|
||||||
|
if (signal?.aborted || (/aborted/i.test(errorText) && !/timeout/i.test(errorText))) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
// Fall through to normal provider chain (debrid services may also support ddownload links)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const order = toProviderOrder(
|
const order = toProviderOrder(
|
||||||
settings.providerPrimary,
|
settings.providerPrimary,
|
||||||
settings.providerSecondary,
|
settings.providerSecondary,
|
||||||
@ -1109,6 +1334,9 @@ export class DebridService {
|
|||||||
if (provider === "alldebrid") {
|
if (provider === "alldebrid") {
|
||||||
return Boolean(settings.allDebridToken.trim());
|
return Boolean(settings.allDebridToken.trim());
|
||||||
}
|
}
|
||||||
|
if (provider === "ddownload") {
|
||||||
|
return Boolean(settings.ddownloadLogin.trim() && settings.ddownloadPassword.trim());
|
||||||
|
}
|
||||||
return Boolean(settings.bestToken.trim());
|
return Boolean(settings.bestToken.trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1122,6 +1350,9 @@ export class DebridService {
|
|||||||
if (provider === "alldebrid") {
|
if (provider === "alldebrid") {
|
||||||
return new AllDebridClient(settings.allDebridToken).unrestrictLink(link, signal);
|
return new AllDebridClient(settings.allDebridToken).unrestrictLink(link, signal);
|
||||||
}
|
}
|
||||||
|
if (provider === "ddownload") {
|
||||||
|
return this.getDdownloadClient(settings.ddownloadLogin, settings.ddownloadPassword).unrestrictLink(link, signal);
|
||||||
|
}
|
||||||
return new BestDebridClient(settings.bestToken).unrestrictLink(link, signal);
|
return new BestDebridClient(settings.bestToken).unrestrictLink(link, signal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -261,7 +261,7 @@ export function startDebugServer(mgr: DownloadManager, baseDir: string): void {
|
|||||||
const port = getPort(baseDir);
|
const port = getPort(baseDir);
|
||||||
|
|
||||||
server = http.createServer(handleRequest);
|
server = http.createServer(handleRequest);
|
||||||
server.listen(port, "0.0.0.0", () => {
|
server.listen(port, "127.0.0.1", () => {
|
||||||
logger.info(`Debug-Server gestartet auf Port ${port}`);
|
logger.info(`Debug-Server gestartet auf Port ${port}`);
|
||||||
});
|
});
|
||||||
server.on("error", (err) => {
|
server.on("error", (err) => {
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -7,6 +7,7 @@ import { IPC_CHANNELS } from "../shared/ipc";
|
|||||||
import { getLogFilePath, logger } from "./logger";
|
import { getLogFilePath, logger } from "./logger";
|
||||||
import { APP_NAME } from "./constants";
|
import { APP_NAME } from "./constants";
|
||||||
import { extractHttpLinksFromText } from "./utils";
|
import { extractHttpLinksFromText } from "./utils";
|
||||||
|
import { cleanupStaleSubstDrives, shutdownDaemon } from "./extractor";
|
||||||
|
|
||||||
/* ── IPC validation helpers ────────────────────────────────────── */
|
/* ── IPC validation helpers ────────────────────────────────────── */
|
||||||
function validateString(value: unknown, name: string): string {
|
function validateString(value: unknown, name: string): string {
|
||||||
@ -81,7 +82,7 @@ function createWindow(): BrowserWindow {
|
|||||||
responseHeaders: {
|
responseHeaders: {
|
||||||
...details.responseHeaders,
|
...details.responseHeaders,
|
||||||
"Content-Security-Policy": [
|
"Content-Security-Policy": [
|
||||||
"default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self' https://api.real-debrid.com https://codeberg.org https://bestdebrid.com https://api.alldebrid.com https://www.mega-debrid.eu"
|
"default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self' https://api.real-debrid.com https://codeberg.org https://bestdebrid.com https://api.alldebrid.com https://www.mega-debrid.eu https://git.24-music.de https://ddownload.com https://ddl.to"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -188,7 +189,12 @@ function startClipboardWatcher(): void {
|
|||||||
}
|
}
|
||||||
lastClipboardText = normalizeClipboardText(clipboard.readText());
|
lastClipboardText = normalizeClipboardText(clipboard.readText());
|
||||||
clipboardTimer = setInterval(() => {
|
clipboardTimer = setInterval(() => {
|
||||||
const text = normalizeClipboardText(clipboard.readText());
|
let text: string;
|
||||||
|
try {
|
||||||
|
text = normalizeClipboardText(clipboard.readText());
|
||||||
|
} catch {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (text === lastClipboardText || !text.trim()) {
|
if (text === lastClipboardText || !text.trim()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -481,6 +487,7 @@ app.on("second-instance", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.whenReady().then(() => {
|
app.whenReady().then(() => {
|
||||||
|
cleanupStaleSubstDrives();
|
||||||
registerIpcHandlers();
|
registerIpcHandlers();
|
||||||
mainWindow = createWindow();
|
mainWindow = createWindow();
|
||||||
bindMainWindowLifecycle(mainWindow);
|
bindMainWindowLifecycle(mainWindow);
|
||||||
@ -493,6 +500,9 @@ app.whenReady().then(() => {
|
|||||||
bindMainWindowLifecycle(mainWindow);
|
bindMainWindowLifecycle(mainWindow);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}).catch((error) => {
|
||||||
|
console.error("App startup failed:", error);
|
||||||
|
app.quit();
|
||||||
});
|
});
|
||||||
|
|
||||||
app.on("window-all-closed", () => {
|
app.on("window-all-closed", () => {
|
||||||
@ -505,6 +515,7 @@ app.on("before-quit", () => {
|
|||||||
if (updateQuitTimer) { clearTimeout(updateQuitTimer); updateQuitTimer = null; }
|
if (updateQuitTimer) { clearTimeout(updateQuitTimer); updateQuitTimer = null; }
|
||||||
stopClipboardWatcher();
|
stopClipboardWatcher();
|
||||||
destroyTray();
|
destroyTray();
|
||||||
|
shutdownDaemon();
|
||||||
try {
|
try {
|
||||||
controller.shutdown();
|
controller.shutdown();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@ -228,22 +228,23 @@ export class MegaWebFallback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async unrestrict(link: string, signal?: AbortSignal): Promise<UnrestrictedLink | null> {
|
public async unrestrict(link: string, signal?: AbortSignal): Promise<UnrestrictedLink | null> {
|
||||||
|
const overallSignal = withTimeoutSignal(signal, 180000);
|
||||||
return this.runExclusive(async () => {
|
return this.runExclusive(async () => {
|
||||||
throwIfAborted(signal);
|
throwIfAborted(overallSignal);
|
||||||
const creds = this.getCredentials();
|
const creds = this.getCredentials();
|
||||||
if (!creds.login.trim() || !creds.password.trim()) {
|
if (!creds.login.trim() || !creds.password.trim()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.cookie || Date.now() - this.cookieSetAt > 20 * 60 * 1000) {
|
if (!this.cookie || Date.now() - this.cookieSetAt > 20 * 60 * 1000) {
|
||||||
await this.login(creds.login, creds.password, signal);
|
await this.login(creds.login, creds.password, overallSignal);
|
||||||
}
|
}
|
||||||
|
|
||||||
const generated = await this.generate(link, signal);
|
const generated = await this.generate(link, overallSignal);
|
||||||
if (!generated) {
|
if (!generated) {
|
||||||
this.cookie = "";
|
this.cookie = "";
|
||||||
await this.login(creds.login, creds.password, signal);
|
await this.login(creds.login, creds.password, overallSignal);
|
||||||
const retry = await this.generate(link, signal);
|
const retry = await this.generate(link, overallSignal);
|
||||||
if (!retry) {
|
if (!retry) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -261,7 +262,7 @@ export class MegaWebFallback {
|
|||||||
fileSize: null,
|
fileSize: null,
|
||||||
retriesUsed: 0
|
retriesUsed: 0
|
||||||
};
|
};
|
||||||
}, signal);
|
}, overallSignal);
|
||||||
}
|
}
|
||||||
|
|
||||||
public invalidateSession(): void {
|
public invalidateSession(): void {
|
||||||
|
|||||||
@ -8,6 +8,7 @@ export interface UnrestrictedLink {
|
|||||||
directUrl: string;
|
directUrl: string;
|
||||||
fileSize: number | null;
|
fileSize: number | null;
|
||||||
retriesUsed: number;
|
retriesUsed: number;
|
||||||
|
skipTlsVerify?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
function shouldRetryStatus(status: number): boolean {
|
function shouldRetryStatus(status: number): boolean {
|
||||||
@ -78,6 +79,11 @@ async function sleepWithSignal(ms: number, signal?: AbortSignal): Promise<void>
|
|||||||
await sleep(ms);
|
await sleep(ms);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Check before entering the Promise constructor to avoid a race where the timer
|
||||||
|
// resolves before the aborted check runs (especially when ms=0).
|
||||||
|
if (signal.aborted) {
|
||||||
|
throw new Error("aborted");
|
||||||
|
}
|
||||||
await new Promise<void>((resolve, reject) => {
|
await new Promise<void>((resolve, reject) => {
|
||||||
let timer: NodeJS.Timeout | null = setTimeout(() => {
|
let timer: NodeJS.Timeout | null = setTimeout(() => {
|
||||||
timer = null;
|
timer = null;
|
||||||
@ -94,10 +100,6 @@ async function sleepWithSignal(ms: number, signal?: AbortSignal): Promise<void>
|
|||||||
reject(new Error("aborted"));
|
reject(new Error("aborted"));
|
||||||
};
|
};
|
||||||
|
|
||||||
if (signal.aborted) {
|
|
||||||
onAbort();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
signal.addEventListener("abort", onAbort, { once: true });
|
signal.addEventListener("abort", onAbort, { once: true });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -76,7 +76,12 @@ async function cleanupOldSessionLogs(dir: string, maxAgeDays: number): Promise<v
|
|||||||
|
|
||||||
export function initSessionLog(baseDir: string): void {
|
export function initSessionLog(baseDir: string): void {
|
||||||
sessionLogsDir = path.join(baseDir, "session-logs");
|
sessionLogsDir = path.join(baseDir, "session-logs");
|
||||||
|
try {
|
||||||
fs.mkdirSync(sessionLogsDir, { recursive: true });
|
fs.mkdirSync(sessionLogsDir, { recursive: true });
|
||||||
|
} catch {
|
||||||
|
sessionLogsDir = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const timestamp = formatTimestamp();
|
const timestamp = formatTimestamp();
|
||||||
sessionLogPath = path.join(sessionLogsDir, `session_${timestamp}.txt`);
|
sessionLogPath = path.join(sessionLogsDir, `session_${timestamp}.txt`);
|
||||||
|
|||||||
@ -5,8 +5,8 @@ import { AppSettings, BandwidthScheduleEntry, DebridProvider, DownloadItem, Down
|
|||||||
import { defaultSettings } from "./constants";
|
import { defaultSettings } from "./constants";
|
||||||
import { logger } from "./logger";
|
import { logger } from "./logger";
|
||||||
|
|
||||||
const VALID_PRIMARY_PROVIDERS = new Set(["realdebrid", "megadebrid", "bestdebrid", "alldebrid"]);
|
const VALID_PRIMARY_PROVIDERS = new Set(["realdebrid", "megadebrid", "bestdebrid", "alldebrid", "ddownload"]);
|
||||||
const VALID_FALLBACK_PROVIDERS = new Set(["none", "realdebrid", "megadebrid", "bestdebrid", "alldebrid"]);
|
const VALID_FALLBACK_PROVIDERS = new Set(["none", "realdebrid", "megadebrid", "bestdebrid", "alldebrid", "ddownload"]);
|
||||||
const VALID_CLEANUP_MODES = new Set(["none", "trash", "delete"]);
|
const VALID_CLEANUP_MODES = new Set(["none", "trash", "delete"]);
|
||||||
const VALID_CONFLICT_MODES = new Set(["overwrite", "skip", "rename", "ask"]);
|
const VALID_CONFLICT_MODES = new Set(["overwrite", "skip", "rename", "ask"]);
|
||||||
const VALID_FINISHED_POLICIES = new Set(["never", "immediate", "on_start", "package_done"]);
|
const VALID_FINISHED_POLICIES = new Set(["never", "immediate", "on_start", "package_done"]);
|
||||||
@ -17,7 +17,7 @@ const VALID_PACKAGE_PRIORITIES = new Set<string>(["high", "normal", "low"]);
|
|||||||
const VALID_DOWNLOAD_STATUSES = new Set<DownloadStatus>([
|
const VALID_DOWNLOAD_STATUSES = new Set<DownloadStatus>([
|
||||||
"queued", "validating", "downloading", "paused", "reconnect_wait", "extracting", "integrity_check", "completed", "failed", "cancelled"
|
"queued", "validating", "downloading", "paused", "reconnect_wait", "extracting", "integrity_check", "completed", "failed", "cancelled"
|
||||||
]);
|
]);
|
||||||
const VALID_ITEM_PROVIDERS = new Set<DebridProvider>(["realdebrid", "megadebrid", "bestdebrid", "alldebrid"]);
|
const VALID_ITEM_PROVIDERS = new Set<DebridProvider>(["realdebrid", "megadebrid", "bestdebrid", "alldebrid", "ddownload"]);
|
||||||
const VALID_ONLINE_STATUSES = new Set(["online", "offline", "checking"]);
|
const VALID_ONLINE_STATUSES = new Set(["online", "offline", "checking"]);
|
||||||
|
|
||||||
function asText(value: unknown): string {
|
function asText(value: unknown): string {
|
||||||
@ -91,6 +91,18 @@ function normalizeColumnOrder(raw: unknown): string[] {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const DEPRECATED_UPDATE_REPOS = new Set([
|
||||||
|
"sucukdeluxe/real-debrid-downloader"
|
||||||
|
]);
|
||||||
|
|
||||||
|
function migrateUpdateRepo(raw: string, fallback: string): string {
|
||||||
|
const trimmed = raw.trim();
|
||||||
|
if (!trimmed || DEPRECATED_UPDATE_REPOS.has(trimmed.toLowerCase())) {
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
return trimmed;
|
||||||
|
}
|
||||||
|
|
||||||
export function normalizeSettings(settings: AppSettings): AppSettings {
|
export function normalizeSettings(settings: AppSettings): AppSettings {
|
||||||
const defaults = defaultSettings();
|
const defaults = defaultSettings();
|
||||||
const normalized: AppSettings = {
|
const normalized: AppSettings = {
|
||||||
@ -99,7 +111,9 @@ export function normalizeSettings(settings: AppSettings): AppSettings {
|
|||||||
megaPassword: asText(settings.megaPassword),
|
megaPassword: asText(settings.megaPassword),
|
||||||
bestToken: asText(settings.bestToken),
|
bestToken: asText(settings.bestToken),
|
||||||
allDebridToken: asText(settings.allDebridToken),
|
allDebridToken: asText(settings.allDebridToken),
|
||||||
archivePasswordList: String(settings.archivePasswordList ?? "").replace(/\r\n/g, "\n"),
|
ddownloadLogin: asText(settings.ddownloadLogin),
|
||||||
|
ddownloadPassword: asText(settings.ddownloadPassword),
|
||||||
|
archivePasswordList: String(settings.archivePasswordList ?? "").replace(/\r\n|\r/g, "\n"),
|
||||||
rememberToken: Boolean(settings.rememberToken),
|
rememberToken: Boolean(settings.rememberToken),
|
||||||
providerPrimary: settings.providerPrimary,
|
providerPrimary: settings.providerPrimary,
|
||||||
providerSecondary: settings.providerSecondary,
|
providerSecondary: settings.providerSecondary,
|
||||||
@ -130,7 +144,7 @@ export function normalizeSettings(settings: AppSettings): AppSettings {
|
|||||||
speedLimitKbps: clampNumber(settings.speedLimitKbps, defaults.speedLimitKbps, 0, 500000),
|
speedLimitKbps: clampNumber(settings.speedLimitKbps, defaults.speedLimitKbps, 0, 500000),
|
||||||
speedLimitMode: settings.speedLimitMode,
|
speedLimitMode: settings.speedLimitMode,
|
||||||
autoUpdateCheck: Boolean(settings.autoUpdateCheck),
|
autoUpdateCheck: Boolean(settings.autoUpdateCheck),
|
||||||
updateRepo: asText(settings.updateRepo) || defaults.updateRepo,
|
updateRepo: migrateUpdateRepo(asText(settings.updateRepo), defaults.updateRepo),
|
||||||
clipboardWatch: Boolean(settings.clipboardWatch),
|
clipboardWatch: Boolean(settings.clipboardWatch),
|
||||||
minimizeToTray: Boolean(settings.minimizeToTray),
|
minimizeToTray: Boolean(settings.minimizeToTray),
|
||||||
collapseNewPackages: settings.collapseNewPackages !== undefined ? Boolean(settings.collapseNewPackages) : defaults.collapseNewPackages,
|
collapseNewPackages: settings.collapseNewPackages !== undefined ? Boolean(settings.collapseNewPackages) : defaults.collapseNewPackages,
|
||||||
@ -188,7 +202,9 @@ function sanitizeCredentialPersistence(settings: AppSettings): AppSettings {
|
|||||||
megaLogin: "",
|
megaLogin: "",
|
||||||
megaPassword: "",
|
megaPassword: "",
|
||||||
bestToken: "",
|
bestToken: "",
|
||||||
allDebridToken: ""
|
allDebridToken: "",
|
||||||
|
ddownloadLogin: "",
|
||||||
|
ddownloadPassword: ""
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -430,6 +446,7 @@ export function normalizeLoadedSessionTransientFields(session: SessionState): Se
|
|||||||
if (ACTIVE_PKG_STATUSES.has(pkg.status)) {
|
if (ACTIVE_PKG_STATUSES.has(pkg.status)) {
|
||||||
pkg.status = "queued";
|
pkg.status = "queued";
|
||||||
}
|
}
|
||||||
|
pkg.postProcessLabel = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear stale session-level running/paused flags
|
// Clear stale session-level running/paused flags
|
||||||
@ -485,6 +502,7 @@ async function writeSettingsPayload(paths: StoragePaths, payload: string): Promi
|
|||||||
await fsp.copyFile(tempPath, paths.configFile);
|
await fsp.copyFile(tempPath, paths.configFile);
|
||||||
await fsp.rm(tempPath, { force: true }).catch(() => {});
|
await fsp.rm(tempPath, { force: true }).catch(() => {});
|
||||||
} else {
|
} else {
|
||||||
|
await fsp.rm(tempPath, { force: true }).catch(() => {});
|
||||||
throw renameError;
|
throw renameError;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -605,6 +623,7 @@ async function writeSessionPayload(paths: StoragePaths, payload: string, generat
|
|||||||
await fsp.copyFile(tempPath, paths.sessionFile);
|
await fsp.copyFile(tempPath, paths.sessionFile);
|
||||||
await fsp.rm(tempPath, { force: true }).catch(() => {});
|
await fsp.rm(tempPath, { force: true }).catch(() => {});
|
||||||
} else {
|
} else {
|
||||||
|
await fsp.rm(tempPath, { force: true }).catch(() => {});
|
||||||
throw renameError;
|
throw renameError;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,8 +14,32 @@ const DOWNLOAD_BODY_IDLE_TIMEOUT_MS = 45000;
|
|||||||
const RETRIES_PER_CANDIDATE = 3;
|
const RETRIES_PER_CANDIDATE = 3;
|
||||||
const RETRY_DELAY_MS = 1500;
|
const RETRY_DELAY_MS = 1500;
|
||||||
const UPDATE_USER_AGENT = `RD-Node-Downloader/${APP_VERSION}`;
|
const UPDATE_USER_AGENT = `RD-Node-Downloader/${APP_VERSION}`;
|
||||||
const UPDATE_WEB_BASE = "https://codeberg.org";
|
type UpdateSource = {
|
||||||
const UPDATE_API_BASE = "https://codeberg.org/api/v1";
|
name: string;
|
||||||
|
webBase: string;
|
||||||
|
apiBase: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const UPDATE_SOURCES: UpdateSource[] = [
|
||||||
|
{
|
||||||
|
name: "git24",
|
||||||
|
webBase: "https://git.24-music.de",
|
||||||
|
apiBase: "https://git.24-music.de/api/v1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "codeberg",
|
||||||
|
webBase: "https://codeberg.org",
|
||||||
|
apiBase: "https://codeberg.org/api/v1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "github",
|
||||||
|
webBase: "https://github.com",
|
||||||
|
apiBase: "https://api.github.com"
|
||||||
|
}
|
||||||
|
];
|
||||||
|
const PRIMARY_UPDATE_SOURCE = UPDATE_SOURCES[0];
|
||||||
|
const UPDATE_WEB_BASE = PRIMARY_UPDATE_SOURCE.webBase;
|
||||||
|
const UPDATE_API_BASE = PRIMARY_UPDATE_SOURCE.apiBase;
|
||||||
|
|
||||||
let activeUpdateAbortController: AbortController | null = null;
|
let activeUpdateAbortController: AbortController | null = null;
|
||||||
|
|
||||||
@ -57,9 +81,9 @@ export function normalizeUpdateRepo(repo: string): string {
|
|||||||
|
|
||||||
const normalizeParts = (input: string): string => {
|
const normalizeParts = (input: string): string => {
|
||||||
const cleaned = input
|
const cleaned = input
|
||||||
.replace(/^https?:\/\/(?:www\.)?(?:codeberg\.org|github\.com)\//i, "")
|
.replace(/^https?:\/\/(?:www\.)?(?:codeberg\.org|github\.com|git\.24-music\.de)\//i, "")
|
||||||
.replace(/^(?:www\.)?(?:codeberg\.org|github\.com)\//i, "")
|
.replace(/^(?:www\.)?(?:codeberg\.org|github\.com|git\.24-music\.de)\//i, "")
|
||||||
.replace(/^git@(?:codeberg\.org|github\.com):/i, "")
|
.replace(/^git@(?:codeberg\.org|github\.com|git\.24-music\.de):/i, "")
|
||||||
.replace(/\.git$/i, "")
|
.replace(/\.git$/i, "")
|
||||||
.replace(/^\/+|\/+$/g, "");
|
.replace(/^\/+|\/+$/g, "");
|
||||||
const parts = cleaned.split("/").filter(Boolean);
|
const parts = cleaned.split("/").filter(Boolean);
|
||||||
@ -76,7 +100,13 @@ export function normalizeUpdateRepo(repo: string): string {
|
|||||||
try {
|
try {
|
||||||
const url = new URL(raw);
|
const url = new URL(raw);
|
||||||
const host = url.hostname.toLowerCase();
|
const host = url.hostname.toLowerCase();
|
||||||
if (host === "codeberg.org" || host === "www.codeberg.org" || host === "github.com" || host === "www.github.com") {
|
if (
|
||||||
|
host === "codeberg.org"
|
||||||
|
|| host === "www.codeberg.org"
|
||||||
|
|| host === "github.com"
|
||||||
|
|| host === "www.github.com"
|
||||||
|
|| host === "git.24-music.de"
|
||||||
|
) {
|
||||||
const normalized = normalizeParts(url.pathname);
|
const normalized = normalizeParts(url.pathname);
|
||||||
if (normalized) {
|
if (normalized) {
|
||||||
return normalized;
|
return normalized;
|
||||||
@ -306,6 +336,8 @@ function parseReleasePayload(payload: Record<string, unknown>, fallback: UpdateC
|
|||||||
const releaseUrl = String(payload.html_url || fallback.releaseUrl);
|
const releaseUrl = String(payload.html_url || fallback.releaseUrl);
|
||||||
const setup = pickSetupAsset(readReleaseAssets(payload));
|
const setup = pickSetupAsset(readReleaseAssets(payload));
|
||||||
|
|
||||||
|
const body = typeof payload.body === "string" ? payload.body.trim() : "";
|
||||||
|
|
||||||
return {
|
return {
|
||||||
updateAvailable: isRemoteNewer(APP_VERSION, latestVersion),
|
updateAvailable: isRemoteNewer(APP_VERSION, latestVersion),
|
||||||
currentVersion: APP_VERSION,
|
currentVersion: APP_VERSION,
|
||||||
@ -314,7 +346,8 @@ function parseReleasePayload(payload: Record<string, unknown>, fallback: UpdateC
|
|||||||
releaseUrl,
|
releaseUrl,
|
||||||
setupAssetUrl: setup?.browser_download_url || "",
|
setupAssetUrl: setup?.browser_download_url || "",
|
||||||
setupAssetName: setup?.name || "",
|
setupAssetName: setup?.name || "",
|
||||||
setupAssetDigest: setup?.digest || ""
|
setupAssetDigest: setup?.digest || "",
|
||||||
|
releaseNotes: body || undefined
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -761,7 +794,8 @@ async function downloadFile(url: string, targetPath: string, onProgress?: Update
|
|||||||
};
|
};
|
||||||
|
|
||||||
const reader = response.body.getReader();
|
const reader = response.body.getReader();
|
||||||
const chunks: Buffer[] = [];
|
const tempPath = targetPath + ".tmp";
|
||||||
|
const writeStream = fs.createWriteStream(tempPath);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
resetIdleTimer();
|
resetIdleTimer();
|
||||||
@ -775,27 +809,39 @@ async function downloadFile(url: string, targetPath: string, onProgress?: Update
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
const buf = Buffer.from(value.buffer, value.byteOffset, value.byteLength);
|
const buf = Buffer.from(value.buffer, value.byteOffset, value.byteLength);
|
||||||
chunks.push(buf);
|
if (!writeStream.write(buf)) {
|
||||||
|
await new Promise<void>((resolve) => writeStream.once("drain", resolve));
|
||||||
|
}
|
||||||
downloadedBytes += buf.byteLength;
|
downloadedBytes += buf.byteLength;
|
||||||
resetIdleTimer();
|
resetIdleTimer();
|
||||||
emitDownloadProgress(false);
|
emitDownloadProgress(false);
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
writeStream.destroy();
|
||||||
|
await fs.promises.rm(tempPath, { force: true }).catch(() => {});
|
||||||
|
throw error;
|
||||||
} finally {
|
} finally {
|
||||||
clearIdleTimer();
|
clearIdleTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await new Promise<void>((resolve, reject) => {
|
||||||
|
writeStream.end(() => resolve());
|
||||||
|
writeStream.on("error", reject);
|
||||||
|
});
|
||||||
|
|
||||||
if (idleTimedOut) {
|
if (idleTimedOut) {
|
||||||
|
await fs.promises.rm(tempPath, { force: true }).catch(() => {});
|
||||||
throw new Error(`Update Download Body Timeout nach ${Math.ceil(idleTimeoutMs / 1000)}s`);
|
throw new Error(`Update Download Body Timeout nach ${Math.ceil(idleTimeoutMs / 1000)}s`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const fileBuffer = Buffer.concat(chunks);
|
if (totalBytes && downloadedBytes !== totalBytes) {
|
||||||
if (totalBytes && fileBuffer.byteLength !== totalBytes) {
|
await fs.promises.rm(tempPath, { force: true }).catch(() => {});
|
||||||
throw new Error(`Update Download unvollständig (${fileBuffer.byteLength} / ${totalBytes} Bytes)`);
|
throw new Error(`Update Download unvollständig (${downloadedBytes} / ${totalBytes} Bytes)`);
|
||||||
}
|
}
|
||||||
|
|
||||||
await fs.promises.writeFile(targetPath, fileBuffer);
|
await fs.promises.rename(tempPath, targetPath);
|
||||||
emitDownloadProgress(true);
|
emitDownloadProgress(true);
|
||||||
logger.info(`Update-Download abgeschlossen: ${targetPath} (${fileBuffer.byteLength} Bytes)`);
|
logger.info(`Update-Download abgeschlossen: ${targetPath} (${downloadedBytes} Bytes)`);
|
||||||
|
|
||||||
return { expectedBytes: totalBytes };
|
return { expectedBytes: totalBytes };
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import {
|
|||||||
AppSettings,
|
AppSettings,
|
||||||
DuplicatePolicy,
|
DuplicatePolicy,
|
||||||
HistoryEntry,
|
HistoryEntry,
|
||||||
|
PackagePriority,
|
||||||
SessionStats,
|
SessionStats,
|
||||||
StartConflictEntry,
|
StartConflictEntry,
|
||||||
StartConflictResolutionResult,
|
StartConflictResolutionResult,
|
||||||
@ -56,7 +57,7 @@ const api: ElectronApi = {
|
|||||||
getHistory: (): Promise<HistoryEntry[]> => ipcRenderer.invoke(IPC_CHANNELS.GET_HISTORY),
|
getHistory: (): Promise<HistoryEntry[]> => ipcRenderer.invoke(IPC_CHANNELS.GET_HISTORY),
|
||||||
clearHistory: (): Promise<void> => ipcRenderer.invoke(IPC_CHANNELS.CLEAR_HISTORY),
|
clearHistory: (): Promise<void> => ipcRenderer.invoke(IPC_CHANNELS.CLEAR_HISTORY),
|
||||||
removeHistoryEntry: (entryId: string): Promise<void> => ipcRenderer.invoke(IPC_CHANNELS.REMOVE_HISTORY_ENTRY, entryId),
|
removeHistoryEntry: (entryId: string): Promise<void> => ipcRenderer.invoke(IPC_CHANNELS.REMOVE_HISTORY_ENTRY, entryId),
|
||||||
setPackagePriority: (packageId: string, priority: string): Promise<void> => ipcRenderer.invoke(IPC_CHANNELS.SET_PACKAGE_PRIORITY, packageId, priority),
|
setPackagePriority: (packageId: string, priority: PackagePriority): Promise<void> => ipcRenderer.invoke(IPC_CHANNELS.SET_PACKAGE_PRIORITY, packageId, priority),
|
||||||
skipItems: (itemIds: string[]): Promise<void> => ipcRenderer.invoke(IPC_CHANNELS.SKIP_ITEMS, itemIds),
|
skipItems: (itemIds: string[]): Promise<void> => ipcRenderer.invoke(IPC_CHANNELS.SKIP_ITEMS, itemIds),
|
||||||
resetItems: (itemIds: string[]): Promise<void> => ipcRenderer.invoke(IPC_CHANNELS.RESET_ITEMS, itemIds),
|
resetItems: (itemIds: string[]): Promise<void> => ipcRenderer.invoke(IPC_CHANNELS.RESET_ITEMS, itemIds),
|
||||||
startItems: (itemIds: string[]): Promise<void> => ipcRenderer.invoke(IPC_CHANNELS.START_ITEMS, itemIds),
|
startItems: (itemIds: string[]): Promise<void> => ipcRenderer.invoke(IPC_CHANNELS.START_ITEMS, itemIds),
|
||||||
|
|||||||
@ -36,6 +36,7 @@ interface ConfirmPromptState {
|
|||||||
message: string;
|
message: string;
|
||||||
confirmLabel: string;
|
confirmLabel: string;
|
||||||
danger?: boolean;
|
danger?: boolean;
|
||||||
|
details?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ContextMenuState {
|
interface ContextMenuState {
|
||||||
@ -61,7 +62,7 @@ const emptyStats = (): DownloadStats => ({
|
|||||||
|
|
||||||
const emptySnapshot = (): UiSnapshot => ({
|
const emptySnapshot = (): UiSnapshot => ({
|
||||||
settings: {
|
settings: {
|
||||||
token: "", megaLogin: "", megaPassword: "", bestToken: "", allDebridToken: "",
|
token: "", megaLogin: "", megaPassword: "", bestToken: "", allDebridToken: "", ddownloadLogin: "", ddownloadPassword: "",
|
||||||
archivePasswordList: "",
|
archivePasswordList: "",
|
||||||
rememberToken: true, providerPrimary: "realdebrid", providerSecondary: "megadebrid",
|
rememberToken: true, providerPrimary: "realdebrid", providerSecondary: "megadebrid",
|
||||||
providerTertiary: "bestdebrid", autoProviderFallback: true, outputDir: "", packageName: "",
|
providerTertiary: "bestdebrid", autoProviderFallback: true, outputDir: "", packageName: "",
|
||||||
@ -93,7 +94,7 @@ const cleanupLabels: Record<string, string> = {
|
|||||||
const AUTO_RENDER_PACKAGE_LIMIT = 260;
|
const AUTO_RENDER_PACKAGE_LIMIT = 260;
|
||||||
|
|
||||||
const providerLabels: Record<DebridProvider, string> = {
|
const providerLabels: Record<DebridProvider, string> = {
|
||||||
realdebrid: "Real-Debrid", megadebrid: "Mega-Debrid", bestdebrid: "BestDebrid", alldebrid: "AllDebrid"
|
realdebrid: "Real-Debrid", megadebrid: "Mega-Debrid", bestdebrid: "BestDebrid", alldebrid: "AllDebrid", ddownload: "DDownload"
|
||||||
};
|
};
|
||||||
|
|
||||||
function formatDateTime(ts: number): string {
|
function formatDateTime(ts: number): string {
|
||||||
@ -115,15 +116,6 @@ function extractHoster(url: string): string {
|
|||||||
} catch { return ""; }
|
} catch { return ""; }
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatHoster(item: DownloadItem): string {
|
|
||||||
const hoster = extractHoster(item.url);
|
|
||||||
const label = hoster || "-";
|
|
||||||
if (item.provider) {
|
|
||||||
return `${label} via ${providerLabels[item.provider]}`;
|
|
||||||
}
|
|
||||||
return label;
|
|
||||||
}
|
|
||||||
|
|
||||||
const settingsSubTabs: { key: SettingsSubTab; label: string }[] = [
|
const settingsSubTabs: { key: SettingsSubTab; label: string }[] = [
|
||||||
{ key: "allgemein", label: "Allgemein" },
|
{ key: "allgemein", label: "Allgemein" },
|
||||||
{ key: "accounts", label: "Accounts" },
|
{ key: "accounts", label: "Accounts" },
|
||||||
@ -316,6 +308,7 @@ const BandwidthChart = memo(function BandwidthChart({ items, running, paused, sp
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleResize = () => {
|
const handleResize = () => {
|
||||||
|
if (animationFrameRef.current) cancelAnimationFrame(animationFrameRef.current);
|
||||||
animationFrameRef.current = requestAnimationFrame(drawChart);
|
animationFrameRef.current = requestAnimationFrame(drawChart);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -907,7 +900,7 @@ export function App(): ReactElement {
|
|||||||
return next;
|
return next;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [packages, snapshot.session.items]);
|
}, [packages, snapshot.session.items, collapsedPackages]);
|
||||||
|
|
||||||
const allPackagesCollapsed = useMemo(() => (
|
const allPackagesCollapsed = useMemo(() => (
|
||||||
packages.length > 0 && packages.every((pkg) => collapsedPackages[pkg.id])
|
packages.length > 0 && packages.every((pkg) => collapsedPackages[pkg.id])
|
||||||
@ -930,6 +923,15 @@ export function App(): ReactElement {
|
|||||||
return list;
|
return list;
|
||||||
}, [settingsDraft.token, settingsDraft.megaLogin, settingsDraft.megaPassword, settingsDraft.bestToken, settingsDraft.allDebridToken]);
|
}, [settingsDraft.token, settingsDraft.megaLogin, settingsDraft.megaPassword, settingsDraft.bestToken, settingsDraft.allDebridToken]);
|
||||||
|
|
||||||
|
// DDownload is a direct file hoster (not a debrid service) and is used automatically
|
||||||
|
// for ddownload.com/ddl.to URLs. It counts as a configured account but does not
|
||||||
|
// appear in the primary/secondary/tertiary provider dropdowns.
|
||||||
|
const hasDdownloadAccount = useMemo(() =>
|
||||||
|
Boolean((settingsDraft.ddownloadLogin || "").trim() && (settingsDraft.ddownloadPassword || "").trim()),
|
||||||
|
[settingsDraft.ddownloadLogin, settingsDraft.ddownloadPassword]);
|
||||||
|
|
||||||
|
const totalConfiguredAccounts = configuredProviders.length + (hasDdownloadAccount ? 1 : 0);
|
||||||
|
|
||||||
const primaryProviderValue: DebridProvider = useMemo(() => {
|
const primaryProviderValue: DebridProvider = useMemo(() => {
|
||||||
if (configuredProviders.includes(settingsDraft.providerPrimary)) {
|
if (configuredProviders.includes(settingsDraft.providerPrimary)) {
|
||||||
return settingsDraft.providerPrimary;
|
return settingsDraft.providerPrimary;
|
||||||
@ -989,10 +991,36 @@ export function App(): ReactElement {
|
|||||||
if (source === "manual") { showToast(`Kein Update verfügbar (v${result.currentVersion})`, 2000); }
|
if (source === "manual") { showToast(`Kein Update verfügbar (v${result.currentVersion})`, 2000); }
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
let changelogText = "";
|
||||||
|
if (result.releaseNotes) {
|
||||||
|
const lines = result.releaseNotes.split("\n");
|
||||||
|
const compactLines: string[] = [];
|
||||||
|
for (const line of lines) {
|
||||||
|
if (/^\s{2,}[-*]/.test(line)) continue;
|
||||||
|
if (/^#{1,6}\s/.test(line)) continue;
|
||||||
|
if (!line.trim()) continue;
|
||||||
|
let clean = line
|
||||||
|
.replace(/\*\*([^*]+)\*\*/g, "$1")
|
||||||
|
.replace(/\*([^*]+)\*/g, "$1")
|
||||||
|
.replace(/`([^`]+)`/g, "$1")
|
||||||
|
.replace(/^\s*[-*]\s+/, "- ")
|
||||||
|
.trim();
|
||||||
|
const colonIdx = clean.indexOf(":");
|
||||||
|
if (colonIdx > 0 && colonIdx < clean.length - 1) {
|
||||||
|
const afterColon = clean.slice(colonIdx + 1).trim();
|
||||||
|
if (afterColon.length > 60) {
|
||||||
|
clean = clean.slice(0, colonIdx + 1).trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (clean) compactLines.push(clean);
|
||||||
|
}
|
||||||
|
changelogText = compactLines.join("\n");
|
||||||
|
}
|
||||||
const approved = await askConfirmPrompt({
|
const approved = await askConfirmPrompt({
|
||||||
title: "Update verfügbar",
|
title: "Update verfügbar",
|
||||||
message: `${result.latestTag} (aktuell v${result.currentVersion})\n\nJetzt automatisch herunterladen und installieren?`,
|
message: `${result.latestTag} (aktuell v${result.currentVersion})\n\nJetzt automatisch herunterladen und installieren?`,
|
||||||
confirmLabel: "Jetzt installieren"
|
confirmLabel: "Jetzt installieren",
|
||||||
|
details: changelogText || undefined
|
||||||
});
|
});
|
||||||
if (!mountedRef.current) {
|
if (!mountedRef.current) {
|
||||||
return;
|
return;
|
||||||
@ -1103,7 +1131,7 @@ export function App(): ReactElement {
|
|||||||
|
|
||||||
const onStartDownloads = async (): Promise<void> => {
|
const onStartDownloads = async (): Promise<void> => {
|
||||||
await performQuickAction(async () => {
|
await performQuickAction(async () => {
|
||||||
if (configuredProviders.length === 0) {
|
if (totalConfiguredAccounts === 0) {
|
||||||
setTab("settings");
|
setTab("settings");
|
||||||
showToast("Bitte zuerst mindestens einen Hoster-Account eintragen", 3000);
|
showToast("Bitte zuerst mindestens einen Hoster-Account eintragen", 3000);
|
||||||
return;
|
return;
|
||||||
@ -1833,10 +1861,12 @@ export function App(): ReactElement {
|
|||||||
|
|
||||||
const executeDeleteSelection = useCallback((ids: Set<string>): void => {
|
const executeDeleteSelection = useCallback((ids: Set<string>): void => {
|
||||||
const current = snapshotRef.current;
|
const current = snapshotRef.current;
|
||||||
|
const promises: Promise<void>[] = [];
|
||||||
for (const id of ids) {
|
for (const id of ids) {
|
||||||
if (current.session.items[id]) void window.rd.removeItem(id);
|
if (current.session.items[id]) promises.push(window.rd.removeItem(id));
|
||||||
else if (current.session.packages[id]) void window.rd.cancelPackage(id);
|
else if (current.session.packages[id]) promises.push(window.rd.cancelPackage(id));
|
||||||
}
|
}
|
||||||
|
void Promise.all(promises).catch(() => {});
|
||||||
setSelectedIds(new Set());
|
setSelectedIds(new Set());
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@ -1855,7 +1885,7 @@ export function App(): ReactElement {
|
|||||||
const target = e.target as HTMLElement;
|
const target = e.target as HTMLElement;
|
||||||
if (target.tagName !== "INPUT" && target.tagName !== "TEXTAREA") {
|
if (target.tagName !== "INPUT" && target.tagName !== "TEXTAREA") {
|
||||||
// Don't clear selection if an overlay is open — let the overlay close first
|
// Don't clear selection if an overlay is open — let the overlay close first
|
||||||
if (document.querySelector(".ctx-menu") || document.querySelector(".modal-backdrop") || document.querySelector(".link-popup-overlay")) return;
|
if (document.querySelector(".ctx-menu") || document.querySelector(".modal-backdrop")) return;
|
||||||
if (tabRef.current === "downloads") setSelectedIds(new Set());
|
if (tabRef.current === "downloads") setSelectedIds(new Set());
|
||||||
else if (tabRef.current === "history") setSelectedHistoryIds(new Set());
|
else if (tabRef.current === "history") setSelectedHistoryIds(new Set());
|
||||||
}
|
}
|
||||||
@ -1879,28 +1909,28 @@ export function App(): ReactElement {
|
|||||||
|
|
||||||
const onExportBackup = async (): Promise<void> => {
|
const onExportBackup = async (): Promise<void> => {
|
||||||
closeMenus();
|
closeMenus();
|
||||||
try {
|
await performQuickAction(async () => {
|
||||||
const result = await window.rd.exportBackup();
|
const result = await window.rd.exportBackup();
|
||||||
if (result.saved) {
|
if (result.saved) {
|
||||||
showToast("Sicherung exportiert");
|
showToast("Sicherung exportiert");
|
||||||
}
|
}
|
||||||
} catch (error) {
|
}, (error) => {
|
||||||
showToast(`Sicherung fehlgeschlagen: ${String(error)}`, 2600);
|
showToast(`Sicherung fehlgeschlagen: ${String(error)}`, 2600);
|
||||||
}
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const onImportBackup = async (): Promise<void> => {
|
const onImportBackup = async (): Promise<void> => {
|
||||||
closeMenus();
|
closeMenus();
|
||||||
try {
|
await performQuickAction(async () => {
|
||||||
const result = await window.rd.importBackup();
|
const result = await window.rd.importBackup();
|
||||||
if (result.restored) {
|
if (result.restored) {
|
||||||
showToast(result.message, 4000);
|
showToast(result.message, 4000);
|
||||||
} else if (result.message !== "Abgebrochen") {
|
} else if (result.message !== "Abgebrochen") {
|
||||||
showToast(`Sicherung laden fehlgeschlagen: ${result.message}`, 3000);
|
showToast(`Sicherung laden fehlgeschlagen: ${result.message}`, 3000);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
}, (error) => {
|
||||||
showToast(`Sicherung laden fehlgeschlagen: ${String(error)}`, 2600);
|
showToast(`Sicherung laden fehlgeschlagen: ${String(error)}`, 2600);
|
||||||
}
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const onMenuRestart = (): void => {
|
const onMenuRestart = (): void => {
|
||||||
@ -2211,10 +2241,10 @@ export function App(): ReactElement {
|
|||||||
</button>
|
</button>
|
||||||
{openMenu === "hilfe" && (
|
{openMenu === "hilfe" && (
|
||||||
<div className="menu-dropdown">
|
<div className="menu-dropdown">
|
||||||
<button className="menu-dropdown-item" onClick={() => { closeMenus(); void window.rd.openLog(); }}>
|
<button className="menu-dropdown-item" onClick={() => { closeMenus(); void window.rd.openLog().catch(() => {}); }}>
|
||||||
<span>Log öffnen</span>
|
<span>Log öffnen</span>
|
||||||
</button>
|
</button>
|
||||||
<button className="menu-dropdown-item" onClick={() => { closeMenus(); void window.rd.openSessionLog(); }}>
|
<button className="menu-dropdown-item" onClick={() => { closeMenus(); void window.rd.openSessionLog().catch(() => {}); }}>
|
||||||
<span>Session-Log öffnen</span>
|
<span>Session-Log öffnen</span>
|
||||||
</button>
|
</button>
|
||||||
<button className="menu-dropdown-item" onClick={() => { closeMenus(); void onCheckUpdates(); }}>
|
<button className="menu-dropdown-item" onClick={() => { closeMenus(); void onCheckUpdates(); }}>
|
||||||
@ -2234,7 +2264,7 @@ export function App(): ReactElement {
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (snapshot.session.paused) {
|
if (snapshot.session.paused) {
|
||||||
setSnapshot((prev) => ({ ...prev, session: { ...prev.session, paused: false } }));
|
setSnapshot((prev) => ({ ...prev, session: { ...prev.session, paused: false } }));
|
||||||
void window.rd.togglePause();
|
void window.rd.togglePause().catch(() => {});
|
||||||
} else {
|
} else {
|
||||||
void onStartDownloads();
|
void onStartDownloads();
|
||||||
}
|
}
|
||||||
@ -2248,7 +2278,7 @@ export function App(): ReactElement {
|
|||||||
disabled={!snapshot.canPause || snapshot.session.paused}
|
disabled={!snapshot.canPause || snapshot.session.paused}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setSnapshot((prev) => ({ ...prev, session: { ...prev.session, paused: true } }));
|
setSnapshot((prev) => ({ ...prev, session: { ...prev.session, paused: true } }));
|
||||||
void window.rd.togglePause();
|
void window.rd.togglePause().catch(() => {});
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<svg viewBox="0 0 24 24" width="18" height="18"><rect x="5" y="3" width="4.5" height="18" rx="1" fill="currentColor" /><rect x="14.5" y="3" width="4.5" height="18" rx="1" fill="currentColor" /></svg>
|
<svg viewBox="0 0 24 24" width="18" height="18"><rect x="5" y="3" width="4.5" height="18" rx="1" fill="currentColor" /><rect x="14.5" y="3" width="4.5" height="18" rx="1" fill="currentColor" /></svg>
|
||||||
@ -2370,7 +2400,7 @@ export function App(): ReactElement {
|
|||||||
newOrder.splice(toIdx, 0, dragColId);
|
newOrder.splice(toIdx, 0, dragColId);
|
||||||
setColumnOrder(newOrder);
|
setColumnOrder(newOrder);
|
||||||
setDragColId(null);
|
setDragColId(null);
|
||||||
void window.rd.updateSettings({ columnOrder: newOrder });
|
void window.rd.updateSettings({ columnOrder: newOrder }).catch(() => {});
|
||||||
}}
|
}}
|
||||||
onDragEnd={() => { setDragColId(null); setDropTargetCol(null); }}
|
onDragEnd={() => { setDragColId(null); setDropTargetCol(null); }}
|
||||||
onClick={sortCol ? () => {
|
onClick={sortCol ? () => {
|
||||||
@ -2464,7 +2494,7 @@ export function App(): ReactElement {
|
|||||||
: `${historyEntries.length} Paket${historyEntries.length !== 1 ? "e" : ""} im Verlauf`}
|
: `${historyEntries.length} Paket${historyEntries.length !== 1 ? "e" : ""} im Verlauf`}
|
||||||
</span>
|
</span>
|
||||||
{selectedHistoryIds.size > 0 && (
|
{selectedHistoryIds.size > 0 && (
|
||||||
<button className="btn btn-danger" onClick={() => {
|
<button className="btn danger" onClick={() => {
|
||||||
const idSet = new Set(selectedHistoryIds);
|
const idSet = new Set(selectedHistoryIds);
|
||||||
void Promise.all([...idSet].map(id => window.rd.removeHistoryEntry(id))).then(() => {
|
void Promise.all([...idSet].map(id => window.rd.removeHistoryEntry(id))).then(() => {
|
||||||
setHistoryEntries((prev) => prev.filter((e) => !idSet.has(e.id)));
|
setHistoryEntries((prev) => prev.filter((e) => !idSet.has(e.id)));
|
||||||
@ -2475,7 +2505,7 @@ export function App(): ReactElement {
|
|||||||
}}>Ausgewählte entfernen ({selectedHistoryIds.size})</button>
|
}}>Ausgewählte entfernen ({selectedHistoryIds.size})</button>
|
||||||
)}
|
)}
|
||||||
{historyEntries.length > 0 && (
|
{historyEntries.length > 0 && (
|
||||||
<button className="btn btn-danger" onClick={() => { void window.rd.clearHistory().then(() => { setHistoryEntries([]); setSelectedHistoryIds(new Set()); }); }}>Verlauf leeren</button>
|
<button className="btn danger" onClick={() => { void window.rd.clearHistory().then(() => { setHistoryEntries([]); setSelectedHistoryIds(new Set()); }).catch(() => {}); }}>Verlauf leeren</button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{historyEntries.length === 0 && <div className="empty">Noch keine abgeschlossenen Pakete im Verlauf.</div>}
|
{historyEntries.length === 0 && <div className="empty">Noch keine abgeschlossenen Pakete im Verlauf.</div>}
|
||||||
@ -2562,7 +2592,7 @@ export function App(): ReactElement {
|
|||||||
<span>{entry.status === "completed" ? "Abgeschlossen" : "Gelöscht"}</span>
|
<span>{entry.status === "completed" ? "Abgeschlossen" : "Gelöscht"}</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="history-actions">
|
<div className="history-actions">
|
||||||
<button className="btn" onClick={() => { void window.rd.removeHistoryEntry(entry.id).then(() => { setHistoryEntries((prev) => prev.filter((e) => e.id !== entry.id)); setSelectedHistoryIds((prev) => { const n = new Set(prev); n.delete(entry.id); return n; }); }); }}>Eintrag entfernen</button>
|
<button className="btn" onClick={() => { void window.rd.removeHistoryEntry(entry.id).then(() => { setHistoryEntries((prev) => prev.filter((e) => e.id !== entry.id)); setSelectedHistoryIds((prev) => { const n = new Set(prev); n.delete(entry.id); return n; }); }).catch(() => {}); }}>Eintrag entfernen</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@ -2710,6 +2740,10 @@ export function App(): ReactElement {
|
|||||||
<input type="password" value={settingsDraft.bestToken} onChange={(e) => setText("bestToken", e.target.value)} />
|
<input type="password" value={settingsDraft.bestToken} onChange={(e) => setText("bestToken", e.target.value)} />
|
||||||
<label>AllDebrid API Key</label>
|
<label>AllDebrid API Key</label>
|
||||||
<input type="password" value={settingsDraft.allDebridToken} onChange={(e) => setText("allDebridToken", e.target.value)} />
|
<input type="password" value={settingsDraft.allDebridToken} onChange={(e) => setText("allDebridToken", e.target.value)} />
|
||||||
|
<label>DDownload Login</label>
|
||||||
|
<input value={settingsDraft.ddownloadLogin || ""} onChange={(e) => setText("ddownloadLogin", e.target.value)} />
|
||||||
|
<label>DDownload Passwort</label>
|
||||||
|
<input type="password" value={settingsDraft.ddownloadPassword || ""} onChange={(e) => setText("ddownloadPassword", e.target.value)} />
|
||||||
{configuredProviders.length === 0 && (
|
{configuredProviders.length === 0 && (
|
||||||
<div className="hint">Füge mindestens einen Account hinzu, dann erscheint die Hoster-Auswahl.</div>
|
<div className="hint">Füge mindestens einen Account hinzu, dann erscheint die Hoster-Auswahl.</div>
|
||||||
)}
|
)}
|
||||||
@ -2847,6 +2881,12 @@ export function App(): ReactElement {
|
|||||||
<div className="modal-card" onClick={(event) => event.stopPropagation()}>
|
<div className="modal-card" onClick={(event) => event.stopPropagation()}>
|
||||||
<h3>{confirmPrompt.title}</h3>
|
<h3>{confirmPrompt.title}</h3>
|
||||||
<p style={{ whiteSpace: "pre-line" }}>{confirmPrompt.message}</p>
|
<p style={{ whiteSpace: "pre-line" }}>{confirmPrompt.message}</p>
|
||||||
|
{confirmPrompt.details && (
|
||||||
|
<details className="modal-details">
|
||||||
|
<summary>Changelog anzeigen</summary>
|
||||||
|
<pre>{confirmPrompt.details}</pre>
|
||||||
|
</details>
|
||||||
|
)}
|
||||||
<div className="modal-actions">
|
<div className="modal-actions">
|
||||||
<button className="btn" onClick={() => closeConfirmPrompt(false)}>Abbrechen</button>
|
<button className="btn" onClick={() => closeConfirmPrompt(false)}>Abbrechen</button>
|
||||||
<button
|
<button
|
||||||
@ -2869,7 +2909,7 @@ export function App(): ReactElement {
|
|||||||
const pkg = snapshot.session.packages[id];
|
const pkg = snapshot.session.packages[id];
|
||||||
if (pkg) { for (const iid of pkg.itemIds) removedItemIds.add(iid); }
|
if (pkg) { for (const iid of pkg.itemIds) removedItemIds.add(iid); }
|
||||||
}
|
}
|
||||||
const totalRemaining = Object.keys(snapshot.session.items).length - removedItemIds.size;
|
const totalRemaining = Math.max(0, Object.keys(snapshot.session.items).length - removedItemIds.size);
|
||||||
const parts: string[] = [];
|
const parts: string[] = [];
|
||||||
if (pkgCount > 0) parts.push(`${pkgCount} Paket(e)`);
|
if (pkgCount > 0) parts.push(`${pkgCount} Paket(e)`);
|
||||||
if (itemCount > 0) parts.push(`${itemCount} Link(s)`);
|
if (itemCount > 0) parts.push(`${itemCount} Link(s)`);
|
||||||
@ -2943,7 +2983,7 @@ export function App(): ReactElement {
|
|||||||
<span>Links: {Object.keys(snapshot.session.items).length}</span>
|
<span>Links: {Object.keys(snapshot.session.items).length}</span>
|
||||||
<span>Session: {humanSize(snapshot.stats.totalDownloaded)}</span>
|
<span>Session: {humanSize(snapshot.stats.totalDownloaded)}</span>
|
||||||
<span>Gesamt: {humanSize(snapshot.stats.totalDownloadedAllTime)}</span>
|
<span>Gesamt: {humanSize(snapshot.stats.totalDownloadedAllTime)}</span>
|
||||||
<span>Hoster: {configuredProviders.length}</span>
|
<span>Hoster: {totalConfiguredAccounts}</span>
|
||||||
<span>{snapshot.speedText}</span>
|
<span>{snapshot.speedText}</span>
|
||||||
<span>{snapshot.etaText}</span>
|
<span>{snapshot.etaText}</span>
|
||||||
<span className="footer-spacer" />
|
<span className="footer-spacer" />
|
||||||
@ -3003,18 +3043,18 @@ export function App(): ReactElement {
|
|||||||
<button className="ctx-menu-item" onClick={() => {
|
<button className="ctx-menu-item" onClick={() => {
|
||||||
const pkgIds = [...selectedIds].filter((id) => snapshot.session.packages[id]);
|
const pkgIds = [...selectedIds].filter((id) => snapshot.session.packages[id]);
|
||||||
const itemIds = [...selectedIds].filter((id) => { const it = snapshot.session.items[id]; return it && startableStatuses.has(it.status); });
|
const itemIds = [...selectedIds].filter((id) => { const it = snapshot.session.items[id]; return it && startableStatuses.has(it.status); });
|
||||||
if (pkgIds.length > 0) void window.rd.startPackages(pkgIds);
|
if (pkgIds.length > 0) void window.rd.startPackages(pkgIds).catch(() => {});
|
||||||
if (itemIds.length > 0) void window.rd.startItems(itemIds);
|
if (itemIds.length > 0) void window.rd.startItems(itemIds).catch(() => {});
|
||||||
setContextMenu(null);
|
setContextMenu(null);
|
||||||
}}>Ausgewählte Downloads starten{multi ? ` (${selectedIds.size})` : ""}</button>
|
}}>Ausgewählte Downloads starten{multi ? ` (${selectedIds.size})` : ""}</button>
|
||||||
)}
|
)}
|
||||||
<button className="ctx-menu-item" onClick={() => { void window.rd.start(); setContextMenu(null); }}>Alle Downloads starten</button>
|
<button className="ctx-menu-item" onClick={() => { void window.rd.start().catch(() => {}); setContextMenu(null); }}>Alle Downloads starten</button>
|
||||||
<div className="ctx-menu-sep" />
|
<div className="ctx-menu-sep" />
|
||||||
<button className="ctx-menu-item" onClick={() => showLinksPopup(contextMenu.packageId, contextMenu.itemId)}>Linkadressen anzeigen</button>
|
<button className="ctx-menu-item" onClick={() => showLinksPopup(contextMenu.packageId, contextMenu.itemId)}>Linkadressen anzeigen</button>
|
||||||
<div className="ctx-menu-sep" />
|
<div className="ctx-menu-sep" />
|
||||||
{hasPackages && !contextMenu.itemId && (
|
{hasPackages && !contextMenu.itemId && (
|
||||||
<button className="ctx-menu-item" onClick={() => {
|
<button className="ctx-menu-item" onClick={() => {
|
||||||
for (const id of selectedIds) { if (snapshot.session.packages[id]) void window.rd.togglePackage(id); }
|
for (const id of selectedIds) { if (snapshot.session.packages[id]) void window.rd.togglePackage(id).catch(() => {}); }
|
||||||
setContextMenu(null);
|
setContextMenu(null);
|
||||||
}}>
|
}}>
|
||||||
{multi ? `Alle ${selectedIds.size} umschalten` : (snapshot.session.packages[contextMenu.packageId]?.enabled ? "Deaktivieren" : "Aktivieren")}
|
{multi ? `Alle ${selectedIds.size} umschalten` : (snapshot.session.packages[contextMenu.packageId]?.enabled ? "Deaktivieren" : "Aktivieren")}
|
||||||
@ -3039,7 +3079,7 @@ export function App(): ReactElement {
|
|||||||
{hasPackages && !contextMenu.itemId && (
|
{hasPackages && !contextMenu.itemId && (
|
||||||
<button className="ctx-menu-item" onClick={() => {
|
<button className="ctx-menu-item" onClick={() => {
|
||||||
const pkgIds = [...selectedIds].filter((id) => snapshot.session.packages[id]);
|
const pkgIds = [...selectedIds].filter((id) => snapshot.session.packages[id]);
|
||||||
for (const id of pkgIds) void window.rd.resetPackage(id);
|
for (const id of pkgIds) void window.rd.resetPackage(id).catch(() => {});
|
||||||
setContextMenu(null);
|
setContextMenu(null);
|
||||||
}}>Zurücksetzen{multi ? ` (${[...selectedIds].filter((id) => snapshot.session.packages[id]).length})` : ""}</button>
|
}}>Zurücksetzen{multi ? ` (${[...selectedIds].filter((id) => snapshot.session.packages[id]).length})` : ""}</button>
|
||||||
)}
|
)}
|
||||||
@ -3048,7 +3088,7 @@ export function App(): ReactElement {
|
|||||||
const itemIds = multi
|
const itemIds = multi
|
||||||
? [...selectedIds].filter((id) => snapshot.session.items[id])
|
? [...selectedIds].filter((id) => snapshot.session.items[id])
|
||||||
: [contextMenu.itemId!];
|
: [contextMenu.itemId!];
|
||||||
void window.rd.resetItems(itemIds);
|
void window.rd.resetItems(itemIds).catch(() => {});
|
||||||
setContextMenu(null);
|
setContextMenu(null);
|
||||||
}}>Zurücksetzen{multi ? ` (${[...selectedIds].filter((id) => snapshot.session.items[id]).length})` : ""}</button>
|
}}>Zurücksetzen{multi ? ` (${[...selectedIds].filter((id) => snapshot.session.items[id]).length})` : ""}</button>
|
||||||
)}
|
)}
|
||||||
@ -3058,7 +3098,7 @@ export function App(): ReactElement {
|
|||||||
const someCompleted = items.some((item) => item && item.status === "completed");
|
const someCompleted = items.some((item) => item && item.status === "completed");
|
||||||
return (<>
|
return (<>
|
||||||
{someCompleted && (
|
{someCompleted && (
|
||||||
<button className="ctx-menu-item" onClick={() => { void window.rd.extractNow(contextMenu.packageId); setContextMenu(null); }}>Jetzt entpacken</button>
|
<button className="ctx-menu-item" onClick={() => { void window.rd.extractNow(contextMenu.packageId).catch(() => {}); setContextMenu(null); }}>Jetzt entpacken</button>
|
||||||
)}
|
)}
|
||||||
</>);
|
</>);
|
||||||
})()}
|
})()}
|
||||||
@ -3071,7 +3111,7 @@ export function App(): ReactElement {
|
|||||||
const label = p === "high" ? "Hoch" : p === "low" ? "Niedrig" : "Standard";
|
const label = p === "high" ? "Hoch" : p === "low" ? "Niedrig" : "Standard";
|
||||||
const pkgIds = [...selectedIds].filter((id) => snapshot.session.packages[id]);
|
const pkgIds = [...selectedIds].filter((id) => snapshot.session.packages[id]);
|
||||||
const allMatch = pkgIds.every((id) => (snapshot.session.packages[id]?.priority || "normal") === p);
|
const allMatch = pkgIds.every((id) => (snapshot.session.packages[id]?.priority || "normal") === p);
|
||||||
return <button key={p} className={`ctx-menu-item${allMatch ? " ctx-menu-active" : ""}`} onClick={() => { for (const id of pkgIds) void window.rd.setPackagePriority(id, p); setContextMenu(null); }}>{allMatch ? `✓ ${label}` : label}</button>;
|
return <button key={p} className={`ctx-menu-item${allMatch ? " ctx-menu-active" : ""}`} onClick={() => { for (const id of pkgIds) void window.rd.setPackagePriority(id, p).catch(() => {}); setContextMenu(null); }}>{allMatch ? `✓ ${label}` : label}</button>;
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -3080,7 +3120,7 @@ export function App(): ReactElement {
|
|||||||
const itemIds = [...selectedIds].filter((id) => snapshot.session.items[id]);
|
const itemIds = [...selectedIds].filter((id) => snapshot.session.items[id]);
|
||||||
const skippable = itemIds.filter((id) => { const it = snapshot.session.items[id]; return it && (it.status === "queued" || it.status === "reconnect_wait"); });
|
const skippable = itemIds.filter((id) => { const it = snapshot.session.items[id]; return it && (it.status === "queued" || it.status === "reconnect_wait"); });
|
||||||
if (skippable.length === 0) return null;
|
if (skippable.length === 0) return null;
|
||||||
return <button className="ctx-menu-item" onClick={() => { void window.rd.skipItems(skippable); setContextMenu(null); }}>Überspringen{skippable.length > 1 ? ` (${skippable.length})` : ""}</button>;
|
return <button className="ctx-menu-item" onClick={() => { void window.rd.skipItems(skippable).catch(() => {}); setContextMenu(null); }}>Überspringen{skippable.length > 1 ? ` (${skippable.length})` : ""}</button>;
|
||||||
})()}
|
})()}
|
||||||
{hasPackages && (
|
{hasPackages && (
|
||||||
<button className="ctx-menu-item ctx-danger" onClick={() => {
|
<button className="ctx-menu-item ctx-danger" onClick={() => {
|
||||||
@ -3124,7 +3164,7 @@ export function App(): ReactElement {
|
|||||||
newOrder.splice(insertAt, 0, col);
|
newOrder.splice(insertAt, 0, col);
|
||||||
}
|
}
|
||||||
setColumnOrder(newOrder);
|
setColumnOrder(newOrder);
|
||||||
void window.rd.updateSettings({ columnOrder: newOrder });
|
void window.rd.updateSettings({ columnOrder: newOrder }).catch(() => {});
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{isVisible ? "\u2713 " : "\u2003 "}{def.label}
|
{isVisible ? "\u2713 " : "\u2003 "}{def.label}
|
||||||
@ -3165,7 +3205,7 @@ export function App(): ReactElement {
|
|||||||
)}
|
)}
|
||||||
<div className="ctx-menu-sep" />
|
<div className="ctx-menu-sep" />
|
||||||
<button className="ctx-menu-item ctx-danger" onClick={() => {
|
<button className="ctx-menu-item ctx-danger" onClick={() => {
|
||||||
void window.rd.clearHistory().then(() => { setHistoryEntries([]); setSelectedHistoryIds(new Set()); });
|
void window.rd.clearHistory().then(() => { setHistoryEntries([]); setSelectedHistoryIds(new Set()); }).catch(() => {});
|
||||||
setHistoryCtxMenu(null);
|
setHistoryCtxMenu(null);
|
||||||
}}>Verlauf leeren</button>
|
}}>Verlauf leeren</button>
|
||||||
</div>
|
</div>
|
||||||
@ -3179,8 +3219,8 @@ export function App(): ReactElement {
|
|||||||
<div className="link-popup-list">
|
<div className="link-popup-list">
|
||||||
{linkPopup.links.map((link, i) => (
|
{linkPopup.links.map((link, i) => (
|
||||||
<div key={i} className="link-popup-row">
|
<div key={i} className="link-popup-row">
|
||||||
<span className="link-popup-name link-popup-click" title={`${link.name}\nKlicken zum Kopieren`} onClick={() => { void navigator.clipboard.writeText(link.name); showToast("Name kopiert"); }}>{link.name}</span>
|
<span className="link-popup-name link-popup-click" title={`${link.name}\nKlicken zum Kopieren`} onClick={() => { void navigator.clipboard.writeText(link.name).then(() => showToast("Name kopiert")).catch(() => showToast("Kopieren fehlgeschlagen")); }}>{link.name}</span>
|
||||||
<span className="link-popup-url link-popup-click" title={`${link.url}\nKlicken zum Kopieren`} onClick={() => { void navigator.clipboard.writeText(link.url); showToast("Link kopiert"); }}>{link.url}</span>
|
<span className="link-popup-url link-popup-click" title={`${link.url}\nKlicken zum Kopieren`} onClick={() => { void navigator.clipboard.writeText(link.url).then(() => showToast("Link kopiert")).catch(() => showToast("Kopieren fehlgeschlagen")); }}>{link.url}</span>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
@ -3188,15 +3228,13 @@ export function App(): ReactElement {
|
|||||||
{linkPopup.isPackage && (
|
{linkPopup.isPackage && (
|
||||||
<button className="btn" onClick={() => {
|
<button className="btn" onClick={() => {
|
||||||
const text = linkPopup.links.map((l) => l.name).join("\n");
|
const text = linkPopup.links.map((l) => l.name).join("\n");
|
||||||
void navigator.clipboard.writeText(text);
|
void navigator.clipboard.writeText(text).then(() => showToast("Alle Namen kopiert")).catch(() => showToast("Kopieren fehlgeschlagen"));
|
||||||
showToast("Alle Namen kopiert");
|
|
||||||
}}>Alle Namen kopieren</button>
|
}}>Alle Namen kopieren</button>
|
||||||
)}
|
)}
|
||||||
{linkPopup.isPackage && (
|
{linkPopup.isPackage && (
|
||||||
<button className="btn" onClick={() => {
|
<button className="btn" onClick={() => {
|
||||||
const text = linkPopup.links.map((l) => l.url).join("\n");
|
const text = linkPopup.links.map((l) => l.url).join("\n");
|
||||||
void navigator.clipboard.writeText(text);
|
void navigator.clipboard.writeText(text).then(() => showToast("Alle Links kopiert")).catch(() => showToast("Kopieren fehlgeschlagen"));
|
||||||
showToast("Alle Links kopiert");
|
|
||||||
}}>Alle Links kopieren</button>
|
}}>Alle Links kopieren</button>
|
||||||
)}
|
)}
|
||||||
<button className="btn" onClick={() => setLinkPopup(null)}>Schließen</button>
|
<button className="btn" onClick={() => setLinkPopup(null)}>Schließen</button>
|
||||||
@ -3257,7 +3295,7 @@ const PackageCard = memo(function PackageCard({ pkg, items, packageSpeed, isFirs
|
|||||||
}
|
}
|
||||||
return sum;
|
return sum;
|
||||||
}, 0);
|
}, 0);
|
||||||
const dlProgress = Math.floor(((done + activeProgress) / total) * (useExtractSplit ? 50 : 100));
|
const dlProgress = Math.min(useExtractSplit ? 50 : 100, Math.floor(((done + activeProgress) / total) * (useExtractSplit ? 50 : 100)));
|
||||||
// Include fractional progress from items currently being extracted
|
// Include fractional progress from items currently being extracted
|
||||||
const extractingProgress = items.reduce((sum, item) => {
|
const extractingProgress = items.reduce((sum, item) => {
|
||||||
const fs = item.fullStatus || "";
|
const fs = item.fullStatus || "";
|
||||||
@ -3266,8 +3304,8 @@ const PackageCard = memo(function PackageCard({ pkg, items, packageSpeed, isFirs
|
|||||||
if (m) return sum + Number(m[1]) / 100;
|
if (m) return sum + Number(m[1]) / 100;
|
||||||
return sum;
|
return sum;
|
||||||
}, 0);
|
}, 0);
|
||||||
const exProgress = Math.floor(((extracted + extractingProgress) / total) * 50);
|
const exProgress = Math.min(50, Math.floor(((extracted + extractingProgress) / total) * 50));
|
||||||
const combinedProgress = useExtractSplit ? dlProgress + exProgress : dlProgress;
|
const combinedProgress = Math.min(100, useExtractSplit ? dlProgress + exProgress : dlProgress);
|
||||||
|
|
||||||
const onKeyDown = (e: KeyboardEvent<HTMLInputElement>): void => {
|
const onKeyDown = (e: KeyboardEvent<HTMLInputElement>): void => {
|
||||||
if (e.key === "Enter") { onFinishEdit(pkg.id, pkg.name, editingName); }
|
if (e.key === "Enter") { onFinishEdit(pkg.id, pkg.name, editingName); }
|
||||||
@ -3331,29 +3369,19 @@ const PackageCard = memo(function PackageCard({ pkg, items, packageSpeed, isFirs
|
|||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
case "hoster": return (
|
case "hoster": {
|
||||||
<span key={col} className="pkg-col pkg-col-hoster" title={(() => {
|
const hosterText = [...new Set(items.map((item) => extractHoster(item.url)).filter(Boolean))].join(", ");
|
||||||
const hosters = [...new Set(items.map((item) => extractHoster(item.url)).filter(Boolean))];
|
return <span key={col} className="pkg-col pkg-col-hoster" title={hosterText}>{hosterText}</span>;
|
||||||
return hosters.join(", ");
|
}
|
||||||
})()}>{(() => {
|
case "account": {
|
||||||
const hosters = [...new Set(items.map((item) => extractHoster(item.url)).filter(Boolean))];
|
const accountText = [...new Set(items.map((item) => item.provider).filter(Boolean))].map((p) => providerLabels[p!] || p).join(", ");
|
||||||
return hosters.length > 0 ? hosters.join(", ") : "";
|
return <span key={col} className="pkg-col pkg-col-account" title={accountText}>{accountText}</span>;
|
||||||
})()}</span>
|
}
|
||||||
);
|
|
||||||
case "account": return (
|
|
||||||
<span key={col} className="pkg-col pkg-col-account" title={(() => {
|
|
||||||
const providers = [...new Set(items.map((item) => item.provider).filter(Boolean))];
|
|
||||||
return providers.map((p) => providerLabels[p!] || p).join(", ");
|
|
||||||
})()}>{(() => {
|
|
||||||
const providers = [...new Set(items.map((item) => item.provider).filter(Boolean))];
|
|
||||||
return providers.length > 0 ? providers.map((p) => providerLabels[p!] || p).join(", ") : "";
|
|
||||||
})()}</span>
|
|
||||||
);
|
|
||||||
case "prio": return (
|
case "prio": return (
|
||||||
<span key={col} className={`pkg-col pkg-col-prio${pkg.priority === "high" ? " prio-high" : pkg.priority === "low" ? " prio-low" : ""}`}>{pkg.priority === "high" ? "Hoch" : pkg.priority === "low" ? "Niedrig" : ""}</span>
|
<span key={col} className={`pkg-col pkg-col-prio${pkg.priority === "high" ? " prio-high" : pkg.priority === "low" ? " prio-low" : ""}`}>{pkg.priority === "high" ? "Hoch" : pkg.priority === "low" ? "Niedrig" : ""}</span>
|
||||||
);
|
);
|
||||||
case "status": return (
|
case "status": return (
|
||||||
<span key={col} className="pkg-col pkg-col-status">[{done}/{total}{done === total && total > 0 ? " - Done" : ""}{failed > 0 ? ` · ${failed} Fehler` : ""}{cancelled > 0 ? ` · ${cancelled} abgebr.` : ""}]</span>
|
<span key={col} className="pkg-col pkg-col-status">[{done}/{total}{done === total && total > 0 ? " - Done" : ""}{failed > 0 ? ` · ${failed} Fehler` : ""}{cancelled > 0 ? ` · ${cancelled} abgebr.` : ""}]{pkg.postProcessLabel ? ` - ${pkg.postProcessLabel}` : ""}</span>
|
||||||
);
|
);
|
||||||
case "speed": return (
|
case "speed": return (
|
||||||
<span key={col} className="pkg-col pkg-col-speed">{packageSpeed > 0 ? formatSpeedMbps(packageSpeed) : ""}</span>
|
<span key={col} className="pkg-col pkg-col-speed">{packageSpeed > 0 ? formatSpeedMbps(packageSpeed) : ""}</span>
|
||||||
@ -3406,7 +3434,7 @@ const PackageCard = memo(function PackageCard({ pkg, items, packageSpeed, isFirs
|
|||||||
) : ""}
|
) : ""}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
case "hoster": return <span key={col} className="pkg-col pkg-col-hoster" title={extractHoster(item.url)}>{extractHoster(item.url) || ""}</span>;
|
case "hoster": { const h = extractHoster(item.url) || ""; return <span key={col} className="pkg-col pkg-col-hoster" title={h}>{h}</span>; }
|
||||||
case "account": return <span key={col} className="pkg-col pkg-col-account">{item.provider ? providerLabels[item.provider] : ""}</span>;
|
case "account": return <span key={col} className="pkg-col pkg-col-account">{item.provider ? providerLabels[item.provider] : ""}</span>;
|
||||||
case "prio": return <span key={col} className="pkg-col pkg-col-prio"></span>;
|
case "prio": return <span key={col} className="pkg-col pkg-col-prio"></span>;
|
||||||
case "status": return (
|
case "status": return (
|
||||||
|
|||||||
25
src/renderer/package-order.ts
Normal file
25
src/renderer/package-order.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import type { PackageEntry } from "../shared/types";
|
||||||
|
|
||||||
|
export function reorderPackageOrderByDrop(order: string[], draggedPackageId: string, targetPackageId: string): string[] {
|
||||||
|
const fromIndex = order.indexOf(draggedPackageId);
|
||||||
|
const toIndex = order.indexOf(targetPackageId);
|
||||||
|
if (fromIndex < 0 || toIndex < 0 || fromIndex === toIndex) {
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
const next = [...order];
|
||||||
|
const [dragged] = next.splice(fromIndex, 1);
|
||||||
|
const insertIndex = Math.max(0, Math.min(next.length, toIndex));
|
||||||
|
next.splice(insertIndex, 0, dragged);
|
||||||
|
return next;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sortPackageOrderByName(order: string[], packages: Record<string, PackageEntry>, descending: boolean): string[] {
|
||||||
|
const sorted = [...order];
|
||||||
|
sorted.sort((a, b) => {
|
||||||
|
const nameA = (packages[a]?.name ?? "").toLowerCase();
|
||||||
|
const nameB = (packages[b]?.name ?? "").toLowerCase();
|
||||||
|
const cmp = nameA.localeCompare(nameB, undefined, { numeric: true, sensitivity: "base" });
|
||||||
|
return descending ? -cmp : cmp;
|
||||||
|
});
|
||||||
|
return sorted;
|
||||||
|
}
|
||||||
@ -1639,6 +1639,7 @@ td {
|
|||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
padding: 10px 14px;
|
padding: 10px 14px;
|
||||||
box-shadow: 0 16px 30px rgba(0, 0, 0, 0.35);
|
box-shadow: 0 16px 30px rgba(0, 0, 0, 0.35);
|
||||||
|
z-index: 50;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ctx-menu {
|
.ctx-menu {
|
||||||
@ -1763,6 +1764,8 @@ td {
|
|||||||
|
|
||||||
.modal-card {
|
.modal-card {
|
||||||
width: min(560px, 100%);
|
width: min(560px, 100%);
|
||||||
|
max-height: calc(100vh - 40px);
|
||||||
|
overflow-y: auto;
|
||||||
border: 1px solid var(--border);
|
border: 1px solid var(--border);
|
||||||
border-radius: 14px;
|
border-radius: 14px;
|
||||||
background: linear-gradient(180deg, color-mix(in srgb, var(--card) 98%, transparent), color-mix(in srgb, var(--surface) 98%, transparent));
|
background: linear-gradient(180deg, color-mix(in srgb, var(--card) 98%, transparent), color-mix(in srgb, var(--surface) 98%, transparent));
|
||||||
@ -1781,6 +1784,34 @@ td {
|
|||||||
color: var(--muted);
|
color: var(--muted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.modal-details {
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
.modal-details summary {
|
||||||
|
padding: 6px 10px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 13px;
|
||||||
|
color: var(--muted);
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
.modal-details summary:hover {
|
||||||
|
color: var(--text);
|
||||||
|
}
|
||||||
|
.modal-details pre {
|
||||||
|
margin: 0;
|
||||||
|
padding: 8px 10px;
|
||||||
|
border-top: 1px solid var(--border);
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.5;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
word-break: break-word;
|
||||||
|
max-height: 260px;
|
||||||
|
overflow-y: auto;
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
|
||||||
.modal-path {
|
.modal-path {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
word-break: break-all;
|
word-break: break-all;
|
||||||
|
|||||||
@ -14,7 +14,7 @@ export type CleanupMode = "none" | "trash" | "delete";
|
|||||||
export type ConflictMode = "overwrite" | "skip" | "rename" | "ask";
|
export type ConflictMode = "overwrite" | "skip" | "rename" | "ask";
|
||||||
export type SpeedMode = "global" | "per_download";
|
export type SpeedMode = "global" | "per_download";
|
||||||
export type FinishedCleanupPolicy = "never" | "immediate" | "on_start" | "package_done";
|
export type FinishedCleanupPolicy = "never" | "immediate" | "on_start" | "package_done";
|
||||||
export type DebridProvider = "realdebrid" | "megadebrid" | "bestdebrid" | "alldebrid";
|
export type DebridProvider = "realdebrid" | "megadebrid" | "bestdebrid" | "alldebrid" | "ddownload";
|
||||||
export type DebridFallbackProvider = DebridProvider | "none";
|
export type DebridFallbackProvider = DebridProvider | "none";
|
||||||
export type AppTheme = "dark" | "light";
|
export type AppTheme = "dark" | "light";
|
||||||
export type PackagePriority = "high" | "normal" | "low";
|
export type PackagePriority = "high" | "normal" | "low";
|
||||||
@ -42,6 +42,8 @@ export interface AppSettings {
|
|||||||
megaPassword: string;
|
megaPassword: string;
|
||||||
bestToken: string;
|
bestToken: string;
|
||||||
allDebridToken: string;
|
allDebridToken: string;
|
||||||
|
ddownloadLogin: string;
|
||||||
|
ddownloadPassword: string;
|
||||||
archivePasswordList: string;
|
archivePasswordList: string;
|
||||||
rememberToken: boolean;
|
rememberToken: boolean;
|
||||||
providerPrimary: DebridProvider;
|
providerPrimary: DebridProvider;
|
||||||
@ -119,6 +121,7 @@ export interface PackageEntry {
|
|||||||
cancelled: boolean;
|
cancelled: boolean;
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
priority: PackagePriority;
|
priority: PackagePriority;
|
||||||
|
postProcessLabel?: string;
|
||||||
createdAt: number;
|
createdAt: number;
|
||||||
updatedAt: number;
|
updatedAt: number;
|
||||||
}
|
}
|
||||||
@ -219,6 +222,7 @@ export interface UpdateCheckResult {
|
|||||||
setupAssetUrl?: string;
|
setupAssetUrl?: string;
|
||||||
setupAssetName?: string;
|
setupAssetName?: string;
|
||||||
setupAssetDigest?: string;
|
setupAssetDigest?: string;
|
||||||
|
releaseNotes?: string;
|
||||||
error?: string;
|
error?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -269,6 +269,7 @@ describe("buildAutoRenameBaseName", () => {
|
|||||||
const result = buildAutoRenameBaseName("Show.S99.720p-4sf", "show.s99e999.720p.mkv");
|
const result = buildAutoRenameBaseName("Show.S99.720p-4sf", "show.s99e999.720p.mkv");
|
||||||
// SCENE_EPISODE_RE allows up to 3-digit episodes and 2-digit seasons
|
// SCENE_EPISODE_RE allows up to 3-digit episodes and 2-digit seasons
|
||||||
expect(result).not.toBeNull();
|
expect(result).not.toBeNull();
|
||||||
|
expect(result!).toContain("S99E999");
|
||||||
});
|
});
|
||||||
|
|
||||||
// Real-world scene release patterns
|
// Real-world scene release patterns
|
||||||
@ -343,6 +344,7 @@ describe("buildAutoRenameBaseName", () => {
|
|||||||
const result = buildAutoRenameBaseName("Show.S01-4sf", "show.s01e01.mkv");
|
const result = buildAutoRenameBaseName("Show.S01-4sf", "show.s01e01.mkv");
|
||||||
// "mkv" should not be treated as part of the filename match
|
// "mkv" should not be treated as part of the filename match
|
||||||
expect(result).not.toBeNull();
|
expect(result).not.toBeNull();
|
||||||
|
expect(result!).toContain("S01E01");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not match episode-like patterns in codec strings", () => {
|
it("does not match episode-like patterns in codec strings", () => {
|
||||||
@ -373,6 +375,7 @@ describe("buildAutoRenameBaseName", () => {
|
|||||||
// Extreme edge case - sanitizeFilename trims leading dots
|
// Extreme edge case - sanitizeFilename trims leading dots
|
||||||
expect(result).not.toBeNull();
|
expect(result).not.toBeNull();
|
||||||
expect(result!).toContain("S01E01");
|
expect(result!).toContain("S01E01");
|
||||||
|
expect(result!).toContain("-4sf");
|
||||||
expect(result!).not.toContain(".S01E01.S01E01"); // no duplication
|
expect(result!).not.toContain(".S01E01.S01E01"); // no duplication
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -670,4 +673,22 @@ describe("buildAutoRenameBaseNameFromFolders", () => {
|
|||||||
);
|
);
|
||||||
expect(result).toBe("Riviera.S02E02.GERMAN.DUBBED.DL.720p.WebHD.x264-TVP");
|
expect(result).toBe("Riviera.S02E02.GERMAN.DUBBED.DL.720p.WebHD.x264-TVP");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("renames Room 104 abbreviated source r104.de.dl.web.7p-s04e02", () => {
|
||||||
|
const result = buildAutoRenameBaseNameFromFoldersWithOptions(
|
||||||
|
["Room.104.S04.GERMAN.DL.720p.WEBRiP.x264-LAW"],
|
||||||
|
"r104.de.dl.web.7p-s04e02",
|
||||||
|
{ forceEpisodeForSeasonFolder: true }
|
||||||
|
);
|
||||||
|
expect(result).toBe("Room.104.S04E02.GERMAN.DL.720p.WEBRiP.x264-LAW");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("renames Room 104 wayne source with episode", () => {
|
||||||
|
const result = buildAutoRenameBaseNameFromFoldersWithOptions(
|
||||||
|
["Room.104.S04.GERMAN.DL.720p.WEBRiP.x264-LAW"],
|
||||||
|
"room.104.s04e01.german.dl.720p.web.h264-wayne",
|
||||||
|
{ forceEpisodeForSeasonFolder: true }
|
||||||
|
);
|
||||||
|
expect(result).toBe("Room.104.S04E01.GERMAN.DL.720p.WEBRiP.x264-LAW");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -317,7 +317,7 @@ describe("debrid service", () => {
|
|||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
const abortTimer = setTimeout(() => {
|
const abortTimer = setTimeout(() => {
|
||||||
controller.abort("test");
|
controller.abort("test");
|
||||||
}, 25);
|
}, 200);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await expect(service.unrestrictLink("https://rapidgator.net/file/abort-mega-web", controller.signal)).rejects.toThrow(/aborted/i);
|
await expect(service.unrestrictLink("https://rapidgator.net/file/abort-mega-web", controller.signal)).rejects.toThrow(/aborted/i);
|
||||||
|
|||||||
@ -36,12 +36,8 @@ afterEach(() => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("extractor jvm backend", () => {
|
describe.skipIf(!hasJavaRuntime() || !hasJvmExtractorRuntime())("extractor jvm backend", () => {
|
||||||
it("extracts zip archives through SevenZipJBinding backend", async () => {
|
it("extracts zip archives through SevenZipJBinding backend", async () => {
|
||||||
if (!hasJavaRuntime() || !hasJvmExtractorRuntime()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
process.env.RD_EXTRACT_BACKEND = "jvm";
|
process.env.RD_EXTRACT_BACKEND = "jvm";
|
||||||
|
|
||||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), "rd-jvm-extract-"));
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), "rd-jvm-extract-"));
|
||||||
@ -69,11 +65,112 @@ describe("extractor jvm backend", () => {
|
|||||||
expect(fs.existsSync(path.join(targetDir, "episode.txt"))).toBe(true);
|
expect(fs.existsSync(path.join(targetDir, "episode.txt"))).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("respects ask/skip conflict mode in jvm backend", async () => {
|
it("emits progress callbacks with archiveName and percent", async () => {
|
||||||
if (!hasJavaRuntime() || !hasJvmExtractorRuntime()) {
|
process.env.RD_EXTRACT_BACKEND = "jvm";
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), "rd-jvm-progress-"));
|
||||||
|
tempDirs.push(root);
|
||||||
|
const packageDir = path.join(root, "pkg");
|
||||||
|
const targetDir = path.join(root, "out");
|
||||||
|
fs.mkdirSync(packageDir, { recursive: true });
|
||||||
|
|
||||||
|
// Create a ZIP with some content to trigger progress
|
||||||
|
const zipPath = path.join(packageDir, "progress-test.zip");
|
||||||
|
const zip = new AdmZip();
|
||||||
|
zip.addFile("file1.txt", Buffer.from("Hello World ".repeat(100)));
|
||||||
|
zip.addFile("file2.txt", Buffer.from("Another file ".repeat(100)));
|
||||||
|
zip.writeZip(zipPath);
|
||||||
|
|
||||||
|
const progressUpdates: Array<{
|
||||||
|
archiveName: string;
|
||||||
|
percent: number;
|
||||||
|
phase: string;
|
||||||
|
archivePercent?: number;
|
||||||
|
}> = [];
|
||||||
|
|
||||||
|
const result = await extractPackageArchives({
|
||||||
|
packageDir,
|
||||||
|
targetDir,
|
||||||
|
cleanupMode: "none",
|
||||||
|
conflictMode: "overwrite",
|
||||||
|
removeLinks: false,
|
||||||
|
removeSamples: false,
|
||||||
|
onProgress: (update) => {
|
||||||
|
progressUpdates.push({
|
||||||
|
archiveName: update.archiveName,
|
||||||
|
percent: update.percent,
|
||||||
|
phase: update.phase,
|
||||||
|
archivePercent: update.archivePercent,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.extracted).toBe(1);
|
||||||
|
expect(result.failed).toBe(0);
|
||||||
|
|
||||||
|
// Should have at least preparing, extracting, and done phases
|
||||||
|
const phases = new Set(progressUpdates.map((u) => u.phase));
|
||||||
|
expect(phases.has("preparing")).toBe(true);
|
||||||
|
expect(phases.has("extracting")).toBe(true);
|
||||||
|
|
||||||
|
// Extracting phase should include the archive name
|
||||||
|
const extracting = progressUpdates.filter((u) => u.phase === "extracting" && u.archiveName === "progress-test.zip");
|
||||||
|
expect(extracting.length).toBeGreaterThan(0);
|
||||||
|
|
||||||
|
// Should end at 100%
|
||||||
|
const lastExtracting = extracting[extracting.length - 1];
|
||||||
|
expect(lastExtracting.archivePercent).toBe(100);
|
||||||
|
|
||||||
|
// Files should exist
|
||||||
|
expect(fs.existsSync(path.join(targetDir, "file1.txt"))).toBe(true);
|
||||||
|
expect(fs.existsSync(path.join(targetDir, "file2.txt"))).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("extracts multiple archives sequentially with progress for each", async () => {
|
||||||
|
process.env.RD_EXTRACT_BACKEND = "jvm";
|
||||||
|
|
||||||
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), "rd-jvm-multi-"));
|
||||||
|
tempDirs.push(root);
|
||||||
|
const packageDir = path.join(root, "pkg");
|
||||||
|
const targetDir = path.join(root, "out");
|
||||||
|
fs.mkdirSync(packageDir, { recursive: true });
|
||||||
|
|
||||||
|
// Create two separate ZIP archives
|
||||||
|
const zip1 = new AdmZip();
|
||||||
|
zip1.addFile("episode01.txt", Buffer.from("ep1 content"));
|
||||||
|
zip1.writeZip(path.join(packageDir, "archive1.zip"));
|
||||||
|
|
||||||
|
const zip2 = new AdmZip();
|
||||||
|
zip2.addFile("episode02.txt", Buffer.from("ep2 content"));
|
||||||
|
zip2.writeZip(path.join(packageDir, "archive2.zip"));
|
||||||
|
|
||||||
|
const archiveNames = new Set<string>();
|
||||||
|
|
||||||
|
const result = await extractPackageArchives({
|
||||||
|
packageDir,
|
||||||
|
targetDir,
|
||||||
|
cleanupMode: "none",
|
||||||
|
conflictMode: "overwrite",
|
||||||
|
removeLinks: false,
|
||||||
|
removeSamples: false,
|
||||||
|
onProgress: (update) => {
|
||||||
|
if (update.phase === "extracting" && update.archiveName) {
|
||||||
|
archiveNames.add(update.archiveName);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.extracted).toBe(2);
|
||||||
|
expect(result.failed).toBe(0);
|
||||||
|
// Both archive names should have appeared in progress
|
||||||
|
expect(archiveNames.has("archive1.zip")).toBe(true);
|
||||||
|
expect(archiveNames.has("archive2.zip")).toBe(true);
|
||||||
|
// Both files extracted
|
||||||
|
expect(fs.existsSync(path.join(targetDir, "episode01.txt"))).toBe(true);
|
||||||
|
expect(fs.existsSync(path.join(targetDir, "episode02.txt"))).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("respects ask/skip conflict mode in jvm backend", async () => {
|
||||||
process.env.RD_EXTRACT_BACKEND = "jvm";
|
process.env.RD_EXTRACT_BACKEND = "jvm";
|
||||||
|
|
||||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), "rd-jvm-extract-"));
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), "rd-jvm-extract-"));
|
||||||
|
|||||||
@ -15,6 +15,8 @@ import {
|
|||||||
|
|
||||||
const tempDirs: string[] = [];
|
const tempDirs: string[] = [];
|
||||||
const originalExtractBackend = process.env.RD_EXTRACT_BACKEND;
|
const originalExtractBackend = process.env.RD_EXTRACT_BACKEND;
|
||||||
|
const originalStatfs = fs.promises.statfs;
|
||||||
|
const originalZipEntryMemoryLimit = process.env.RD_ZIP_ENTRY_MEMORY_LIMIT_MB;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
process.env.RD_EXTRACT_BACKEND = "legacy";
|
process.env.RD_EXTRACT_BACKEND = "legacy";
|
||||||
@ -29,6 +31,12 @@ afterEach(() => {
|
|||||||
} else {
|
} else {
|
||||||
process.env.RD_EXTRACT_BACKEND = originalExtractBackend;
|
process.env.RD_EXTRACT_BACKEND = originalExtractBackend;
|
||||||
}
|
}
|
||||||
|
(fs.promises as any).statfs = originalStatfs;
|
||||||
|
if (originalZipEntryMemoryLimit === undefined) {
|
||||||
|
delete process.env.RD_ZIP_ENTRY_MEMORY_LIMIT_MB;
|
||||||
|
} else {
|
||||||
|
process.env.RD_ZIP_ENTRY_MEMORY_LIMIT_MB = originalZipEntryMemoryLimit;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("extractor", () => {
|
describe("extractor", () => {
|
||||||
@ -574,7 +582,6 @@ describe("extractor", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("keeps original ZIP size guard error when external fallback is unavailable", async () => {
|
it("keeps original ZIP size guard error when external fallback is unavailable", async () => {
|
||||||
const previousLimit = process.env.RD_ZIP_ENTRY_MEMORY_LIMIT_MB;
|
|
||||||
process.env.RD_ZIP_ENTRY_MEMORY_LIMIT_MB = "8";
|
process.env.RD_ZIP_ENTRY_MEMORY_LIMIT_MB = "8";
|
||||||
|
|
||||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), "rd-extract-"));
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), "rd-extract-"));
|
||||||
@ -588,7 +595,6 @@ describe("extractor", () => {
|
|||||||
zip.addFile("large.bin", Buffer.alloc(9 * 1024 * 1024, 7));
|
zip.addFile("large.bin", Buffer.alloc(9 * 1024 * 1024, 7));
|
||||||
zip.writeZip(zipPath);
|
zip.writeZip(zipPath);
|
||||||
|
|
||||||
try {
|
|
||||||
const result = await extractPackageArchives({
|
const result = await extractPackageArchives({
|
||||||
packageDir,
|
packageDir,
|
||||||
targetDir,
|
targetDir,
|
||||||
@ -600,20 +606,9 @@ describe("extractor", () => {
|
|||||||
expect(result.extracted).toBe(0);
|
expect(result.extracted).toBe(0);
|
||||||
expect(result.failed).toBe(1);
|
expect(result.failed).toBe(1);
|
||||||
expect(String(result.lastError)).toMatch(/ZIP-Eintrag.*groß/i);
|
expect(String(result.lastError)).toMatch(/ZIP-Eintrag.*groß/i);
|
||||||
} finally {
|
|
||||||
if (previousLimit === undefined) {
|
|
||||||
delete process.env.RD_ZIP_ENTRY_MEMORY_LIMIT_MB;
|
|
||||||
} else {
|
|
||||||
process.env.RD_ZIP_ENTRY_MEMORY_LIMIT_MB = previousLimit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches resume-state archive names case-insensitively on Windows", async () => {
|
it.skipIf(process.platform !== "win32")("matches resume-state archive names case-insensitively on Windows", async () => {
|
||||||
if (process.platform !== "win32") {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), "rd-extract-"));
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), "rd-extract-"));
|
||||||
tempDirs.push(root);
|
tempDirs.push(root);
|
||||||
const packageDir = path.join(root, "pkg");
|
const packageDir = path.join(root, "pkg");
|
||||||
@ -650,10 +645,8 @@ describe("extractor", () => {
|
|||||||
zip.addFile("test.txt", Buffer.alloc(1024, 0x41));
|
zip.addFile("test.txt", Buffer.alloc(1024, 0x41));
|
||||||
zip.writeZip(path.join(packageDir, "test.zip"));
|
zip.writeZip(path.join(packageDir, "test.zip"));
|
||||||
|
|
||||||
const originalStatfs = fs.promises.statfs;
|
|
||||||
(fs.promises as any).statfs = async () => ({ bfree: 1, bsize: 1 });
|
(fs.promises as any).statfs = async () => ({ bfree: 1, bsize: 1 });
|
||||||
|
|
||||||
try {
|
|
||||||
await expect(
|
await expect(
|
||||||
extractPackageArchives({
|
extractPackageArchives({
|
||||||
packageDir,
|
packageDir,
|
||||||
@ -664,9 +657,6 @@ describe("extractor", () => {
|
|||||||
removeSamples: false,
|
removeSamples: false,
|
||||||
})
|
})
|
||||||
).rejects.toThrow(/Nicht genug Speicherplatz/);
|
).rejects.toThrow(/Nicht genug Speicherplatz/);
|
||||||
} finally {
|
|
||||||
(fs.promises as any).statfs = originalStatfs;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("proceeds when disk space is sufficient", async () => {
|
it("proceeds when disk space is sufficient", async () => {
|
||||||
|
|||||||
@ -166,7 +166,7 @@ describe("mega-web-fallback", () => {
|
|||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
controller.abort("test");
|
controller.abort("test");
|
||||||
}, 30);
|
}, 200);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await expect(fallback.unrestrict("https://mega.debrid/link2", controller.signal)).rejects.toThrow(/aborted/i);
|
await expect(fallback.unrestrict("https://mega.debrid/link2", controller.signal)).rejects.toThrow(/aborted/i);
|
||||||
|
|||||||
188
tests/resolve-archive-items.test.ts
Normal file
188
tests/resolve-archive-items.test.ts
Normal file
@ -0,0 +1,188 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { resolveArchiveItemsFromList } from "../src/main/download-manager";
|
||||||
|
|
||||||
|
type MinimalItem = {
|
||||||
|
targetPath?: string;
|
||||||
|
fileName?: string;
|
||||||
|
[key: string]: unknown;
|
||||||
|
};
|
||||||
|
|
||||||
|
function makeItems(names: string[]): MinimalItem[] {
|
||||||
|
return names.map((name) => ({
|
||||||
|
targetPath: `C:\\Downloads\\Package\\${name}`,
|
||||||
|
fileName: name,
|
||||||
|
id: name,
|
||||||
|
status: "completed",
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("resolveArchiveItemsFromList", () => {
|
||||||
|
// ── Multipart RAR (.partN.rar) ──
|
||||||
|
|
||||||
|
it("matches multipart .part1.rar archives", () => {
|
||||||
|
const items = makeItems([
|
||||||
|
"Movie.part1.rar",
|
||||||
|
"Movie.part2.rar",
|
||||||
|
"Movie.part3.rar",
|
||||||
|
"Other.rar",
|
||||||
|
]);
|
||||||
|
const result = resolveArchiveItemsFromList("Movie.part1.rar", items as any);
|
||||||
|
expect(result).toHaveLength(3);
|
||||||
|
expect(result.map((i: any) => i.fileName)).toEqual([
|
||||||
|
"Movie.part1.rar",
|
||||||
|
"Movie.part2.rar",
|
||||||
|
"Movie.part3.rar",
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("matches multipart .part01.rar archives (zero-padded)", () => {
|
||||||
|
const items = makeItems([
|
||||||
|
"Film.part01.rar",
|
||||||
|
"Film.part02.rar",
|
||||||
|
"Film.part10.rar",
|
||||||
|
"Unrelated.zip",
|
||||||
|
]);
|
||||||
|
const result = resolveArchiveItemsFromList("Film.part01.rar", items as any);
|
||||||
|
expect(result).toHaveLength(3);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── Old-style RAR (.rar + .r00, .r01, etc.) ──
|
||||||
|
|
||||||
|
it("matches old-style .rar + .rNN volumes", () => {
|
||||||
|
const items = makeItems([
|
||||||
|
"Archive.rar",
|
||||||
|
"Archive.r00",
|
||||||
|
"Archive.r01",
|
||||||
|
"Archive.r02",
|
||||||
|
"Other.zip",
|
||||||
|
]);
|
||||||
|
const result = resolveArchiveItemsFromList("Archive.rar", items as any);
|
||||||
|
expect(result).toHaveLength(4);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── Single RAR ──
|
||||||
|
|
||||||
|
it("matches a single .rar file", () => {
|
||||||
|
const items = makeItems(["SingleFile.rar", "Other.mkv"]);
|
||||||
|
const result = resolveArchiveItemsFromList("SingleFile.rar", items as any);
|
||||||
|
expect(result).toHaveLength(1);
|
||||||
|
expect((result[0] as any).fileName).toBe("SingleFile.rar");
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── Split ZIP ──
|
||||||
|
|
||||||
|
it("matches split .zip.NNN files", () => {
|
||||||
|
const items = makeItems([
|
||||||
|
"Data.zip",
|
||||||
|
"Data.zip.001",
|
||||||
|
"Data.zip.002",
|
||||||
|
"Data.zip.003",
|
||||||
|
]);
|
||||||
|
const result = resolveArchiveItemsFromList("Data.zip.001", items as any);
|
||||||
|
expect(result).toHaveLength(4);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── Split 7z ──
|
||||||
|
|
||||||
|
it("matches split .7z.NNN files", () => {
|
||||||
|
const items = makeItems([
|
||||||
|
"Backup.7z.001",
|
||||||
|
"Backup.7z.002",
|
||||||
|
]);
|
||||||
|
const result = resolveArchiveItemsFromList("Backup.7z.001", items as any);
|
||||||
|
expect(result).toHaveLength(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── Generic .NNN splits ──
|
||||||
|
|
||||||
|
it("matches generic .NNN split files", () => {
|
||||||
|
const items = makeItems([
|
||||||
|
"video.001",
|
||||||
|
"video.002",
|
||||||
|
"video.003",
|
||||||
|
]);
|
||||||
|
const result = resolveArchiveItemsFromList("video.001", items as any);
|
||||||
|
expect(result).toHaveLength(3);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── Exact filename match ──
|
||||||
|
|
||||||
|
it("matches a single .zip by exact name", () => {
|
||||||
|
const items = makeItems(["myarchive.zip", "other.rar"]);
|
||||||
|
const result = resolveArchiveItemsFromList("myarchive.zip", items as any);
|
||||||
|
expect(result).toHaveLength(1);
|
||||||
|
expect((result[0] as any).fileName).toBe("myarchive.zip");
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── Case insensitivity ──
|
||||||
|
|
||||||
|
it("matches case-insensitively", () => {
|
||||||
|
const items = makeItems([
|
||||||
|
"MOVIE.PART1.RAR",
|
||||||
|
"MOVIE.PART2.RAR",
|
||||||
|
]);
|
||||||
|
const result = resolveArchiveItemsFromList("movie.part1.rar", items as any);
|
||||||
|
expect(result).toHaveLength(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── Stem-based fallback ──
|
||||||
|
|
||||||
|
it("uses stem-based fallback when exact patterns fail", () => {
|
||||||
|
// Simulate a debrid service that renames "Movie.part1.rar" to "Movie.part1_dl.rar"
|
||||||
|
// but the disk file is "Movie.part1.rar"
|
||||||
|
const items = makeItems([
|
||||||
|
"Movie.rar",
|
||||||
|
]);
|
||||||
|
// The archive on disk is "Movie.part1.rar" but there's no item matching the
|
||||||
|
// .partN pattern. The stem "movie" should match "Movie.rar" via fallback.
|
||||||
|
const result = resolveArchiveItemsFromList("Movie.part1.rar", items as any);
|
||||||
|
// stem fallback: "movie" starts with "movie" and ends with .rar
|
||||||
|
expect(result).toHaveLength(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── Single item fallback ──
|
||||||
|
|
||||||
|
it("returns single archive item when no pattern matches", () => {
|
||||||
|
const items = makeItems(["totally-different-name.rar"]);
|
||||||
|
const result = resolveArchiveItemsFromList("Original.rar", items as any);
|
||||||
|
// Single item in list with archive extension → return it
|
||||||
|
expect(result).toHaveLength(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── Empty when no match ──
|
||||||
|
|
||||||
|
it("returns empty when items have no archive extensions", () => {
|
||||||
|
const items = makeItems(["video.mkv", "subtitle.srt"]);
|
||||||
|
const result = resolveArchiveItemsFromList("Archive.rar", items as any);
|
||||||
|
expect(result).toHaveLength(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── Items without targetPath ──
|
||||||
|
|
||||||
|
it("falls back to fileName when targetPath is missing", () => {
|
||||||
|
const items = [
|
||||||
|
{ fileName: "Movie.part1.rar", id: "1", status: "completed" },
|
||||||
|
{ fileName: "Movie.part2.rar", id: "2", status: "completed" },
|
||||||
|
];
|
||||||
|
const result = resolveArchiveItemsFromList("Movie.part1.rar", items as any);
|
||||||
|
expect(result).toHaveLength(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── Multiple archives, should not cross-match ──
|
||||||
|
|
||||||
|
it("does not cross-match different archive groups", () => {
|
||||||
|
const items = makeItems([
|
||||||
|
"Episode.S01E01.part1.rar",
|
||||||
|
"Episode.S01E01.part2.rar",
|
||||||
|
"Episode.S01E02.part1.rar",
|
||||||
|
"Episode.S01E02.part2.rar",
|
||||||
|
]);
|
||||||
|
const result1 = resolveArchiveItemsFromList("Episode.S01E01.part1.rar", items as any);
|
||||||
|
expect(result1).toHaveLength(2);
|
||||||
|
expect(result1.every((i: any) => i.fileName.includes("S01E01"))).toBe(true);
|
||||||
|
|
||||||
|
const result2 = resolveArchiveItemsFromList("Episode.S01E02.part1.rar", items as any);
|
||||||
|
expect(result2).toHaveLength(2);
|
||||||
|
expect(result2.every((i: any) => i.fileName.includes("S01E02"))).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -153,7 +153,7 @@ async function main(): Promise<void> {
|
|||||||
createStoragePaths(path.join(tempRoot, "state-pause"))
|
createStoragePaths(path.join(tempRoot, "state-pause"))
|
||||||
);
|
);
|
||||||
manager2.addPackages([{ name: "pause", links: ["https://dummy/slow"] }]);
|
manager2.addPackages([{ name: "pause", links: ["https://dummy/slow"] }]);
|
||||||
manager2.start();
|
await manager2.start();
|
||||||
await new Promise((resolve) => setTimeout(resolve, 120));
|
await new Promise((resolve) => setTimeout(resolve, 120));
|
||||||
const paused = manager2.togglePause();
|
const paused = manager2.togglePause();
|
||||||
assert(paused, "Pause konnte nicht aktiviert werden");
|
assert(paused, "Pause konnte nicht aktiviert werden");
|
||||||
|
|||||||
@ -8,6 +8,8 @@ import { setLogListener } from "../src/main/logger";
|
|||||||
const tempDirs: string[] = [];
|
const tempDirs: string[] = [];
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
// Ensure session log is shut down between tests
|
||||||
|
shutdownSessionLog();
|
||||||
// Ensure listener is cleared between tests
|
// Ensure listener is cleared between tests
|
||||||
setLogListener(null);
|
setLogListener(null);
|
||||||
for (const dir of tempDirs.splice(0)) {
|
for (const dir of tempDirs.splice(0)) {
|
||||||
@ -45,7 +47,7 @@ describe("session-log", () => {
|
|||||||
logger.info("Test-Nachricht für Session-Log");
|
logger.info("Test-Nachricht für Session-Log");
|
||||||
|
|
||||||
// Wait for flush (200ms interval + margin)
|
// Wait for flush (200ms interval + margin)
|
||||||
await new Promise((resolve) => setTimeout(resolve, 350));
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||||
|
|
||||||
const content = fs.readFileSync(logPath, "utf8");
|
const content = fs.readFileSync(logPath, "utf8");
|
||||||
expect(content).toContain("Test-Nachricht für Session-Log");
|
expect(content).toContain("Test-Nachricht für Session-Log");
|
||||||
@ -79,7 +81,7 @@ describe("session-log", () => {
|
|||||||
const { logger } = await import("../src/main/logger");
|
const { logger } = await import("../src/main/logger");
|
||||||
logger.info("Nach-Shutdown-Nachricht");
|
logger.info("Nach-Shutdown-Nachricht");
|
||||||
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, 350));
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||||
|
|
||||||
const content = fs.readFileSync(logPath, "utf8");
|
const content = fs.readFileSync(logPath, "utf8");
|
||||||
expect(content).not.toContain("Nach-Shutdown-Nachricht");
|
expect(content).not.toContain("Nach-Shutdown-Nachricht");
|
||||||
@ -137,7 +139,7 @@ describe("session-log", () => {
|
|||||||
shutdownSessionLog();
|
shutdownSessionLog();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("multiple sessions create different files", () => {
|
it("multiple sessions create different files", async () => {
|
||||||
const baseDir = fs.mkdtempSync(path.join(os.tmpdir(), "rd-slog-"));
|
const baseDir = fs.mkdtempSync(path.join(os.tmpdir(), "rd-slog-"));
|
||||||
tempDirs.push(baseDir);
|
tempDirs.push(baseDir);
|
||||||
|
|
||||||
@ -146,10 +148,7 @@ describe("session-log", () => {
|
|||||||
shutdownSessionLog();
|
shutdownSessionLog();
|
||||||
|
|
||||||
// Small delay to ensure different timestamp
|
// Small delay to ensure different timestamp
|
||||||
const start = Date.now();
|
await new Promise((resolve) => setTimeout(resolve, 1100));
|
||||||
while (Date.now() - start < 1100) {
|
|
||||||
// busy-wait for 1.1 seconds to get different second in filename
|
|
||||||
}
|
|
||||||
|
|
||||||
initSessionLog(baseDir);
|
initSessionLog(baseDir);
|
||||||
const path2 = getSessionLogPath();
|
const path2 = getSessionLogPath();
|
||||||
|
|||||||
@ -22,7 +22,7 @@ afterEach(() => {
|
|||||||
|
|
||||||
describe("update", () => {
|
describe("update", () => {
|
||||||
it("normalizes update repo input", () => {
|
it("normalizes update repo input", () => {
|
||||||
expect(normalizeUpdateRepo("")).toBe("Sucukdeluxe/real-debrid-downloader");
|
expect(normalizeUpdateRepo("")).toBe("Administrator/real-debrid-downloader");
|
||||||
expect(normalizeUpdateRepo("owner/repo")).toBe("owner/repo");
|
expect(normalizeUpdateRepo("owner/repo")).toBe("owner/repo");
|
||||||
expect(normalizeUpdateRepo("https://codeberg.org/owner/repo")).toBe("owner/repo");
|
expect(normalizeUpdateRepo("https://codeberg.org/owner/repo")).toBe("owner/repo");
|
||||||
expect(normalizeUpdateRepo("https://www.codeberg.org/owner/repo")).toBe("owner/repo");
|
expect(normalizeUpdateRepo("https://www.codeberg.org/owner/repo")).toBe("owner/repo");
|
||||||
@ -31,14 +31,14 @@ describe("update", () => {
|
|||||||
expect(normalizeUpdateRepo("git@codeberg.org:owner/repo.git")).toBe("owner/repo");
|
expect(normalizeUpdateRepo("git@codeberg.org:owner/repo.git")).toBe("owner/repo");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("uses normalized repo slug for Codeberg API requests", async () => {
|
it("uses normalized repo slug for API requests", async () => {
|
||||||
let requestedUrl = "";
|
let requestedUrl = "";
|
||||||
globalThis.fetch = (async (input: RequestInfo | URL): Promise<Response> => {
|
globalThis.fetch = (async (input: RequestInfo | URL): Promise<Response> => {
|
||||||
requestedUrl = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
|
requestedUrl = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
|
||||||
return new Response(
|
return new Response(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
tag_name: `v${APP_VERSION}`,
|
tag_name: `v${APP_VERSION}`,
|
||||||
html_url: "https://codeberg.org/owner/repo/releases/tag/v1.0.0",
|
html_url: "https://git.24-music.de/owner/repo/releases/tag/v1.0.0",
|
||||||
assets: []
|
assets: []
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
@ -48,8 +48,8 @@ describe("update", () => {
|
|||||||
);
|
);
|
||||||
}) as typeof fetch;
|
}) as typeof fetch;
|
||||||
|
|
||||||
const result = await checkGitHubUpdate("https://codeberg.org/owner/repo/releases");
|
const result = await checkGitHubUpdate("https://git.24-music.de/owner/repo/releases");
|
||||||
expect(requestedUrl).toBe("https://codeberg.org/api/v1/repos/owner/repo/releases/latest");
|
expect(requestedUrl).toBe("https://git.24-music.de/api/v1/repos/owner/repo/releases/latest");
|
||||||
expect(result.currentVersion).toBe(APP_VERSION);
|
expect(result.currentVersion).toBe(APP_VERSION);
|
||||||
expect(result.latestVersion).toBe(APP_VERSION);
|
expect(result.latestVersion).toBe(APP_VERSION);
|
||||||
expect(result.updateAvailable).toBe(false);
|
expect(result.updateAvailable).toBe(false);
|
||||||
@ -484,14 +484,14 @@ describe("normalizeUpdateRepo extended", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("returns default for malformed inputs", () => {
|
it("returns default for malformed inputs", () => {
|
||||||
expect(normalizeUpdateRepo("just-one-part")).toBe("Sucukdeluxe/real-debrid-downloader");
|
expect(normalizeUpdateRepo("just-one-part")).toBe("Administrator/real-debrid-downloader");
|
||||||
expect(normalizeUpdateRepo(" ")).toBe("Sucukdeluxe/real-debrid-downloader");
|
expect(normalizeUpdateRepo(" ")).toBe("Administrator/real-debrid-downloader");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("rejects traversal-like owner or repo segments", () => {
|
it("rejects traversal-like owner or repo segments", () => {
|
||||||
expect(normalizeUpdateRepo("../owner/repo")).toBe("Sucukdeluxe/real-debrid-downloader");
|
expect(normalizeUpdateRepo("../owner/repo")).toBe("Administrator/real-debrid-downloader");
|
||||||
expect(normalizeUpdateRepo("owner/../repo")).toBe("Sucukdeluxe/real-debrid-downloader");
|
expect(normalizeUpdateRepo("owner/../repo")).toBe("Administrator/real-debrid-downloader");
|
||||||
expect(normalizeUpdateRepo("https://codeberg.org/owner/../../repo")).toBe("Sucukdeluxe/real-debrid-downloader");
|
expect(normalizeUpdateRepo("https://codeberg.org/owner/../../repo")).toBe("Administrator/real-debrid-downloader");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("handles www prefix", () => {
|
it("handles www prefix", () => {
|
||||||
|
|||||||
@ -12,5 +12,5 @@
|
|||||||
"isolatedModules": true,
|
"isolatedModules": true,
|
||||||
"types": ["node", "vite/client"]
|
"types": ["node", "vite/client"]
|
||||||
},
|
},
|
||||||
"include": ["src", "tests", "vite.config.ts"]
|
"include": ["src", "tests", "vite.config.mts"]
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user