feat: 添加文件下载响应生成方法,支持不同存储后端的下载处理

This commit is contained in:
2025-11-14 22:58:14 +08:00
parent ed845a3d9a
commit e404764ea9
3 changed files with 97 additions and 86 deletions

View File

@@ -208,3 +208,29 @@ class BaseStorage(ABC):
创建成功返回 True失败返回 False
"""
pass
def generate_download_response(self, key: str) -> Dict[str, Any]:
"""
生成文件下载响应
Args:
key: 对象键名(文件路径)
Returns:
包含下载信息的字典,包括:
- type: "redirect""content"
- url: 重定向URL当type为redirect时
- content: 文件内容当type为content时
- headers: HTTP响应头
- mimetype: MIME类型
"""
# 默认实现返回重定向URL
presigned = self.generate_presigned_url(key)
if presigned:
return {"type": "redirect", "url": presigned}
public_url = self.get_public_url(key)
if public_url:
return {"type": "redirect", "url": public_url}
return None