|
|
@@ -182,7 +182,12 @@ async def get_public_scans():
|
|
|
WHERE is_public = TRUE
|
|
|
ORDER BY created_at DESC
|
|
|
"""
|
|
|
- return db.execute_query(query)
|
|
|
+ scans = db.execute_query(query)
|
|
|
+ scans_dir = os.path.join(config.UPLOAD_DIR, "scans")
|
|
|
+ for scan in scans:
|
|
|
+ photo_path = os.path.join(scans_dir, scan["folder_name"], "photo.webp")
|
|
|
+ scan["has_photo"] = os.path.exists(photo_path)
|
|
|
+ return scans
|
|
|
|
|
|
@router.get("/admin/scans")
|
|
|
async def admin_get_all_scans(admin: dict = Depends(require_admin)):
|
|
|
@@ -193,7 +198,12 @@ async def admin_get_all_scans(admin: dict = Depends(require_admin)):
|
|
|
FROM portfolio_scans
|
|
|
ORDER BY created_at DESC
|
|
|
"""
|
|
|
- return db.execute_query(query)
|
|
|
+ scans = db.execute_query(query)
|
|
|
+ scans_dir = os.path.join(config.UPLOAD_DIR, "scans")
|
|
|
+ for scan in scans:
|
|
|
+ photo_path = os.path.join(scans_dir, scan["folder_name"], "photo.webp")
|
|
|
+ scan["has_photo"] = os.path.exists(photo_path)
|
|
|
+ return scans
|
|
|
|
|
|
@router.post("/admin/scans/upload-bundle")
|
|
|
async def admin_upload_scan_bundle(
|
|
|
@@ -257,6 +267,20 @@ async def admin_upload_scan_bundle(
|
|
|
if not os.path.exists(thumbnail_path):
|
|
|
raise HTTPException(status_code=400, detail="Invalid bundle: thumbnail.webp is missing")
|
|
|
|
|
|
+ # Check and convert original photograph if present
|
|
|
+ for ext in [".webp", ".png", ".jpg", ".jpeg"]:
|
|
|
+ p_path = os.path.join(dest_dir, f"photo{ext}")
|
|
|
+ if os.path.exists(p_path):
|
|
|
+ if ext != ".webp":
|
|
|
+ from PIL import Image
|
|
|
+ try:
|
|
|
+ with Image.open(p_path) as img:
|
|
|
+ img.save(os.path.join(dest_dir, "photo.webp"), "WEBP", quality=85)
|
|
|
+ os.remove(p_path)
|
|
|
+ except Exception as ex:
|
|
|
+ print(f"Failed to convert photo to WebP: {ex}")
|
|
|
+ break
|
|
|
+
|
|
|
# Insert DB record
|
|
|
query = """
|
|
|
INSERT INTO portfolio_scans (
|