diff --git a/api/apps/minio_app.py b/api/apps/minio_app.py index f5c15f1..41c9b13 100644 --- a/api/apps/minio_app.py +++ b/api/apps/minio_app.py @@ -1,10 +1,12 @@ import os +from flask import jsonify + @manager.route("/endpoint", methods=["GET"]) # noqa: F821 -# @login_required def minio(): - """ - Constructs the MinIO endpoint URL based on environment variables. - """ - return os.getenv("MINIO_VISIT_HOST", "localhost") + ":" + os.getenv("MINIO_PORT", "9000") + "/" + host = os.getenv("MINIO_VISIT_HOST", "localhost") + if not host.startswith("http"): + host = "http://" + host + port = os.getenv("MINIO_PORT", "9000") + return jsonify({"url": f"{host}:{port}/"}) diff --git a/web/.env b/web/.env index 50118e1..26f6574 100644 --- a/web/.env +++ b/web/.env @@ -1,3 +1 @@ -PORT=9222 -MINIO_VISIT_HOST=localhost -MINIO_PORT=9000 \ No newline at end of file +PORT=9222 \ No newline at end of file diff --git a/web/src/components/chunk_image/index.tsx b/web/src/components/chunk_image/index.tsx index f490807..b3c8253 100644 --- a/web/src/components/chunk_image/index.tsx +++ b/web/src/components/chunk_image/index.tsx @@ -17,13 +17,17 @@ const ChunkImage = ({ id, className, ...props }: IImage) => { const [imgSrc, setImgSrc] = useState(''); useEffect(() => { - fetch(api.minio_endpoint) - .then((res) => res.text()) - .catch(() => 'http://localhost:9000') - .then((minioUrl) => { - console.log('Minio URL:', minioUrl); - setImgSrc(`${minioUrl}/${id}`); - }); + const getMinioUrl = async () => { + try { + const res = await fetch(api.minio_endpoint); + const data = await res.json(); + setImgSrc(`${data.url}${id}`); + } catch (err) { + setImgSrc(`http://localhost:9000/${id}`); + } + }; + + getMinioUrl(); }, [setImgSrc, id]); return (