#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere
TypeScript dockerhacktoberfestjavapdfpdf-converterpdf-editorpdf-manipulationpdf-mergerpdf-ocrpdf-toolspdf-web-appspdfmergerself-hosted
fix(processing-folders): keep desktop disk results in place (#8125)
Reece Brownef799b93ee297
diff --git a/frontend/editor/src/proprietary/components/policies/ProcessingFolderSetupFlow.tsx b/frontend/editor/src/proprietary/components/policies/ProcessingFolderSetupFlow.tsxindex 6cb7509394..93ad1282ff 100644--- a/frontend/editor/src/proprietary/components/policies/ProcessingFolderSetupFlow.tsx+++ b/frontend/editor/src/proprietary/components/policies/ProcessingFolderSetupFlow.tsx@@ -149,9 +149,13 @@ export function ProcessingFolderSetupFlow({});void processing.refresh();if (onDisk)- void deliverSweepResults(saved.id, null, addFiles, {- excludeRunIds: baseline,- });+ void deliverSweepResults(+ saved.id,+ null,+ addFiles,+ { folderId: selected.id },+ { excludeRunIds: baseline },+ );onClose();if (!folder) navigate(`/files/${selected.id}`);}diff --git a/frontend/editor/src/proprietary/hooks/useProcessingFolders.ts b/frontend/editor/src/proprietary/hooks/useProcessingFolders.tsindex 9c44c9e9d7..a479e193ed 100644--- a/frontend/editor/src/proprietary/hooks/useProcessingFolders.ts+++ b/frontend/editor/src/proprietary/hooks/useProcessingFolders.ts@@ -189,9 +189,13 @@ export function useProcessingFolders(): ProcessingFoldersApi {});// Resume sweeps behind the response; pull a mount's on-disk results into the workbench.if (folderKind(folder) === "local") {- void deliverSweepResults(paused.id, null, addFiles, {- excludeRunIds: baseline,- });+ void deliverSweepResults(+ paused.id,+ null,+ addFiles,+ { folderId: folder.id },+ { excludeRunIds: baseline },+ );}await reload();return;@@ -207,7 +211,9 @@ export function useProcessingFolders(): ProcessingFoldersApi {});// The sweep runs behind the create response — no run count to wait on; pull// the on-disk results into the workbench as they settle.- void deliverSweepResults(saved.id, null, addFiles);+ void deliverSweepResults(saved.id, null, addFiles, {+ folderId: folder.id,+ });break;}case "virtual":@@ -308,9 +314,13 @@ export function useProcessingFolders(): ProcessingFoldersApi {// A mount's results land on disk where nothing shows them; a storage folder's// replace in place, already visible.if (folderKind(folder) === "local" && outcome.runIds.length > 0) {- void deliverSweepResults(existing.id, outcome.runIds.length, addFiles, {- includeRunIds: new Set(outcome.runIds),- });+ void deliverSweepResults(+ existing.id,+ outcome.runIds.length,+ addFiles,+ { folderId: folder.id },+ { includeRunIds: new Set(outcome.runIds) },+ );}},[recordFor, addFiles],diff --git a/frontend/editor/src/proprietary/services/processingRunDelivery.test.ts b/frontend/editor/src/proprietary/services/processingRunDelivery.test.tsindex ef1fe00798..b1080f7147 100644--- a/frontend/editor/src/proprietary/services/processingRunDelivery.test.ts+++ b/frontend/editor/src/proprietary/services/processingRunDelivery.test.ts@@ -58,9 +58,13 @@ describe("deliverSweepResults - one live delivery per folder", () => {// A caller that needs progress (the wizard) must run its own loop rather than// join the callback-less one already running, which cannot fire its callbacks.const bare = deliverSweepResults("policy-1", 1, addFiles);- const withCallbacks = deliverSweepResults("policy-1", 1, addFiles, {- onProgress,- });+ const withCallbacks = deliverSweepResults(+ "policy-1",+ 1,+ addFiles,+ {},+ { onProgress },+ );expect(withCallbacks).not.toBe(bare);await Promise.all([bare, withCallbacks]);@@ -78,9 +82,13 @@ describe("deliverSweepResults - one live delivery per folder", () => {// useProcessingFolders: enable() runs callback-less, sweep() always passes// includeRunIds - so the sweep runs its own loop over the same settled run.const fromEnable = deliverSweepResults("policy-1", null, addFiles);- const fromSweep = deliverSweepResults("policy-1", 1, addFiles, {- includeRunIds: new Set(["r1"]),- });+ const fromSweep = deliverSweepResults(+ "policy-1",+ 1,+ addFiles,+ {},+ { includeRunIds: new Set(["r1"]) },+ );await Promise.all([fromEnable, fromSweep]);expect(opened).toEqual(["r1.pdf"]);@@ -91,7 +99,13 @@ describe("deliverSweepResults - one live delivery per folder", () => {const onSettled = vi.fn();const bare = deliverSweepResults("policy-1", 1, addFiles);- const watcher = deliverSweepResults("policy-1", 1, addFiles, { onSettled });+ const watcher = deliverSweepResults(+ "policy-1",+ 1,+ addFiles,+ {},+ { onSettled },+ );await Promise.all([bare, watcher]);// The wizard reads the result's classification labels off these files, so a@@ -116,4 +130,17 @@ describe("deliverSweepResults - one live delivery per folder", () => {await Promise.all([a, b]);expect(addFiles).toHaveBeenCalledTimes(2);});++ it("imports disk results into their mounted folder without selecting them", async () => {+ const addFiles = vi.fn().mockResolvedValue(undefined);++ await deliverSweepResults("policy-1", 1, addFiles, {+ folderId: "mount-1",+ });++ expect(addFiles).toHaveBeenCalledWith([fileFor("r1.pdf")], {+ selectFiles: false,+ folderId: "mount-1",+ });+ });});diff --git a/frontend/editor/src/proprietary/services/processingRunDelivery.ts b/frontend/editor/src/proprietary/services/processingRunDelivery.tsindex e23751c76f..d1ec53ece5 100644--- a/frontend/editor/src/proprietary/services/processingRunDelivery.ts+++ b/frontend/editor/src/proprietary/services/processingRunDelivery.ts@@ -57,6 +57,11 @@ export interface SweepDeliveryCallbacks {includeRunIds?: ReadonlySet<string>;}+export interface SweepDeliveryFileOptions {+ /** Library folder that owns imported disk results. */+ folderId?: string;+}+/** The folder's current run ids — captured before a sweep so its delivery can ignore them. */export async function currentRunIds(policyId: string,@@ -158,8 +163,9 @@ export function deliverSweepResults(expected: number | null,addFiles: (files: File[],- options?: { selectFiles?: boolean },+ options?: { selectFiles?: boolean; folderId?: string },) => Promise<unknown>,+ fileOptions: SweepDeliveryFileOptions = {},callbacks?:| SweepDeliveryCallbacks| ((progress: SweepDeliveryProgress) => void),@@ -169,6 +175,7 @@ export function deliverSweepResults(policyId,expected,addFiles,+ fileOptions,callbacks,);}@@ -180,6 +187,7 @@ export function deliverSweepResults(policyId,expected,addFiles,+ fileOptions,).finally(() => {if (deliveriesInFlight.get(policyId) === started) {deliveriesInFlight.delete(policyId);@@ -194,8 +202,9 @@ async function deliverSweepResultsUntracked(expected: number | null,addFiles: (files: File[],- options?: { selectFiles?: boolean },+ options?: { selectFiles?: boolean; folderId?: string },) => Promise<unknown>,+ fileOptions: SweepDeliveryFileOptions,callbacks?:| SweepDeliveryCallbacks| ((progress: SweepDeliveryProgress) => void),@@ -206,6 +215,7 @@ async function deliverSweepResultsUntracked(policyId,expected,addFiles,+ fileOptions,callbacks,);} finally {@@ -218,8 +228,9 @@ async function deliverSweepResultsLoop(expected: number | null,addFiles: (files: File[],- options?: { selectFiles?: boolean },+ options?: { selectFiles?: boolean; folderId?: string },) => Promise<unknown>,+ fileOptions: SweepDeliveryFileOptions,callbacks?:| SweepDeliveryCallbacks| ((progress: SweepDeliveryProgress) => void),@@ -308,7 +319,7 @@ async function deliverSweepResultsLoop(if (opened.length > 0) {// One addFiles per poll batch, never selecting: a selection isn't meaningful// across a folderful of results.- await addFiles(opened);+ await addFiles(opened, { selectFiles: false, ...fileOptions });progress.opened += opened.length;}onProgress?.({ ...progress });