mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-18 21:47:39 +02:00
Fix external folder scan 500 on 3MF files (#846)
scan_external_folder stored raw 3MF metadata containing _thumbnail_data bytes directly in the JSON column, causing a serialization error. Applied the same clean_metadata() pattern used by upload/zip extraction and removed the call to the non-existent parser.extract_thumbnail().
This commit is contained in:
@@ -839,16 +839,33 @@ async def scan_external_folder(
|
||||
if file_type == "3mf":
|
||||
try:
|
||||
parser = ThreeMFParser(str(filepath))
|
||||
meta = parser.parse()
|
||||
if meta:
|
||||
file_metadata = meta
|
||||
thumb_data = parser.extract_thumbnail()
|
||||
if thumb_data:
|
||||
thumb_dir = get_library_thumbnails_dir()
|
||||
thumb_filename = f"{uuid.uuid4().hex}.png"
|
||||
thumb_full = thumb_dir / thumb_filename
|
||||
thumb_full.write_bytes(thumb_data)
|
||||
thumbnail_path = to_relative_path(thumb_full)
|
||||
raw_metadata = parser.parse()
|
||||
if raw_metadata:
|
||||
# Extract thumbnail before cleaning metadata
|
||||
thumb_data = raw_metadata.get("_thumbnail_data")
|
||||
thumbnail_ext = raw_metadata.get("_thumbnail_ext", ".png")
|
||||
if thumb_data:
|
||||
thumb_dir = get_library_thumbnails_dir()
|
||||
thumb_filename = f"{uuid.uuid4().hex}{thumbnail_ext}"
|
||||
thumb_full = thumb_dir / thumb_filename
|
||||
thumb_full.write_bytes(thumb_data)
|
||||
thumbnail_path = to_relative_path(thumb_full)
|
||||
|
||||
# Clean metadata - remove non-JSON-serializable data (bytes, etc.)
|
||||
def clean_metadata(obj):
|
||||
if isinstance(obj, dict):
|
||||
return {
|
||||
k: clean_metadata(v)
|
||||
for k, v in obj.items()
|
||||
if not isinstance(v, bytes) and k not in ("_thumbnail_data", "_thumbnail_ext")
|
||||
}
|
||||
elif isinstance(obj, list):
|
||||
return [clean_metadata(i) for i in obj if not isinstance(i, bytes)]
|
||||
elif isinstance(obj, bytes):
|
||||
return None
|
||||
return obj
|
||||
|
||||
file_metadata = clean_metadata(raw_metadata)
|
||||
except Exception as e:
|
||||
logger.debug("Failed to extract metadata from external 3mf %s: %s", filepath, e)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user