feat: add functionality to upload multiple images to MinIO and return public URLs
This commit is contained in:
@@ -97,6 +97,27 @@ def main(args):
|
|||||||
current["data_cards"] = [c for c in current.get("data_cards", []) if c["id"] != card_id]
|
current["data_cards"] = [c for c in current.get("data_cards", []) if c["id"] != card_id]
|
||||||
_write_state(current)
|
_write_state(current)
|
||||||
return {"status": "success"}
|
return {"status": "success"}
|
||||||
|
elif route == "push_upload_images":
|
||||||
|
# Upload multiple images to MinIO; returns their public URLs (no state change)
|
||||||
|
images = body.get("images", [])
|
||||||
|
if not images:
|
||||||
|
return {"status": "error", "message": "No images provided"}
|
||||||
|
urls = []
|
||||||
|
ts = int(time.time() * 1000)
|
||||||
|
for idx, img in enumerate(images):
|
||||||
|
image_b64 = img.get("image_b64", "")
|
||||||
|
ext = img.get("ext", "jpg").lstrip(".")
|
||||||
|
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}",
|
||||||
|
)
|
||||||
|
public_url = f"https://content2.reversed.dev/{BUCKET}/{file_name}"
|
||||||
|
urls.append(public_url)
|
||||||
|
return {"status": "success", "urls": urls}
|
||||||
else:
|
else:
|
||||||
return {"status": "error", "message": "Unknown push route"}
|
return {"status": "error", "message": "Unknown push route"}
|
||||||
elif route.startswith("pull"):
|
elif route.startswith("pull"):
|
||||||
|
|||||||
Reference in New Issue
Block a user