upload images
This commit is contained in:
@@ -1,7 +1,19 @@
|
||||
import base64
|
||||
import io
|
||||
import json
|
||||
import time
|
||||
from minio import Minio
|
||||
|
||||
DEFAULT_STATE = {"text": "", "image_url": ""}
|
||||
|
||||
MINIO_CLIENT = Minio(
|
||||
"content2.reversed.dev",
|
||||
access_key="tv-control",
|
||||
secret_key="0gEjOlnVAECrqJx5Nd77y7Hhouc5faVf0WttjcRH",
|
||||
secure=True,
|
||||
)
|
||||
BUCKET = "tv-control"
|
||||
|
||||
def _read_state():
|
||||
try:
|
||||
with open("/app/state.json", "r") as f:
|
||||
@@ -25,11 +37,18 @@ def main(args):
|
||||
current["text"] = body.get("text", "")
|
||||
_write_state(current)
|
||||
return {"status": "success"}
|
||||
elif route == "push_image_url":
|
||||
elif route == "push_image":
|
||||
image_b64 = body.get("image_b64", "")
|
||||
image_bytes = base64.b64decode(image_b64)
|
||||
file_name = f"tv-image-{int(time.time() * 1000)}.jpg"
|
||||
MINIO_CLIENT.put_object(
|
||||
BUCKET, file_name, io.BytesIO(image_bytes), len(image_bytes), content_type="image/jpeg"
|
||||
)
|
||||
public_url = f"https://content2.reversed.dev/{BUCKET}/{file_name}"
|
||||
current = _read_state()
|
||||
current["image_url"] = body.get("image_url", "")
|
||||
current["image_url"] = public_url
|
||||
_write_state(current)
|
||||
return {"status": "success"}
|
||||
return {"status": "success", "image_url": public_url}
|
||||
else:
|
||||
return {"status": "error", "message": "Unknown push route"}
|
||||
elif route.startswith("pull"):
|
||||
|
||||
Reference in New Issue
Block a user