提交
This commit is contained in:
1 parent
e59b2aa6cb
commit
eccefc6650
63 files changed
+13267
-11330
No files matched your search
@@ -224,7 +224,7 @@ def register_contract_routes(router):
|
||||
tenant_no = get_tenant_no(db, _user)
|
||||
user_info = crm_user_info(_user)
|
||||
id_list = [x.strip() for x in ids.split(",") if x.strip()]
|
||||
soft_delete_contracts(db, id_list, tenant_no=tenant_no)
|
||||
soft_delete_contracts(db, id_list, tenant_no=tenant_no, user_info=user_info)
|
||||
return success_response(None, message="删除成功")
|
||||
except ValueError as e:
|
||||
return error_response(400, str(e))
|
||||
|
||||
@@ -196,7 +196,7 @@ def register_quote_routes(router):
|
||||
try:
|
||||
tenant_no = get_tenant_no(db, _user)
|
||||
user_info = crm_user_info(_user)
|
||||
soft_delete_quotes(db, body.ids, tenant_no=tenant_no)
|
||||
soft_delete_quotes(db, body.ids, tenant_no=tenant_no, user_info=user_info)
|
||||
return success_response(None, message="删除成功")
|
||||
except ValueError as e:
|
||||
return error_response(400, str(e))
|
||||
@@ -598,7 +598,7 @@ def register_quote_routes(router):
|
||||
try:
|
||||
tenant_no = get_tenant_no(db, _user)
|
||||
user_info = crm_user_info(_user)
|
||||
soft_delete_quote_products(db, body.ids, tenant_no=tenant_no)
|
||||
soft_delete_quote_products(db, body.ids, tenant_no=tenant_no, user_info=user_info)
|
||||
return success_response(None, message="删除成功")
|
||||
except ValueError as e:
|
||||
return error_response(400, str(e))
|
||||
|
||||
@@ -91,6 +91,8 @@ class Settings(BaseSettings):
|
||||
MINIO_SECRET_KEY: str = ""
|
||||
MINIO_BUCKET: str = ""
|
||||
MINIO_SECURE: bool = False
|
||||
# 浏览器可访问的公开前缀(建议 HTTPS 同域反代,如 https://w.shanxiachem.com/ruoyi)。
|
||||
# 配置后:普通 get_url 用此前缀;预签名预览/下载按该主机签发(避免 HTTPS 页 Mixed Content)。
|
||||
MINIO_BASE_URL: str = ""
|
||||
|
||||
# 微信支付配置 (生产环境必需)
|
||||
|
||||
@@ -23,8 +23,8 @@ import uuid
|
||||
import base64
|
||||
from io import BytesIO
|
||||
from datetime import datetime, timedelta
|
||||
from urllib.parse import quote
|
||||
from typing import Optional, BinaryIO
|
||||
from urllib.parse import quote, urlparse
|
||||
from typing import Any, Optional, BinaryIO
|
||||
from pathlib import Path
|
||||
|
||||
from app.core.config import settings
|
||||
@@ -280,9 +280,33 @@ class MinIOStorage(BaseStorage):
|
||||
else:
|
||||
scheme = "https" if settings.MINIO_SECURE else "http"
|
||||
self.base_url = f"{scheme}://{settings.MINIO_ENDPOINT}/{self.bucket_name}"
|
||||
# 预签名给浏览器用:优先按 MINIO_BASE_URL 的主机签发,上传/删除仍走内网 client
|
||||
self._presign_client = self._build_presign_client(Minio)
|
||||
except ImportError:
|
||||
raise ImportError("请安装 MinIO SDK: pip install minio")
|
||||
|
||||
def _build_presign_client(self, minio_cls: Any) -> Any:
|
||||
"""从 MINIO_BASE_URL 解析公网 endpoint;未配置或与内网相同时复用 self.client。"""
|
||||
raw = (settings.MINIO_BASE_URL or "").strip()
|
||||
if not raw:
|
||||
return self.client
|
||||
parsed = urlparse(raw if "://" in raw else f"https://{raw}")
|
||||
host = parsed.hostname
|
||||
if not host:
|
||||
return self.client
|
||||
endpoint = f"{host}:{parsed.port}" if parsed.port else host
|
||||
secure = (parsed.scheme or "https").lower() != "http"
|
||||
if endpoint == settings.MINIO_ENDPOINT and secure == bool(settings.MINIO_SECURE):
|
||||
return self.client
|
||||
# region 固定:预签名不必经公网反代做 GetBucketLocation(反代常只放行 /bucket/object)
|
||||
return minio_cls(
|
||||
endpoint,
|
||||
access_key=settings.MINIO_ACCESS_KEY,
|
||||
secret_key=settings.MINIO_SECRET_KEY,
|
||||
secure=secure,
|
||||
region="us-east-1",
|
||||
)
|
||||
|
||||
def _generate_filename(self, filename: str) -> str:
|
||||
"""生成唯一文件名"""
|
||||
ext = os.path.splitext(filename)[1] or ""
|
||||
@@ -354,7 +378,7 @@ class MinIOStorage(BaseStorage):
|
||||
ascii_name = name.encode("ascii", "ignore").decode() or "download"
|
||||
encoded = quote(name, safe="")
|
||||
disposition = f'attachment; filename="{ascii_name}"; filename*=UTF-8\'\'{encoded}'
|
||||
return self.client.presigned_get_object(
|
||||
return self._presign_client.presigned_get_object(
|
||||
bucket_name=self.bucket_name,
|
||||
object_name=key,
|
||||
expires=timedelta(seconds=expires_seconds),
|
||||
@@ -369,7 +393,7 @@ class MinIOStorage(BaseStorage):
|
||||
response_headers: dict[str, str] = {"response-content-disposition": "inline"}
|
||||
if key.lower().endswith(".pdf"):
|
||||
response_headers["response-content-type"] = "application/pdf"
|
||||
return self.client.presigned_get_object(
|
||||
return self._presign_client.presigned_get_object(
|
||||
bucket_name=self.bucket_name,
|
||||
object_name=key,
|
||||
expires=timedelta(seconds=expires_seconds),
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"""报销附件存储适配 — 复用门户 app.core.storage,对外保持 bx 协议。"""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import timedelta
|
||||
from io import BytesIO
|
||||
from pathlib import Path
|
||||
|
||||
@@ -58,11 +57,8 @@ def get_preview_url(file_path: str, *, expires_seconds: int = 3600) -> str:
|
||||
if not key:
|
||||
return ""
|
||||
if isinstance(store, MinIOStorage):
|
||||
return store.client.presigned_get_object(
|
||||
bucket_name=store.bucket_name,
|
||||
object_name=key,
|
||||
expires=timedelta(seconds=expires_seconds),
|
||||
)
|
||||
# 走 MinIOStorage.presigned_preview_url(按 MINIO_BASE_URL 公网域名签发)
|
||||
return store.presigned_preview_url(key, expires_seconds=expires_seconds)
|
||||
return store.get_url(key)
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user