Przeglądaj źródła

Add print metadata to queue API response (#524)

Queue endpoints now return filament_type, filament_color, layer_height,
nozzle_diameter, and sliced_for_model from the archive or library file.
Previously this data was only available via the archive API.
maziggy 3 miesięcy temu
rodzic
commit
fa87e24968

+ 3 - 0
CHANGELOG.md

@@ -14,6 +14,9 @@ All notable changes to Bambuddy will be documented in this file.
 - **Virtual Printer Queue Mode Doesn't Assign Printer** ([#518](https://github.com/maziggy/bambuddy/issues/518)) — Files sent to a virtual printer in "print queue" mode were added to the queue with no printer assigned, requiring manual assignment. The `_add_to_print_queue()` method always created queue items with `printer_id=None` and no `target_model`. Now assigns the virtual printer's `target_printer_id` if configured, or falls back to the VP's model (e.g., P1S, X1C) as `target_model` for "Any Printer" scheduling.
 - **Settings Text Fields Reset While Typing** — Text input fields on the Settings page (MQTT broker hostname, HA URL, tokens, etc.) reset mid-typing because the auto-save `onSuccess` handler overwrote `localSettings` with the server response, discarding characters typed during the save request. Removed the stale state overwrite so in-progress user input is preserved.
 
+### Improved
+- **Queue API Returns More Print Metadata** ([#524](https://github.com/maziggy/bambuddy/issues/524)) — The `GET /api/v1/queue` and `GET /api/v1/queue/{id}` endpoints now include `filament_type`, `filament_color`, `layer_height`, `nozzle_diameter`, and `sliced_for_model` from the archive or library file. Previously these fields were only available via the archive endpoints, requiring an extra API call.
+
 ## [0.2.1b3] - 2026-02-23
 
 ### Fixed

+ 11 - 1
backend/app/api/routes/print_queue.py

@@ -216,6 +216,11 @@ def _enrich_response(item: PrintQueueItem) -> PrintQueueItemResponse:
         response.archive_thumbnail = item.archive.thumbnail_path
         response.print_time_seconds = item.archive.print_time_seconds
         response.filament_used_grams = item.archive.filament_used_grams
+        response.filament_type = item.archive.filament_type
+        response.filament_color = item.archive.filament_color
+        response.layer_height = item.archive.layer_height
+        response.nozzle_diameter = item.archive.nozzle_diameter
+        response.sliced_for_model = item.archive.sliced_for_model
         if item.plate_id:
             archive_path = settings.base_dir / item.archive.file_path
             if archive_path.exists():
@@ -232,10 +237,15 @@ def _enrich_response(item: PrintQueueItem) -> PrintQueueItemResponse:
         if not response.library_file_name:
             response.library_file_name = item.library_file.filename
         response.library_file_thumbnail = item.library_file.thumbnail_path
-        # Get print time from library file metadata if no archive
+        # Get metadata from library file if no archive
         if not item.archive and item.library_file.file_metadata:
             response.print_time_seconds = item.library_file.file_metadata.get("print_time_seconds")
             response.filament_used_grams = item.library_file.file_metadata.get("filament_used_grams")
+            response.filament_type = item.library_file.file_metadata.get("filament_type")
+            response.filament_color = item.library_file.file_metadata.get("filament_color")
+            response.layer_height = item.library_file.file_metadata.get("layer_height")
+            response.nozzle_diameter = item.library_file.file_metadata.get("nozzle_diameter")
+            response.sliced_for_model = item.library_file.file_metadata.get("sliced_for_model")
         if item.plate_id:
             lib_path = Path(item.library_file.file_path)
             library_file_path = lib_path if lib_path.is_absolute() else settings.base_dir / item.library_file.file_path

+ 5 - 0
backend/app/schemas/print_queue.py

@@ -101,6 +101,11 @@ class PrintQueueItemResponse(BaseModel):
     printer_name: str | None = None
     print_time_seconds: int | None = None  # Estimated print time from archive or library file
     filament_used_grams: float | None = None  # Estimated print weight from archive or library file
+    filament_type: str | None = None  # e.g. "PLA", "PETG" (from archive/library file)
+    filament_color: str | None = None  # e.g. "#FFFFFF" (from archive/library file)
+    layer_height: float | None = None  # e.g. 0.2 (from archive/library file)
+    nozzle_diameter: float | None = None  # e.g. 0.4 (from archive/library file)
+    sliced_for_model: str | None = None  # e.g. "P1S" (from archive/library file)
 
     # User tracking (Issue #206)
     created_by_id: int | None = None