printName.ts 990 B

1234567891011121314151617181920212223
  1. /**
  2. * Append a plate label to the print name. When `plateLabel` is provided (resolved
  3. * by the caller from the linked archive's plate list — see #881 follow-up), it
  4. * is used verbatim, including the explicit "Plate 1" case on multi-plate 3MFs.
  5. * Falls back to parsing `plate_N.gcode` from the MQTT gcode_file path, and in
  6. * that fallback we only show N > 1 because we can't tell from the path alone
  7. * whether the 3MF is multi-plate.
  8. */
  9. export function formatPrintName(
  10. name: string | null,
  11. gcodeFile: string | null | undefined,
  12. t: (key: string, fallback: string, opts?: Record<string, unknown>) => string,
  13. plateLabel?: string | null,
  14. ): string {
  15. if (!name) return '';
  16. if (plateLabel) return `${name} — ${plateLabel}`;
  17. if (!gcodeFile) return name;
  18. const match = gcodeFile.match(/plate_(\d+)\.gcode/);
  19. if (match && parseInt(match[1], 10) > 1) {
  20. return `${name} — ${t('printers.plateNumber', 'Plate {{number}}', { number: match[1] })}`;
  21. }
  22. return name;
  23. }