fix(dispatch): clean up transient library upload from Direct-Print flow (#730)

The "Print" button on a printer card (and drag-drop-onto-card) used
  FileUploadModal to persist the file as a LibraryFile, then dispatched
  through POST /library/files/{id}/print. The LibraryFile row + disk file
  were left behind after every one-off print, polluting File Manager with
  entries the user never asked to save.

  FilePrintRequest.cleanup_library_after_dispatch (default False) opts
  into post-dispatch cleanup. When set, _run_print_library_file stages
  db.delete(lib_file) in the same transaction as archive_print so a
  mid-flight FTP / start_print failure rolls both back cleanly, commits
  together, then unlinks the library disk file + thumbnail after commit
  succeeds. External library files (is_external=True) are never touched.

  Only the Printers-page Direct-Print PrintModal sets the flag. Every
  other api.printLibraryFile caller (File Manager Print, Project Detail
  Print) leaves it unset — their entries are there by user intent.

  Also moves formatPrintName out of PrintersPage.tsx into a new
  utils/printName.ts module — fa1c46d9 (#881) exported it inline so its
  test could import it, tripping react-refresh/only-export-components.
This commit is contained in:
maziggy
2026-04-21 14:10:04 +02:00
parent 276a1db3ef
commit 1682b6956f
15 changed files with 420 additions and 159 deletions
@@ -49,6 +49,7 @@ export function PrintModal({
onClose,
onSuccess,
projectId,
cleanupLibraryAfterDispatch,
}: PrintModalProps) {
const { t } = useTranslation();
const queryClient = useQueryClient();
@@ -737,6 +738,7 @@ export function PrintModal({
ams_mapping: printerMapping,
...printOptions,
project_id: projectId,
cleanup_library_after_dispatch: cleanupLibraryAfterDispatch,
});
} else {
// project_id is intentionally omitted here: reprintArchive targets an existing
@@ -34,6 +34,9 @@ export interface PrintModalProps {
onSuccess?: () => void;
/** Project ID to associate the resulting archive with (only when triggered from project view) */
projectId?: number;
/** Delete the LibraryFile after dispatch — used by the Printers-page Direct-Print flow
* so transient uploads don't linger in File Manager. Only applies to library-file prints. */
cleanupLibraryAfterDispatch?: boolean;
}
/**