| 28 | |
| 29 | |
| 30 | class FileStorageInterface: |
| 31 | |
| 32 | async def save_file(self, file: UploadFile, save_path: str): |
| 33 | """ |
| 34 | 保存文件 |
| 35 | """ |
| 36 | raise NotImplementedError |
| 37 | |
| 38 | async def delete_file(self, file_code: FileCodes): |
| 39 | """ |
| 40 | 删除文件 |
| 41 | """ |
| 42 | raise NotImplementedError |
| 43 | |
| 44 | async def get_file_url(self, file_code: FileCodes): |
| 45 | """ |
| 46 | 获取文件分享的url |
| 47 | |
| 48 | 如果服务不支持直接访问文件,可以通过服务器中转下载。 |
| 49 | 此时,此方法可以调用 utils.py 中的 `get_file_url` 方法,获取服务器中转下载的url |
| 50 | """ |
| 51 | raise NotImplementedError |
| 52 | |
| 53 | async def get_file_response(self, file_code: FileCodes): |
| 54 | """ |
| 55 | 获取文件响应 |
| 56 | |
| 57 | 如果服务不支持直接访问文件,则需要实现该方法,返回文件响应 |
| 58 | 其余情况,可以不实现该方法 |
| 59 | """ |
| 60 | raise NotImplementedError |
| 61 | |
| 62 | async def save_chunk(self, upload_id: str, chunk_index: int, chunk_data: bytes, chunk_hash: str, save_path: str): |
| 63 | """ |
| 64 | 保存分片文件 |
| 65 | :param upload_id: 上传会话ID |
| 66 | :param chunk_index: 分片索引 |
| 67 | :param chunk_data: 分片数据 |
| 68 | :param chunk_hash: 分片哈希值 |
| 69 | :param save_path: 文件保存路径 |
| 70 | """ |
| 71 | raise NotImplementedError |
| 72 | |
| 73 | async def merge_chunks(self, upload_id: str, chunk_info: UploadChunk, save_path: str) -> tuple[str, str]: |
| 74 | """ |
| 75 | 合并分片文件并返回文件路径和完整哈希值 |
| 76 | :param upload_id: 上传会话ID |
| 77 | :param chunk_info: 分片信息 |
| 78 | :param save_path: 文件保存路径 |
| 79 | :return: (文件路径, 文件哈希值) |
| 80 | """ |
| 81 | raise NotImplementedError |
| 82 | |
| 83 | async def generate_presigned_upload_url(self, save_path: str, expires_in: int = 900) -> Optional[str]: |
| 84 | """ |
| 85 | 生成预签名上传URL |
| 86 | :param save_path: 文件保存路径 |
| 87 | :param expires_in: URL过期时间(秒),默认15分钟 |
nothing calls this directly
no outgoing calls
no test coverage detected