From b8b4b441d2fe013dab5e7bb32c1dad1f6ff40a67 Mon Sep 17 00:00:00 2001 From: zstar <65890619+zstar1003@users.noreply.github.com> Date: Tue, 10 Jun 2025 15:29:16 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=20MinIO=20URL=20?= =?UTF-8?q?=E6=9E=84=E9=80=A0=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 更新 MinIO URL 构造逻辑,添加 http 协议头 - 移除 web/.env 中的 MINIO_VISIT_HOST 和 MINIO_PORT 配置 - 修改前端 ChunkImage 组件,使用 JSON 格式解析 MinIO URL --- api/apps/minio_app.py | 12 +++++++----- web/.env | 4 +--- web/src/components/chunk_image/index.tsx | 18 +++++++++++------- 3 files changed, 19 insertions(+), 15 deletions(-) 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 (