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
|
||||
|
||||
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}/"})
|
||||
|
|
|
@ -17,13 +17,17 @@ const ChunkImage = ({ id, className, ...props }: IImage) => {
|
|||
const [imgSrc, setImgSrc] = useState<string>('');
|
||||
|
||||
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 (
|
||||
|
|
Loading…
Reference in New Issue