From 6bd8a67103a10f3aeff50edf86d284a2e6366352 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=AC=E5=8F=B8git?= <240241002@qq.com> Date: Thu, 16 Jul 2026 11:47:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=96=87=E4=BB=B6=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=94=AF=E6=8C=81=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E4=B8=8B=E8=BD=BD=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blueprints/api.py | 4 ++-- services/file_service.py | 7 ++++++- static/js/main.js | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/blueprints/api.py b/blueprints/api.py index 4b642ad..5debbad 100644 --- a/blueprints/api.py +++ b/blueprints/api.py @@ -57,9 +57,9 @@ def get_config(): def upload(): try: files = request.files.getlist("images") - img_urls = handle_file_uploads(files) + img_urls, download_urls = handle_file_uploads(files) system_logger.info(f"用户上传文件: {len(files)} 张", user_id=session.get("user_id")) - return jsonify({"urls": img_urls}) + return jsonify({"urls": img_urls, "download_urls": download_urls}) except Exception as e: return jsonify({"error": str(e)}), 500 diff --git a/services/file_service.py b/services/file_service.py index d35b638..ffc3c9c 100644 --- a/services/file_service.py +++ b/services/file_service.py @@ -11,6 +11,7 @@ from utils import get_proxied_url def handle_file_uploads(files): """处理文件上传到 MinIO""" img_urls = [] + download_urls = [] for f in files: ext = os.path.splitext(f.filename)[1] filename = f"{uuid.uuid4().hex}{ext}" @@ -19,7 +20,11 @@ def handle_file_uploads(files): ExtraArgs={"ContentType": f.content_type} ) img_urls.append(f"{Config.MINIO['public_url']}{quote(filename)}") - return img_urls + endpoint = Config.MINIO["endpoint"].rstrip("/") + bucket = quote(Config.MINIO["bucket"], safe="") + object_key = quote(filename, safe="/") + download_urls.append(f"{endpoint}/{bucket}/{object_key}") + return img_urls, download_urls def get_remote_file_stream(url): """获取远程文件的流""" diff --git a/static/js/main.js b/static/js/main.js index f5bb531..f2308dd 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -730,7 +730,7 @@ document.getElementById('submitBtn').onclick = async () => { throw new Error(uploadResult.error || '参考图上传失败'); } - image = (uploadResult.urls || []).map(url => new URL(url, window.location.origin).href); + image = uploadResult.download_urls || []; if (image.length !== uploadedFiles.length) { throw new Error('部分参考图上传失败'); }