Преглед изворни кода

Add printer_model to 18 FTP call sites for A1/A1 Mini, PS1 compatibility

Several FTP operations (file browser, timelapse scan, storage info,
cover download, skip objects, etc.) were missing the printer_model
parameter. Without it, A1/A1 Mini and PS1 printers can't use the prot_p/prot_c
auto-detection and fallback logic, causing FTP failures on these models
when the mode cache isn't already populated.
maziggy пре 3 месеци
родитељ
комит
aa3482e48b

+ 6 - 2
backend/app/api/routes/archives.py

@@ -1186,7 +1186,9 @@ async def scan_timelapse(
     files = []
     for timelapse_path in ["/timelapse", "/timelapse/video"]:
         try:
-            files = await list_files_async(printer.ip_address, printer.access_code, timelapse_path)
+            files = await list_files_async(
+                printer.ip_address, printer.access_code, timelapse_path, printer_model=printer.model
+            )
             if files:
                 break
         except Exception:
@@ -1406,7 +1408,9 @@ async def select_timelapse(
     remote_path = None
     for timelapse_dir in ["/timelapse", "/timelapse/video"]:
         try:
-            files = await list_files_async(printer.ip_address, printer.access_code, timelapse_dir)
+            files = await list_files_async(
+                printer.ip_address, printer.access_code, timelapse_dir, printer_model=printer.model
+            )
             for f in files:
                 if f.get("name") == filename:
                     remote_path = f.get("path") or f"{timelapse_dir}/{filename}"

+ 16 - 9
backend/app/api/routes/printers.py

@@ -637,6 +637,7 @@ async def get_printer_cover(
                 printer.access_code,
                 remote_paths,
                 temp_path,
+                printer_model=printer.model,
             )
             if downloaded:
                 break
@@ -750,7 +751,7 @@ async def list_printer_files(
     if not printer:
         raise HTTPException(404, "Printer not found")
 
-    files = await list_files_async(printer.ip_address, printer.access_code, path)
+    files = await list_files_async(printer.ip_address, printer.access_code, path, printer_model=printer.model)
 
     # Add full path to each file
     for f in files:
@@ -775,7 +776,7 @@ async def download_printer_file(
     if not printer:
         raise HTTPException(404, "Printer not found")
 
-    data = await download_file_bytes_async(printer.ip_address, printer.access_code, path)
+    data = await download_file_bytes_async(printer.ip_address, printer.access_code, path, printer_model=printer.model)
     if data is None:
         raise HTTPException(404, f"File not found: {path}")
 
@@ -819,7 +820,7 @@ async def get_printer_file_gcode(
     if not printer:
         raise HTTPException(404, "Printer not found")
 
-    data = await download_file_bytes_async(printer.ip_address, printer.access_code, path)
+    data = await download_file_bytes_async(printer.ip_address, printer.access_code, path, printer_model=printer.model)
     if data is None:
         raise HTTPException(404, f"File not found: {path}")
 
@@ -871,7 +872,7 @@ async def get_printer_file_plates(
             "is_multi_plate": False,
         }
 
-    data = await download_file_bytes_async(printer.ip_address, printer.access_code, path)
+    data = await download_file_bytes_async(printer.ip_address, printer.access_code, path, printer_model=printer.model)
     if data is None:
         raise HTTPException(404, f"File not found: {path}")
 
@@ -1102,7 +1103,7 @@ async def get_printer_file_plate_thumbnail(
     if not printer:
         raise HTTPException(404, "Printer not found")
 
-    data = await download_file_bytes_async(printer.ip_address, printer.access_code, path)
+    data = await download_file_bytes_async(printer.ip_address, printer.access_code, path, printer_model=printer.model)
     if data is None:
         raise HTTPException(404, f"File not found: {path}")
 
@@ -1142,7 +1143,9 @@ async def download_printer_files_as_zip(
     with zipfile.ZipFile(zip_buffer, "w", zipfile.ZIP_DEFLATED) as zf:
         for path in paths:
             try:
-                data = await download_file_bytes_async(printer.ip_address, printer.access_code, path)
+                data = await download_file_bytes_async(
+                    printer.ip_address, printer.access_code, path, printer_model=printer.model
+                )
                 if data:
                     filename = path.split("/")[-1]
                     zf.writestr(filename, data)
@@ -1176,7 +1179,7 @@ async def delete_printer_file(
     if not printer:
         raise HTTPException(404, "Printer not found")
 
-    success = await delete_file_async(printer.ip_address, printer.access_code, path)
+    success = await delete_file_async(printer.ip_address, printer.access_code, path, printer_model=printer.model)
     if not success:
         raise HTTPException(500, f"Failed to delete file: {path}")
 
@@ -1195,7 +1198,7 @@ async def get_printer_storage(
     if not printer:
         raise HTTPException(404, "Printer not found")
 
-    storage_info = await get_storage_info_async(printer.ip_address, printer.access_code)
+    storage_info = await get_storage_info_async(printer.ip_address, printer.access_code, printer_model=printer.model)
 
     return storage_info or {"used_bytes": None, "free_bytes": None}
 
@@ -1919,7 +1922,11 @@ async def get_printable_objects(
 
             try:
                 downloaded = await download_file_try_paths_async(
-                    printer.ip_address, printer.access_code, remote_paths, temp_path
+                    printer.ip_address,
+                    printer.access_code,
+                    remote_paths,
+                    temp_path,
+                    printer_model=printer.model,
                 )
                 if downloaded and temp_path.exists():
                     with open(temp_path, "rb") as f:

+ 13 - 3
backend/app/main.py

@@ -1096,7 +1096,9 @@ async def on_print_start(printer_id: int, data: dict):
                 if downloaded_filename:
                     break
                 try:
-                    dir_files = await list_files_async(printer.ip_address, printer.access_code, search_dir)
+                    dir_files = await list_files_async(
+                        printer.ip_address, printer.access_code, search_dir, printer_model=printer.model
+                    )
                     threemf_files = [f.get("name") for f in dir_files if f.get("name", "").endswith(".3mf")]
                     if threemf_files:
                         logger.info(
@@ -1120,6 +1122,8 @@ async def on_print_start(printer_id: int, data: dict):
                                     printer.access_code,
                                     f"{search_dir}/{fname}",
                                     temp_path,
+                                    socket_timeout=ftp_timeout,
+                                    printer_model=printer.model,
                                     max_retries=ftp_retry_count,
                                     retry_delay=ftp_retry_delay,
                                     operation_name=f"Download 3MF from {search_dir}/{fname}",
@@ -1130,6 +1134,8 @@ async def on_print_start(printer_id: int, data: dict):
                                     printer.access_code,
                                     f"{search_dir}/{fname}",
                                     temp_path,
+                                    socket_timeout=ftp_timeout,
+                                    printer_model=printer.model,
                                 )
                             if downloaded:
                                 downloaded_filename = fname
@@ -1413,7 +1419,9 @@ async def _scan_for_timelapse_with_retries(archive_id: int):
                 found_path = None
                 for timelapse_path in ["/timelapse", "/timelapse/video", "/record", "/recording"]:
                     try:
-                        found_files = await list_files_async(printer.ip_address, printer.access_code, timelapse_path)
+                        found_files = await list_files_async(
+                            printer.ip_address, printer.access_code, timelapse_path, printer_model=printer.model
+                        )
                         if found_files:
                             files = found_files
                             found_path = timelapse_path
@@ -1455,7 +1463,9 @@ async def _scan_for_timelapse_with_retries(archive_id: int):
                 # Since we KNOW timelapse was active (from MQTT), just grab the most recent file
                 remote_path = most_recent.get("path") or f"/timelapse/{file_name}"
                 logger.info("[TIMELAPSE] Downloading %s for archive %s", file_name, archive_id)
-                timelapse_data = await download_file_bytes_async(printer.ip_address, printer.access_code, remote_path)
+                timelapse_data = await download_file_bytes_async(
+                    printer.ip_address, printer.access_code, remote_path, printer_model=printer.model
+                )
 
                 if timelapse_data:
                     success = await service.attach_timelapse(archive_id, timelapse_data, file_name)

+ 1 - 0
backend/app/services/firmware_update.py

@@ -140,6 +140,7 @@ class FirmwareUpdateService:
                 storage_info = await get_storage_info_async(
                     printer.ip_address,
                     printer.access_code,
+                    printer_model=printer.model,
                 )
                 if storage_info and "free_bytes" in storage_info:
                     result["sd_card_free_space"] = storage_info["free_bytes"]