refactor(#778): 统一Storage接口,定义StoragePort+SharedStorageService作为唯一入口 #794
Reference in New Issue
Block a user
Delete Branch "refactor/unified-storage-interface"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
背景
代码质量专项P1:3份Storage实现分散(SharedStorageService/oss_helpers/OSSStorageService),接口不统一,能力不共享。
改动
packages/ports/storage_port.py→ StoragePort 抽象接口(12个核心方法)upload_file_smart()大文件分片上传+超时保护+并发线程(从oss_helpers合并)download_asset()自动识别URL/存储键,HTTP+SDK双路径下载resolve_asset_path()/resolve_asset_ids_to_paths()素材路径解析+缓存+安全校验normalize_storage_key()公开方法connect_timeout=10s防TCP握手挂死验证
Issue
#778
d2023a256dtocfc7563520cfc7563520tob5bc22834c代码审查结果 - PR #794
⚠️ 问题(3个需要修改)
StoragePort接口定义download_file返回类型为bool(成功/失败),但SharedStorageService实现中返回类型为None,且失败时抛出异常而非返回 False。这会导致依赖接口进行类型判断的调用方出错。upload_file_smart存在资源泄漏风险。finished为 False)时,函数返回 None,但后台线程仍在继续上传文件(因为是 daemon 线程且未做中断处理)。这会导致“僵尸”上传任务持续占用带宽和文件句柄,直到进程结束或上传完成。file_or_path.seek(0)。如果传入的是不可回退的流(如网络流或管道),会抛出io.UnsupportedOperation异常。应增加seekable检查或捕获异常。💡 建议(2个可选)
requests库的导入做容错处理。oss2做了ImportError处理,但requests是直接导入的。如果环境未安装requests,会导致模块加载失败。建议保持一致性,添加 try-except 或确保其在依赖列表中。create_direct_upload_post中的 Content-Type 校验逻辑可优化。content_type.split("/", 1)[0] + "/"在 Content-Type 为 "image"(无斜杠)时会生成 "image/",这虽然符合 OSS starts-with 逻辑,但语义上略显模糊。建议明确校验格式或补充注释说明此行为。✅ 格式检查通过 | ❌ 逻辑审查需修改 | ⚠️ 建议关注性能
🤖 由 AI 代码审查机器人自动生成 | 2026-07-24 03:07:06 | 模型:
🗑️ 预览环境已清理
PR #794 已关闭或合并,对应的预览环境已被清理。