mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-22 03:49:18 +02:00
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:
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Append a plate label to the print name. When `plateLabel` is provided (resolved
|
||||
* by the caller from the linked archive's plate list — see #881 follow-up), it
|
||||
* is used verbatim, including the explicit "Plate 1" case on multi-plate 3MFs.
|
||||
* Falls back to parsing `plate_N.gcode` from the MQTT gcode_file path, and in
|
||||
* that fallback we only show N > 1 because we can't tell from the path alone
|
||||
* whether the 3MF is multi-plate.
|
||||
*/
|
||||
export function formatPrintName(
|
||||
name: string | null,
|
||||
gcodeFile: string | null | undefined,
|
||||
t: (key: string, fallback: string, opts?: Record<string, unknown>) => string,
|
||||
plateLabel?: string | null,
|
||||
): string {
|
||||
if (!name) return '';
|
||||
if (plateLabel) return `${name} — ${plateLabel}`;
|
||||
if (!gcodeFile) return name;
|
||||
const match = gcodeFile.match(/plate_(\d+)\.gcode/);
|
||||
if (match && parseInt(match[1], 10) > 1) {
|
||||
return `${name} — ${t('printers.plateNumber', 'Plate {{number}}', { number: match[1] })}`;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
Reference in New Issue
Block a user