libraryFiles.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { isApiSliceableFilename, isSliceableFilename } from './slicer';
  2. /**
  3. * Is a library file sliced — does it carry printer-executable G-code?
  4. *
  5. * The name alone is not evidence (#2993). A plate exported from Studio, or a
  6. * print dispatched through the cloud, is a fully sliced 3MF called `Foo.3mf`,
  7. * and deciding from the extension filed those as source-only projects with no
  8. * Print button — while the Archives card, which looks inside the zip, showed
  9. * the same file's green GCODE badge. The backend now classifies on content, so
  10. * `file_type` answers where the name cannot.
  11. *
  12. * Either signal is enough, which mirrors `classify_file_type` on the backend:
  13. * it returns `gcode.3mf` for a `.gcode.3mf` name without opening the file at
  14. * all, and only consults the zip when the name has not already settled it. A
  15. * row stored before the backfill therefore keeps its Print button on the
  16. * strength of its name.
  17. */
  18. export function isSlicedLibraryFile(file: {
  19. filename: string;
  20. file_type?: string | null;
  21. }): boolean {
  22. const fileType = (file.file_type || '').toLowerCase();
  23. if (fileType === 'gcode' || fileType === 'gcode.3mf') return true;
  24. const lower = (file.filename || '').toLowerCase();
  25. return lower.endsWith('.gcode') || lower.endsWith('.gcode.3mf');
  26. }
  27. /**
  28. * Is a library file something a slicer can take as *input*?
  29. *
  30. * `isSliceableFilename` already refuses a `.gcode` / `.gcode.3mf` name — the
  31. * point being that a sliced file is an output, not an input. That refusal was
  32. * as name-bound as the Print gate it sits beside (#2993), so once a sliced
  33. * `Foo.3mf` correctly gained a Print button it would have been offered a
  34. * Slice one as well: re-slicing its own G-code.
  35. */
  36. export function isSliceableLibraryFile(
  37. file: { filename: string; file_type?: string | null },
  38. useSlicerApi: boolean,
  39. ): boolean {
  40. if (isSlicedLibraryFile(file)) return false;
  41. return useSlicerApi ? isApiSliceableFilename(file.filename) : isSliceableFilename(file.filename);
  42. }