Fix manual extract relabeling
This commit is contained in:
parent
e9ec35a6a6
commit
40f097249c
@ -5702,10 +5702,11 @@ export class DownloadManager extends EventEmitter {
|
|||||||
this.clearHybridArchiveState(packageId);
|
this.clearHybridArchiveState(packageId);
|
||||||
const items = pkg.itemIds.map((id) => this.session.items[id]).filter(Boolean) as DownloadItem[];
|
const items = pkg.itemIds.map((id) => this.session.items[id]).filter(Boolean) as DownloadItem[];
|
||||||
const completedItems = items.filter((item) => item.status === "completed");
|
const completedItems = items.filter((item) => item.status === "completed");
|
||||||
if (completedItems.length === 0) return;
|
const targetItems = completedItems.filter((item) => !isExtractedLabel(item.fullStatus));
|
||||||
|
if (targetItems.length === 0) return;
|
||||||
pkg.status = "queued";
|
pkg.status = "queued";
|
||||||
pkg.updatedAt = nowMs();
|
pkg.updatedAt = nowMs();
|
||||||
for (const item of completedItems) {
|
for (const item of targetItems) {
|
||||||
if (!isExtractedLabel(item.fullStatus)) {
|
if (!isExtractedLabel(item.fullStatus)) {
|
||||||
item.fullStatus = "Entpacken - Ausstehend";
|
item.fullStatus = "Entpacken - Ausstehend";
|
||||||
item.updatedAt = nowMs();
|
item.updatedAt = nowMs();
|
||||||
@ -5713,7 +5714,8 @@ export class DownloadManager extends EventEmitter {
|
|||||||
}
|
}
|
||||||
logger.info(`Extraktion manuell wiederholt: pkg=${pkg.name}`);
|
logger.info(`Extraktion manuell wiederholt: pkg=${pkg.name}`);
|
||||||
this.logPackageForPackage(pkg, "INFO", "Extraktion manuell wiederholt", {
|
this.logPackageForPackage(pkg, "INFO", "Extraktion manuell wiederholt", {
|
||||||
completedItems: completedItems.length
|
completedItems: completedItems.length,
|
||||||
|
targetedItems: targetItems.length
|
||||||
});
|
});
|
||||||
this.persistSoon();
|
this.persistSoon();
|
||||||
this.emitState(true);
|
this.emitState(true);
|
||||||
@ -5730,16 +5732,18 @@ export class DownloadManager extends EventEmitter {
|
|||||||
}
|
}
|
||||||
const items = pkg.itemIds.map((id) => this.session.items[id]).filter(Boolean) as DownloadItem[];
|
const items = pkg.itemIds.map((id) => this.session.items[id]).filter(Boolean) as DownloadItem[];
|
||||||
const completedItems = items.filter((item) => item.status === "completed");
|
const completedItems = items.filter((item) => item.status === "completed");
|
||||||
if (completedItems.length === 0) return;
|
const targetItems = completedItems.filter((item) => !isExtractedLabel(item.fullStatus));
|
||||||
|
if (targetItems.length === 0) return;
|
||||||
pkg.status = "queued";
|
pkg.status = "queued";
|
||||||
pkg.updatedAt = nowMs();
|
pkg.updatedAt = nowMs();
|
||||||
for (const item of completedItems) {
|
for (const item of targetItems) {
|
||||||
item.fullStatus = "Entpacken - Ausstehend";
|
item.fullStatus = "Entpacken - Ausstehend";
|
||||||
item.updatedAt = nowMs();
|
item.updatedAt = nowMs();
|
||||||
}
|
}
|
||||||
logger.info(`Jetzt entpacken: pkg=${pkg.name}, completed=${completedItems.length}`);
|
logger.info(`Jetzt entpacken: pkg=${pkg.name}, completed=${completedItems.length}, targeted=${targetItems.length}`);
|
||||||
this.logPackageForPackage(pkg, "INFO", "Jetzt entpacken ausgelöst", {
|
this.logPackageForPackage(pkg, "INFO", "Jetzt entpacken ausgelöst", {
|
||||||
completedItems: completedItems.length
|
completedItems: completedItems.length,
|
||||||
|
targetedItems: targetItems.length
|
||||||
});
|
});
|
||||||
this.persistSoon();
|
this.persistSoon();
|
||||||
this.emitState(true);
|
this.emitState(true);
|
||||||
|
|||||||
@ -5581,7 +5581,7 @@ export function App(): ReactElement {
|
|||||||
{hasPackages && !multi && (() => {
|
{hasPackages && !multi && (() => {
|
||||||
const pkg = snapshot.session.packages[contextMenu.packageId];
|
const pkg = snapshot.session.packages[contextMenu.packageId];
|
||||||
const items = pkg?.itemIds.map((id) => snapshot.session.items[id]).filter(Boolean) || [];
|
const items = pkg?.itemIds.map((id) => snapshot.session.items[id]).filter(Boolean) || [];
|
||||||
const someCompleted = items.some((item) => item && item.status === "completed");
|
const someCompleted = items.some((item) => item && item.status === "completed" && !/^Entpackt\b/i.test(item.fullStatus || ""));
|
||||||
return (<>
|
return (<>
|
||||||
{someCompleted && (
|
{someCompleted && (
|
||||||
<button className="ctx-menu-item" onClick={() => { void window.rd.extractNow(contextMenu.packageId).catch(() => {}); setContextMenu(null); }}>Jetzt entpacken</button>
|
<button className="ctx-menu-item" onClick={() => { void window.rd.extractNow(contextMenu.packageId).catch(() => {}); setContextMenu(null); }}>Jetzt entpacken</button>
|
||||||
@ -6121,4 +6121,3 @@ const PackageCard = memo(function PackageCard({ pkg, items, packageSpeed, stripe
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -227,6 +227,84 @@ describe("download manager", () => {
|
|||||||
expect((manager as any).shouldCollapseQuickPostProcessRequeue(packageId)).toBe(false);
|
expect((manager as any).shouldCollapseQuickPostProcessRequeue(packageId)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("extractNow only re-arms completed items that are not already extracted", () => {
|
||||||
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), "rd-extract-now-"));
|
||||||
|
tempDirs.push(root);
|
||||||
|
|
||||||
|
const session = emptySession();
|
||||||
|
const packageId = "extract-now-pkg";
|
||||||
|
const createdAt = Date.now() - 20_000;
|
||||||
|
const outputDir = path.join(root, "downloads", "Extract Now Test");
|
||||||
|
const extractDir = path.join(root, "extract", "Extract Now Test");
|
||||||
|
fs.mkdirSync(outputDir, { recursive: true });
|
||||||
|
fs.mkdirSync(extractDir, { recursive: true });
|
||||||
|
|
||||||
|
const specs = [
|
||||||
|
{ id: "extract-now-item-1", fileName: "show.e01.rar", fullStatus: "Entpackt - Done (<1s)" },
|
||||||
|
{ id: "extract-now-item-2", fileName: "show.e02.rar", fullStatus: "Entpackt - Done (1.2s)" },
|
||||||
|
{ id: "extract-now-item-3", fileName: "show.e03.rar", fullStatus: "Entpacken - Ausstehend" }
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
session.packageOrder = [packageId];
|
||||||
|
session.packages[packageId] = {
|
||||||
|
id: packageId,
|
||||||
|
name: "Extract Now Test",
|
||||||
|
outputDir,
|
||||||
|
extractDir,
|
||||||
|
status: "completed",
|
||||||
|
itemIds: specs.map((spec) => spec.id),
|
||||||
|
cancelled: false,
|
||||||
|
enabled: true,
|
||||||
|
createdAt,
|
||||||
|
updatedAt: createdAt
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const spec of specs) {
|
||||||
|
const targetPath = path.join(outputDir, spec.fileName);
|
||||||
|
fs.writeFileSync(targetPath, Buffer.alloc(128, 1));
|
||||||
|
session.items[spec.id] = {
|
||||||
|
id: spec.id,
|
||||||
|
packageId,
|
||||||
|
url: `https://example.com/${spec.fileName}`,
|
||||||
|
provider: "realdebrid",
|
||||||
|
status: "completed",
|
||||||
|
retries: 0,
|
||||||
|
speedBps: 0,
|
||||||
|
downloadedBytes: 128,
|
||||||
|
totalBytes: 128,
|
||||||
|
progressPercent: 100,
|
||||||
|
fileName: spec.fileName,
|
||||||
|
targetPath,
|
||||||
|
resumable: true,
|
||||||
|
attempts: 1,
|
||||||
|
lastError: "",
|
||||||
|
fullStatus: spec.fullStatus,
|
||||||
|
createdAt,
|
||||||
|
updatedAt: createdAt
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const manager = new DownloadManager(
|
||||||
|
{
|
||||||
|
...defaultSettings(),
|
||||||
|
token: "rd-token",
|
||||||
|
outputDir: path.join(root, "downloads"),
|
||||||
|
extractDir: path.join(root, "extract"),
|
||||||
|
autoExtract: true,
|
||||||
|
hybridExtract: true
|
||||||
|
},
|
||||||
|
session,
|
||||||
|
createStoragePaths(path.join(root, "state"))
|
||||||
|
);
|
||||||
|
|
||||||
|
manager.extractNow(packageId);
|
||||||
|
|
||||||
|
expect((manager as any).session.items["extract-now-item-1"].fullStatus).toBe("Entpackt - Done (<1s)");
|
||||||
|
expect((manager as any).session.items["extract-now-item-2"].fullStatus).toBe("Entpackt - Done (1.2s)");
|
||||||
|
expect((manager as any).session.items["extract-now-item-3"].fullStatus).toBe("Entpacken - Ausstehend");
|
||||||
|
expect((manager as any).session.packages[packageId].status).toBe("queued");
|
||||||
|
});
|
||||||
|
|
||||||
function createCompletedArchiveSession(root: string, packageName: string, extractedFileName: string): {
|
function createCompletedArchiveSession(root: string, packageName: string, extractedFileName: string): {
|
||||||
session: ReturnType<typeof emptySession>;
|
session: ReturnType<typeof emptySession>;
|
||||||
packageId: string;
|
packageId: string;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user