提交
This commit is contained in:
1 parent
f269a994f4
commit
93cd506a90
71 files changed
+8297
-2207
No files matched your search
@@ -24,6 +24,7 @@ from app.crud import express_company as express_company_svc
|
||||
from app.crud import menu as menu_svc
|
||||
from app.crud import role as role_svc
|
||||
from app.crud import user as user_svc
|
||||
from app.crud.collection_protocol import _lookup_attachment_by_url
|
||||
from app.models.models import BizAttachment, SysRole, SysUser
|
||||
from app.services.web_auth_roles import _map_role_name_to_web
|
||||
|
||||
@@ -1503,3 +1504,33 @@ async def upload_attachment(
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
return error_response(500, f"上传失败: {str(e)}")
|
||||
|
||||
|
||||
class AttachmentDownloadUrlBody(BaseModel):
|
||||
model_config = ConfigDict(populate_by_name=True)
|
||||
file_url: str = Field(..., alias="fileUrl")
|
||||
file_name: Optional[str] = Field(None, alias="fileName")
|
||||
|
||||
|
||||
@router.post("/attachment/download-url")
|
||||
async def attachment_download_url(
|
||||
body: AttachmentDownloadUrlBody,
|
||||
user: dict = Depends(require_admin_or_super_admin),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""返回带 Content-Disposition 的下载 URL,保证浏览器使用原始文件名。"""
|
||||
file_url = (body.file_url or "").strip()
|
||||
if not file_url:
|
||||
return error_response(400, "文件地址不能为空")
|
||||
tenant_no = _get_tenant_no(db, user)
|
||||
att = _lookup_attachment_by_url(db, file_url, tenant_no)
|
||||
download_name = (body.file_name or "").strip()
|
||||
if not download_name and att:
|
||||
download_name = (att.original_name or "").strip()
|
||||
if not download_name:
|
||||
download_name = file_url.rsplit("/", 1)[-1] or "download"
|
||||
try:
|
||||
url = storage.presigned_download_url(file_url, download_name)
|
||||
return success_response({"downloadUrl": url})
|
||||
except Exception as e:
|
||||
return error_response(500, f"获取下载链接失败: {str(e)}")
|
||||
Reference in new issue
Block a user