From 294aca62c98faa9fd456697aa1884d81e8222a28 Mon Sep 17 00:00:00 2001 From: space Date: Sun, 1 Mar 2026 16:40:03 +0100 Subject: [PATCH] fix: improve image extension handling and error reporting in upload functions --- .gitea/workflows/ci.yml | 2 +- functions/control/main.py | 15 ++++++++++----- mobile/src/pages/datacards.tsx | 2 +- mobile/src/pages/settings.tsx | 2 +- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 4434ffa..804ac5e 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -52,5 +52,5 @@ jobs: uses: actions/upload-artifact@v4 with: name: android-preview-build.zip - path: mobile/app-build/* + path: mobile/app-build if-no-files-found: error diff --git a/functions/control/main.py b/functions/control/main.py index c376069..073e8eb 100644 --- a/functions/control/main.py +++ b/functions/control/main.py @@ -124,11 +124,16 @@ def main(args): if not image_b64: continue image_bytes = base64.b64decode(image_b64) - file_name = f"tv-rotator-{ts}-{idx}.{ext}" - MINIO_CLIENT.put_object( - BUCKET, file_name, io.BytesIO(image_bytes), len(image_bytes), - content_type=f"image/{ext}", - ) + # Normalise ext: strip any URI junk, fall back to jpg + safe_ext = ext if ext and len(ext) <= 5 and ext.isalnum() else "jpg" + file_name = f"tv-rotator-{ts}-{idx}.{safe_ext}" + try: + MINIO_CLIENT.put_object( + BUCKET, file_name, io.BytesIO(image_bytes), len(image_bytes), + content_type=f"image/{safe_ext}", + ) + except Exception as e: + return {"status": "error", "message": f"MinIO upload failed: {e}"} public_url = f"https://content2.reversed.dev/{BUCKET}/{file_name}" urls.append(public_url) return {"status": "success", "urls": urls} diff --git a/mobile/src/pages/datacards.tsx b/mobile/src/pages/datacards.tsx index 4c8f2a2..f14e10a 100644 --- a/mobile/src/pages/datacards.tsx +++ b/mobile/src/pages/datacards.tsx @@ -776,7 +776,7 @@ function ImageRotatorFields({ form, onChange, onUrlsChange }: ImageRotatorFields if (result.canceled) return; const asset = result.assets[0]; if (!asset.base64) { Alert.alert("Error", "Could not read image data."); return; } - const ext = asset.uri.split(".").pop()?.toLowerCase() ?? "jpg"; + const ext = (asset.mimeType?.split("/")[1] ?? asset.uri.split(".").pop() ?? "jpg").toLowerCase(); setUploading(true); try { const res = await fetch(`${BASE_URL}/push_upload_images`, { diff --git a/mobile/src/pages/settings.tsx b/mobile/src/pages/settings.tsx index 7db40f6..078fb9f 100644 --- a/mobile/src/pages/settings.tsx +++ b/mobile/src/pages/settings.tsx @@ -63,7 +63,7 @@ export function SettingsPage() { return; } - const ext = (asset.uri.split(".").pop() ?? "jpg").toLowerCase(); + const ext = (asset.mimeType?.split("/")[1] ?? asset.uri.split(".").pop() ?? "jpg").toLowerCase(); setPendingUri(asset.uri); setPendingBase64(asset.base64 ?? null); setPendingExt(ext);