refactor: 重构 MinIO URL 构造方式
- 更新 MinIO URL 构造逻辑,添加 http 协议头 - 移除 web/.env 中的 MINIO_VISIT_HOST 和 MINIO_PORT 配置 - 修改前端 ChunkImage 组件,使用 JSON 格式解析 MinIO URL
This commit is contained in:
parent
59d5ca5c95
commit
b8b4b441d2
|
@ -1,10 +1,12 @@
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from flask import jsonify
|
||||||
|
|
||||||
|
|
||||||
@manager.route("/endpoint", methods=["GET"]) # noqa: F821
|
@manager.route("/endpoint", methods=["GET"]) # noqa: F821
|
||||||
# @login_required
|
|
||||||
def minio():
|
def minio():
|
||||||
"""
|
host = os.getenv("MINIO_VISIT_HOST", "localhost")
|
||||||
Constructs the MinIO endpoint URL based on environment variables.
|
if not host.startswith("http"):
|
||||||
"""
|
host = "http://" + host
|
||||||
return os.getenv("MINIO_VISIT_HOST", "localhost") + ":" + os.getenv("MINIO_PORT", "9000") + "/"
|
port = os.getenv("MINIO_PORT", "9000")
|
||||||
|
return jsonify({"url": f"{host}:{port}/"})
|
||||||
|
|
|
@ -17,13 +17,17 @@ const ChunkImage = ({ id, className, ...props }: IImage) => {
|
||||||
const [imgSrc, setImgSrc] = useState<string>('');
|
const [imgSrc, setImgSrc] = useState<string>('');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetch(api.minio_endpoint)
|
const getMinioUrl = async () => {
|
||||||
.then((res) => res.text())
|
try {
|
||||||
.catch(() => 'http://localhost:9000')
|
const res = await fetch(api.minio_endpoint);
|
||||||
.then((minioUrl) => {
|
const data = await res.json();
|
||||||
console.log('Minio URL:', minioUrl);
|
setImgSrc(`${data.url}${id}`);
|
||||||
setImgSrc(`${minioUrl}/${id}`);
|
} catch (err) {
|
||||||
});
|
setImgSrc(`http://localhost:9000/${id}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
getMinioUrl();
|
||||||
}, [setImgSrc, id]);
|
}, [setImgSrc, id]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
Loading…
Reference in New Issue