后台更新 服务优化
Build Backend JAR / build (push) Failing after 16m54s

This commit is contained in:
supernijia
2026-08-11 14:50:21 +08:00
parent 38216a1885
commit 5b1ccad40e
24 changed files with 1623 additions and 502 deletions
+40 -6
View File
@@ -34,7 +34,7 @@ from werkzeug.security import generate_password_hash
from utils.db import get_db
from utils.auth import admin_required, login_required, get_current_admin_role
from ali_oss import upload_file as oss_upload_file
from ali_oss import upload_fileobj as oss_upload_fileobj
try:
from config import bucket_path, backend_java_base_url
@@ -47,6 +47,10 @@ _backend_java_session_local = threading.local()
_internal_token_lock = threading.Lock()
IMAGE_VIDEO_DATA_PERMISSION_KEY = 'admin_image_video_task_data'
SHOP_DATA_CRAWL_DATA_PERMISSION_KEY = 'admin_shop_data_crawl_task_data'
try:
VERSION_UPLOAD_MAX_BYTES = int(os.environ.get('VERSION_UPLOAD_MAX_BYTES', str(512 * 1024 * 1024)))
except ValueError:
VERSION_UPLOAD_MAX_BYTES = 512 * 1024 * 1024
ADMIN_MENU_ACCESS_CONFIG = {
'dedupe-total-data': {
@@ -2723,13 +2727,28 @@ def upload_version():
return jsonify({'success': False, 'error': '请选择要上传的 zip 压缩包'})
if not (file_storage.filename or '').lower().endswith('.zip'):
return jsonify({'success': False, 'error': '仅支持 .zip 格式'})
conn = None
try:
file_content = file_storage.read()
if not file_content:
if file_storage.content_length and file_storage.content_length > VERSION_UPLOAD_MAX_BYTES:
return jsonify({'success': False, 'error': '文件超过允许的大小限制'})
file_stream = file_storage.stream
stream_size = file_storage.content_length
try:
file_stream.seek(0)
file_stream.seek(0, os.SEEK_END)
stream_size = file_stream.tell()
file_stream.seek(0)
except (AttributeError, OSError, TypeError, ValueError):
try:
file_stream.seek(0)
except (AttributeError, OSError, TypeError, ValueError):
pass
if stream_size == 0:
return jsonify({'success': False, 'error': '文件为空'})
safe_key = _safe_version_key(version)
key = f"{bucket_path}versions/{safe_key}.zip"
file_url = oss_upload_file(file_content, key)
file_url = oss_upload_fileobj(file_stream, key, VERSION_UPLOAD_MAX_BYTES,
'application/zip')
conn = get_db()
with conn.cursor() as cur:
cur.execute(
@@ -2737,7 +2756,6 @@ def upload_version():
(version, file_url)
)
conn.commit()
conn.close()
return jsonify({
'success': True,
'version': version,
@@ -2747,6 +2765,12 @@ def upload_version():
except Exception as e:
traceback.print_exc()
return jsonify({'success': False, 'error': str(e)})
finally:
if conn is not None:
try:
conn.close()
except Exception:
pass
# ---------- 店铺密钥管理 ----------
@@ -2972,6 +2996,7 @@ def export_dedupe_total_data():
url,
params=params,
headers={'X-Internal-Token': _resolve_internal_token()},
stream=True,
timeout=60,
)
except requests.RequestException:
@@ -2982,14 +3007,23 @@ def export_dedupe_total_data():
error = data.get('message') or data.get('error') or '导出失败'
except ValueError:
error = '导出失败'
resp.close()
return jsonify({'success': False, 'error': error}), resp.status_code
headers = {}
disposition = resp.headers.get('Content-Disposition')
if disposition:
headers['Content-Disposition'] = disposition
def generate():
try:
for chunk in resp.iter_content(chunk_size=1024 * 1024):
if chunk:
yield chunk
finally:
resp.close()
return Response(
resp.content,
stream_with_context(generate()),
status=resp.status_code,
headers=headers,
content_type=resp.headers.get(