tamar-file-hub-client 0.0.8__py3-none-any.whl → 0.0.10__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- file_hub_client/rpc/gen/file_service_pb2.py +28 -28
- file_hub_client/rpc/protos/file_service.proto +1 -0
- file_hub_client/services/file/async_blob_service.py +85 -83
- file_hub_client/services/file/sync_blob_service.py +85 -83
- {tamar_file_hub_client-0.0.8.dist-info → tamar_file_hub_client-0.0.10.dist-info}/METADATA +1 -1
- {tamar_file_hub_client-0.0.8.dist-info → tamar_file_hub_client-0.0.10.dist-info}/RECORD +8 -8
- {tamar_file_hub_client-0.0.8.dist-info → tamar_file_hub_client-0.0.10.dist-info}/WHEEL +0 -0
- {tamar_file_hub_client-0.0.8.dist-info → tamar_file_hub_client-0.0.10.dist-info}/top_level.txt +0 -0
@@ -26,7 +26,7 @@ from google.protobuf import timestamp_pb2 as google_dot_protobuf_dot_timestamp__
|
|
26
26
|
from google.protobuf import struct_pb2 as google_dot_protobuf_dot_struct__pb2
|
27
27
|
|
28
28
|
|
29
|
-
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x12\x66ile_service.proto\x12\x04\x66ile\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x1cgoogle/protobuf/struct.proto\"\xab\x01\n\x04\x46ile\x12\n\n\x02id\x18\x01 \x01(\t\x12\x11\n\tfolder_id\x18\x02 \x01(\t\x12\x11\n\tfile_name\x18\x03 \x01(\t\x12\x11\n\tfile_type\x18\x04 \x01(\t\x12.\n\ncreated_at\x18\x05 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12.\n\nupdated_at\x18\x06 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\"\xb7\x02\n\nUploadFile\x12\n\n\x02id\x18\x01 \x01(\t\x12\x11\n\tfolder_id\x18\x02 \x01(\t\x12\x0f\n\x07\x66ile_id\x18\x03 \x01(\t\x12\x14\n\x0cstorage_type\x18\x04 \x01(\t\x12\x13\n\x0bstored_name\x18\x05 \x01(\t\x12\x13\n\x0bstored_path\x18\x06 \x01(\t\x12\x11\n\tfile_name\x18\x07 \x01(\t\x12\x11\n\tfile_size\x18\x08 \x01(\x03\x12\x10\n\x08\x66ile_ext\x18\t \x01(\t\x12\x11\n\tmime_type\x18\n \x01(\t\x12\x0e\n\x06status\x18\x0b \x01(\t\x12.\n\ncreated_at\x18\x0c \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12.\n\nupdated_at\x18\r \x01(\x0b\x32\x1a.google.protobuf.Timestamp\"\xdf\x01\n\x11UploadFileRequest\x12\x16\n\tfolder_id\x18\x01 \x01(\tH\x00\x88\x01\x01\x12\x11\n\tfile_name\x18\x02 \x01(\t\x12\x0f\n\x07\x63ontent\x18\x03 \x01(\x0c\x12\x11\n\tfile_type\x18\x04 \x01(\t\x12\x11\n\tmime_type\x18\x05 \x01(\t\x12\x19\n\x0cis_temporary\x18\x06 \x01(\x08H\x01\x88\x01\x01\x12\x1b\n\x0e\x65xpire_seconds\x18\x07 \x01(\x05H\x02\x88\x01\x01\x42\x0c\n\n_folder_idB\x0f\n\r_is_temporaryB\x11\n\x0f_expire_seconds\"\xf3\x01\n\x10UploadUrlRequest\x12\x16\n\tfolder_id\x18\x01 \x01(\tH\x00\x88\x01\x01\x12\x11\n\tfile_name\x18\x02 \x01(\t\x12\x11\n\tfile_type\x18\x03 \x01(\t\x12\x11\n\tmime_type\x18\x04 \x01(\t\x12\x11\n\tfile_size\x18\x05 \x01(\x03\x12\x11\n\tfile_hash\x18\x06 \x01(\t\x12\x19\n\x0cis_temporary\x18\x07 \x01(\x08H\x01\x88\x01\x01\x12\x1b\n\x0e\x65xpire_seconds\x18\x08 \x01(\x05H\x02\x88\x01\x01\x42\x0c\n\n_folder_idB\x0f\n\r_is_temporaryB\x11\n\x0f_expire_seconds\")\n\x16UploadCompletedRequest\x12\x0f\n\x07\x66ile_id\x18\x01 \x01(\t\"
|
29
|
+
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x12\x66ile_service.proto\x12\x04\x66ile\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x1cgoogle/protobuf/struct.proto\"\xab\x01\n\x04\x46ile\x12\n\n\x02id\x18\x01 \x01(\t\x12\x11\n\tfolder_id\x18\x02 \x01(\t\x12\x11\n\tfile_name\x18\x03 \x01(\t\x12\x11\n\tfile_type\x18\x04 \x01(\t\x12.\n\ncreated_at\x18\x05 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12.\n\nupdated_at\x18\x06 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\"\xb7\x02\n\nUploadFile\x12\n\n\x02id\x18\x01 \x01(\t\x12\x11\n\tfolder_id\x18\x02 \x01(\t\x12\x0f\n\x07\x66ile_id\x18\x03 \x01(\t\x12\x14\n\x0cstorage_type\x18\x04 \x01(\t\x12\x13\n\x0bstored_name\x18\x05 \x01(\t\x12\x13\n\x0bstored_path\x18\x06 \x01(\t\x12\x11\n\tfile_name\x18\x07 \x01(\t\x12\x11\n\tfile_size\x18\x08 \x01(\x03\x12\x10\n\x08\x66ile_ext\x18\t \x01(\t\x12\x11\n\tmime_type\x18\n \x01(\t\x12\x0e\n\x06status\x18\x0b \x01(\t\x12.\n\ncreated_at\x18\x0c \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12.\n\nupdated_at\x18\r \x01(\x0b\x32\x1a.google.protobuf.Timestamp\"\xdf\x01\n\x11UploadFileRequest\x12\x16\n\tfolder_id\x18\x01 \x01(\tH\x00\x88\x01\x01\x12\x11\n\tfile_name\x18\x02 \x01(\t\x12\x0f\n\x07\x63ontent\x18\x03 \x01(\x0c\x12\x11\n\tfile_type\x18\x04 \x01(\t\x12\x11\n\tmime_type\x18\x05 \x01(\t\x12\x19\n\x0cis_temporary\x18\x06 \x01(\x08H\x01\x88\x01\x01\x12\x1b\n\x0e\x65xpire_seconds\x18\x07 \x01(\x05H\x02\x88\x01\x01\x42\x0c\n\n_folder_idB\x0f\n\r_is_temporaryB\x11\n\x0f_expire_seconds\"\xf3\x01\n\x10UploadUrlRequest\x12\x16\n\tfolder_id\x18\x01 \x01(\tH\x00\x88\x01\x01\x12\x11\n\tfile_name\x18\x02 \x01(\t\x12\x11\n\tfile_type\x18\x03 \x01(\t\x12\x11\n\tmime_type\x18\x04 \x01(\t\x12\x11\n\tfile_size\x18\x05 \x01(\x03\x12\x11\n\tfile_hash\x18\x06 \x01(\t\x12\x19\n\x0cis_temporary\x18\x07 \x01(\x08H\x01\x88\x01\x01\x12\x1b\n\x0e\x65xpire_seconds\x18\x08 \x01(\x05H\x02\x88\x01\x01\x42\x0c\n\n_folder_idB\x0f\n\r_is_temporaryB\x11\n\x0f_expire_seconds\")\n\x16UploadCompletedRequest\x12\x0f\n\x07\x66ile_id\x18\x01 \x01(\t\"u\n\x12\x44ownloadUrlRequest\x12\x0f\n\x07\x66ile_id\x18\x01 \x01(\t\x12\x13\n\x06is_cdn\x18\x03 \x01(\x08H\x00\x88\x01\x01\x12\x1b\n\x0e\x65xpire_seconds\x18\x02 \x01(\x05H\x01\x88\x01\x01\x42\t\n\x07_is_cdnB\x11\n\x0f_expire_seconds\"\xd4\x01\n\x10ShareLinkRequest\x12\x0f\n\x07\x66ile_id\x18\x01 \x01(\t\x12\x11\n\tis_public\x18\x02 \x01(\x08\x12\x14\n\x0c\x61\x63\x63\x65ss_scope\x18\x03 \x01(\t\x12\x1b\n\x0e\x65xpire_seconds\x18\x04 \x01(\x05H\x00\x88\x01\x01\x12\x17\n\nmax_access\x18\x05 \x01(\x05H\x01\x88\x01\x01\x12\x1b\n\x0eshare_password\x18\x06 \x01(\tH\x02\x88\x01\x01\x42\x11\n\x0f_expire_secondsB\r\n\x0b_max_accessB\x11\n\x0f_share_password\"\x82\x01\n\x10\x46ileVisitRequest\x12\x15\n\rfile_share_id\x18\x01 \x01(\t\x12\x13\n\x0b\x61\x63\x63\x65ss_type\x18\x02 \x01(\t\x12\x17\n\x0f\x61\x63\x63\x65ss_duration\x18\x03 \x01(\x05\x12)\n\x08metadata\x18\x04 \x01(\x0b\x32\x17.google.protobuf.Struct\"!\n\x0eGetFileRequest\x12\x0f\n\x07\x66ile_id\x18\x01 \x01(\t\"6\n\x11RenameFileRequest\x12\x0f\n\x07\x66ile_id\x18\x01 \x01(\t\x12\x10\n\x08new_name\x18\x02 \x01(\t\"$\n\x11\x44\x65leteFileRequest\x12\x0f\n\x07\x66ile_id\x18\x01 \x01(\t\"\x8d\x02\n\x10ListFilesRequest\x12\x16\n\tfolder_id\x18\x01 \x01(\tH\x00\x88\x01\x01\x12\x16\n\tfile_name\x18\x02 \x01(\tH\x01\x88\x01\x01\x12\x11\n\tfile_type\x18\x03 \x03(\t\x12\x1c\n\x0f\x63reated_by_role\x18\x04 \x01(\tH\x02\x88\x01\x01\x12\x17\n\ncreated_by\x18\x05 \x01(\tH\x03\x88\x01\x01\x12\x16\n\tpage_size\x18\x06 \x01(\x05H\x04\x88\x01\x01\x12\x11\n\x04page\x18\x07 \x01(\x05H\x05\x88\x01\x01\x42\x0c\n\n_folder_idB\x0c\n\n_file_nameB\x12\n\x10_created_by_roleB\r\n\x0b_created_byB\x0c\n\n_page_sizeB\x07\n\x05_page\"U\n\x12UploadFileResponse\x12\x18\n\x04\x66ile\x18\x01 \x01(\x0b\x32\n.file.File\x12%\n\x0bupload_file\x18\x02 \x01(\x0b\x32\x10.file.UploadFile\"a\n\x11UploadUrlResponse\x12\x18\n\x04\x66ile\x18\x01 \x01(\x0b\x32\n.file.File\x12%\n\x0bupload_file\x18\x02 \x01(\x0b\x32\x10.file.UploadFile\x12\x0b\n\x03url\x18\x03 \x01(\t\"\"\n\x13\x44ownloadUrlResponse\x12\x0b\n\x03url\x18\x01 \x01(\t\"*\n\x11ShareLinkResponse\x12\x15\n\rfile_share_id\x18\x01 \x01(\t\"-\n\x10\x46ileListResponse\x12\x19\n\x05\x66iles\x18\x01 \x03(\x0b\x32\n.file.File\"\x07\n\x05\x45mpty2\xbd\x05\n\x0b\x46ileService\x12?\n\nUploadFile\x12\x17.file.UploadFileRequest\x1a\x18.file.UploadFileResponse\x12\x44\n\x11GenerateUploadUrl\x12\x16.file.UploadUrlRequest\x1a\x17.file.UploadUrlResponse\x12M\n\x1aGenerateResumableUploadUrl\x12\x16.file.UploadUrlRequest\x1a\x17.file.UploadUrlResponse\x12\x43\n\x16\x43onfirmUploadCompleted\x12\x1c.file.UploadCompletedRequest\x1a\x0b.file.Empty\x12J\n\x13GenerateDownloadUrl\x12\x18.file.DownloadUrlRequest\x1a\x19.file.DownloadUrlResponse\x12\x44\n\x11GenerateShareLink\x12\x16.file.ShareLinkRequest\x1a\x17.file.ShareLinkResponse\x12\x30\n\tVisitFile\x12\x16.file.FileVisitRequest\x1a\x0b.file.Empty\x12+\n\x07GetFile\x12\x14.file.GetFileRequest\x1a\n.file.File\x12\x31\n\nRenameFile\x12\x17.file.RenameFileRequest\x1a\n.file.File\x12\x32\n\nDeleteFile\x12\x17.file.DeleteFileRequest\x1a\x0b.file.Empty\x12;\n\tListFiles\x12\x16.file.ListFilesRequest\x1a\x16.file.FileListResponseb\x06proto3')
|
30
30
|
|
31
31
|
_globals = globals()
|
32
32
|
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
|
@@ -44,31 +44,31 @@ if not _descriptor._USE_C_DESCRIPTORS:
|
|
44
44
|
_globals['_UPLOADCOMPLETEDREQUEST']._serialized_start=1051
|
45
45
|
_globals['_UPLOADCOMPLETEDREQUEST']._serialized_end=1092
|
46
46
|
_globals['_DOWNLOADURLREQUEST']._serialized_start=1094
|
47
|
-
_globals['_DOWNLOADURLREQUEST']._serialized_end=
|
48
|
-
_globals['_SHARELINKREQUEST']._serialized_start=
|
49
|
-
_globals['_SHARELINKREQUEST']._serialized_end=
|
50
|
-
_globals['_FILEVISITREQUEST']._serialized_start=
|
51
|
-
_globals['_FILEVISITREQUEST']._serialized_end=
|
52
|
-
_globals['_GETFILEREQUEST']._serialized_start=
|
53
|
-
_globals['_GETFILEREQUEST']._serialized_end=
|
54
|
-
_globals['_RENAMEFILEREQUEST']._serialized_start=
|
55
|
-
_globals['_RENAMEFILEREQUEST']._serialized_end=
|
56
|
-
_globals['_DELETEFILEREQUEST']._serialized_start=
|
57
|
-
_globals['_DELETEFILEREQUEST']._serialized_end=
|
58
|
-
_globals['_LISTFILESREQUEST']._serialized_start=
|
59
|
-
_globals['_LISTFILESREQUEST']._serialized_end=
|
60
|
-
_globals['_UPLOADFILERESPONSE']._serialized_start=
|
61
|
-
_globals['_UPLOADFILERESPONSE']._serialized_end=
|
62
|
-
_globals['_UPLOADURLRESPONSE']._serialized_start=
|
63
|
-
_globals['_UPLOADURLRESPONSE']._serialized_end=
|
64
|
-
_globals['_DOWNLOADURLRESPONSE']._serialized_start=
|
65
|
-
_globals['_DOWNLOADURLRESPONSE']._serialized_end=
|
66
|
-
_globals['_SHARELINKRESPONSE']._serialized_start=
|
67
|
-
_globals['_SHARELINKRESPONSE']._serialized_end=
|
68
|
-
_globals['_FILELISTRESPONSE']._serialized_start=
|
69
|
-
_globals['_FILELISTRESPONSE']._serialized_end=
|
70
|
-
_globals['_EMPTY']._serialized_start=
|
71
|
-
_globals['_EMPTY']._serialized_end=
|
72
|
-
_globals['_FILESERVICE']._serialized_start=
|
73
|
-
_globals['_FILESERVICE']._serialized_end=
|
47
|
+
_globals['_DOWNLOADURLREQUEST']._serialized_end=1211
|
48
|
+
_globals['_SHARELINKREQUEST']._serialized_start=1214
|
49
|
+
_globals['_SHARELINKREQUEST']._serialized_end=1426
|
50
|
+
_globals['_FILEVISITREQUEST']._serialized_start=1429
|
51
|
+
_globals['_FILEVISITREQUEST']._serialized_end=1559
|
52
|
+
_globals['_GETFILEREQUEST']._serialized_start=1561
|
53
|
+
_globals['_GETFILEREQUEST']._serialized_end=1594
|
54
|
+
_globals['_RENAMEFILEREQUEST']._serialized_start=1596
|
55
|
+
_globals['_RENAMEFILEREQUEST']._serialized_end=1650
|
56
|
+
_globals['_DELETEFILEREQUEST']._serialized_start=1652
|
57
|
+
_globals['_DELETEFILEREQUEST']._serialized_end=1688
|
58
|
+
_globals['_LISTFILESREQUEST']._serialized_start=1691
|
59
|
+
_globals['_LISTFILESREQUEST']._serialized_end=1960
|
60
|
+
_globals['_UPLOADFILERESPONSE']._serialized_start=1962
|
61
|
+
_globals['_UPLOADFILERESPONSE']._serialized_end=2047
|
62
|
+
_globals['_UPLOADURLRESPONSE']._serialized_start=2049
|
63
|
+
_globals['_UPLOADURLRESPONSE']._serialized_end=2146
|
64
|
+
_globals['_DOWNLOADURLRESPONSE']._serialized_start=2148
|
65
|
+
_globals['_DOWNLOADURLRESPONSE']._serialized_end=2182
|
66
|
+
_globals['_SHARELINKRESPONSE']._serialized_start=2184
|
67
|
+
_globals['_SHARELINKRESPONSE']._serialized_end=2226
|
68
|
+
_globals['_FILELISTRESPONSE']._serialized_start=2228
|
69
|
+
_globals['_FILELISTRESPONSE']._serialized_end=2273
|
70
|
+
_globals['_EMPTY']._serialized_start=2275
|
71
|
+
_globals['_EMPTY']._serialized_end=2282
|
72
|
+
_globals['_FILESERVICE']._serialized_start=2285
|
73
|
+
_globals['_FILESERVICE']._serialized_end=2986
|
74
74
|
# @@protoc_insertion_point(module_scope)
|
@@ -29,85 +29,6 @@ class AsyncBlobService(BaseFileService):
|
|
29
29
|
self.http_uploader = AsyncHttpUploader()
|
30
30
|
self.http_downloader = AsyncHttpDownloader()
|
31
31
|
|
32
|
-
async def _generate_resumable_upload_url(
|
33
|
-
self,
|
34
|
-
file_name: str,
|
35
|
-
file_size: int,
|
36
|
-
folder_id: Optional[str] = None,
|
37
|
-
file_type: str = "dat",
|
38
|
-
mime_type: Optional[str] = None,
|
39
|
-
file_hash: Optional[str] = None,
|
40
|
-
is_temporary: Optional[bool] = False,
|
41
|
-
expire_seconds: Optional[int] = None,
|
42
|
-
request_id: Optional[str] = None,
|
43
|
-
**metadata
|
44
|
-
) -> UploadUrlResponse:
|
45
|
-
"""
|
46
|
-
生成断点续传URL
|
47
|
-
|
48
|
-
Args:
|
49
|
-
file_name: 文件名
|
50
|
-
file_size: 文件大小
|
51
|
-
folder_id: 文件夹ID
|
52
|
-
file_type: 文件类型
|
53
|
-
mime_type: MIME类型
|
54
|
-
file_hash: 文件哈希
|
55
|
-
is_temporary: 是否为临时文件
|
56
|
-
expire_seconds: 过期秒数
|
57
|
-
**metadata: 额外的元数据(如 x-org-id, x-user-id 等)
|
58
|
-
|
59
|
-
Returns:
|
60
|
-
上传URL响应
|
61
|
-
"""
|
62
|
-
from ...rpc.gen import file_service_pb2, file_service_pb2_grpc
|
63
|
-
|
64
|
-
stub = await self.client.get_stub(file_service_pb2_grpc.FileServiceStub)
|
65
|
-
|
66
|
-
request = file_service_pb2.UploadUrlRequest(
|
67
|
-
file_name=file_name,
|
68
|
-
file_size=file_size,
|
69
|
-
file_type=file_type,
|
70
|
-
mime_type=mime_type or "application/octet-stream",
|
71
|
-
file_hash=file_hash,
|
72
|
-
is_temporary=is_temporary,
|
73
|
-
expire_seconds=expire_seconds if is_temporary and expire_seconds else None,
|
74
|
-
)
|
75
|
-
|
76
|
-
if folder_id:
|
77
|
-
request.folder_id = folder_id
|
78
|
-
|
79
|
-
# 构建元数据
|
80
|
-
grpc_metadata = self.client.build_metadata(request_id=request_id, **metadata)
|
81
|
-
|
82
|
-
response = await stub.GenerateResumableUploadUrl(request, metadata=grpc_metadata)
|
83
|
-
|
84
|
-
return UploadUrlResponse(
|
85
|
-
file=self._convert_file_info(response.file),
|
86
|
-
upload_file=self._convert_upload_file_info(response.upload_file),
|
87
|
-
upload_url=response.url
|
88
|
-
)
|
89
|
-
|
90
|
-
async def _confirm_upload_completed(self, file_id: str, request_id: Optional[str] = None,
|
91
|
-
**metadata) -> None:
|
92
|
-
"""
|
93
|
-
确认上传完成
|
94
|
-
|
95
|
-
Args:
|
96
|
-
file_id: 文件ID
|
97
|
-
request_id: 请求ID(可选,如果不提供则自动生成)
|
98
|
-
**metadata: 额外的元数据(如 x-org-id, x-user-id 等)
|
99
|
-
"""
|
100
|
-
from ...rpc.gen import file_service_pb2, file_service_pb2_grpc
|
101
|
-
|
102
|
-
stub = await self.client.get_stub(file_service_pb2_grpc.FileServiceStub)
|
103
|
-
|
104
|
-
request = file_service_pb2.UploadCompletedRequest(file_id=file_id)
|
105
|
-
|
106
|
-
# 构建元数据
|
107
|
-
grpc_metadata = self.client.build_metadata(request_id=request_id, **metadata)
|
108
|
-
|
109
|
-
await stub.ConfirmUploadCompleted(request, metadata=grpc_metadata)
|
110
|
-
|
111
32
|
@retry_with_backoff(max_retries=3)
|
112
33
|
async def _upload_file(
|
113
34
|
self,
|
@@ -228,7 +149,7 @@ class AsyncBlobService(BaseFileService):
|
|
228
149
|
)
|
229
150
|
|
230
151
|
# 确认上传完成
|
231
|
-
await self.
|
152
|
+
await self.confirm_upload_completed(
|
232
153
|
file_id=upload_url_resp.file.id,
|
233
154
|
request_id=request_id,
|
234
155
|
**metadata
|
@@ -256,7 +177,7 @@ class AsyncBlobService(BaseFileService):
|
|
256
177
|
) -> FileUploadResponse:
|
257
178
|
"""断点续传实现"""
|
258
179
|
# 获取断点续传URL,以及对应的文件和上传文件信息
|
259
|
-
upload_url_resp = await self.
|
180
|
+
upload_url_resp = await self.generate_resumable_upload_url(
|
260
181
|
file_name=file_name,
|
261
182
|
file_size=file_size,
|
262
183
|
folder_id=folder_id,
|
@@ -292,7 +213,7 @@ class AsyncBlobService(BaseFileService):
|
|
292
213
|
)
|
293
214
|
|
294
215
|
# 确认上传完成
|
295
|
-
await self.
|
216
|
+
await self.confirm_upload_completed(
|
296
217
|
file_id=upload_url_resp.file.id,
|
297
218
|
request_id=request_id,
|
298
219
|
**metadata
|
@@ -304,6 +225,85 @@ class AsyncBlobService(BaseFileService):
|
|
304
225
|
upload_file=upload_url_resp.upload_file
|
305
226
|
)
|
306
227
|
|
228
|
+
async def confirm_upload_completed(self, file_id: str, request_id: Optional[str] = None,
|
229
|
+
**metadata) -> None:
|
230
|
+
"""
|
231
|
+
确认上传完成
|
232
|
+
|
233
|
+
Args:
|
234
|
+
file_id: 文件ID
|
235
|
+
request_id: 请求ID(可选,如果不提供则自动生成)
|
236
|
+
**metadata: 额外的元数据(如 x-org-id, x-user-id 等)
|
237
|
+
"""
|
238
|
+
from ...rpc.gen import file_service_pb2, file_service_pb2_grpc
|
239
|
+
|
240
|
+
stub = await self.client.get_stub(file_service_pb2_grpc.FileServiceStub)
|
241
|
+
|
242
|
+
request = file_service_pb2.UploadCompletedRequest(file_id=file_id)
|
243
|
+
|
244
|
+
# 构建元数据
|
245
|
+
grpc_metadata = self.client.build_metadata(request_id=request_id, **metadata)
|
246
|
+
|
247
|
+
await stub.ConfirmUploadCompleted(request, metadata=grpc_metadata)
|
248
|
+
|
249
|
+
async def generate_resumable_upload_url(
|
250
|
+
self,
|
251
|
+
file_name: str,
|
252
|
+
file_size: int,
|
253
|
+
folder_id: Optional[str] = None,
|
254
|
+
file_type: str = "dat",
|
255
|
+
mime_type: Optional[str] = None,
|
256
|
+
file_hash: Optional[str] = None,
|
257
|
+
is_temporary: Optional[bool] = False,
|
258
|
+
expire_seconds: Optional[int] = None,
|
259
|
+
request_id: Optional[str] = None,
|
260
|
+
**metadata
|
261
|
+
) -> UploadUrlResponse:
|
262
|
+
"""
|
263
|
+
生成断点续传URL
|
264
|
+
|
265
|
+
Args:
|
266
|
+
file_name: 文件名
|
267
|
+
file_size: 文件大小
|
268
|
+
folder_id: 文件夹ID
|
269
|
+
file_type: 文件类型
|
270
|
+
mime_type: MIME类型
|
271
|
+
file_hash: 文件哈希
|
272
|
+
is_temporary: 是否为临时文件
|
273
|
+
expire_seconds: 过期秒数
|
274
|
+
**metadata: 额外的元数据(如 x-org-id, x-user-id 等)
|
275
|
+
|
276
|
+
Returns:
|
277
|
+
上传URL响应
|
278
|
+
"""
|
279
|
+
from ...rpc.gen import file_service_pb2, file_service_pb2_grpc
|
280
|
+
|
281
|
+
stub = await self.client.get_stub(file_service_pb2_grpc.FileServiceStub)
|
282
|
+
|
283
|
+
request = file_service_pb2.UploadUrlRequest(
|
284
|
+
file_name=file_name,
|
285
|
+
file_size=file_size,
|
286
|
+
file_type=file_type,
|
287
|
+
mime_type=mime_type or "application/octet-stream",
|
288
|
+
file_hash=file_hash,
|
289
|
+
is_temporary=is_temporary,
|
290
|
+
expire_seconds=expire_seconds if is_temporary and expire_seconds else None,
|
291
|
+
)
|
292
|
+
|
293
|
+
if folder_id:
|
294
|
+
request.folder_id = folder_id
|
295
|
+
|
296
|
+
# 构建元数据
|
297
|
+
grpc_metadata = self.client.build_metadata(request_id=request_id, **metadata)
|
298
|
+
|
299
|
+
response = await stub.GenerateResumableUploadUrl(request, metadata=grpc_metadata)
|
300
|
+
|
301
|
+
return UploadUrlResponse(
|
302
|
+
file=self._convert_file_info(response.file),
|
303
|
+
upload_file=self._convert_upload_file_info(response.upload_file),
|
304
|
+
upload_url=response.url
|
305
|
+
)
|
306
|
+
|
307
307
|
async def generate_upload_url(
|
308
308
|
self,
|
309
309
|
file_name: str,
|
@@ -504,6 +504,7 @@ class AsyncBlobService(BaseFileService):
|
|
504
504
|
self,
|
505
505
|
file_id: str,
|
506
506
|
*,
|
507
|
+
is_cdn: Optional[bool] = True,
|
507
508
|
expire_seconds: Optional[int] = None,
|
508
509
|
request_id: Optional[str] = None,
|
509
510
|
**metadata
|
@@ -513,6 +514,7 @@ class AsyncBlobService(BaseFileService):
|
|
513
514
|
|
514
515
|
Args:
|
515
516
|
file_id: 文件ID
|
517
|
+
is_cdn: 是否返回CDN的URL
|
516
518
|
expire_seconds: 过期时间(秒)
|
517
519
|
request_id: 请求ID(可选,如果不提供则自动生成)
|
518
520
|
**metadata: 额外的元数据(如 x-org-id, x-user-id 等)
|
@@ -524,7 +526,7 @@ class AsyncBlobService(BaseFileService):
|
|
524
526
|
|
525
527
|
stub = await self.client.get_stub(file_service_pb2_grpc.FileServiceStub)
|
526
528
|
|
527
|
-
request = file_service_pb2.DownloadUrlRequest(file_id=file_id,
|
529
|
+
request = file_service_pb2.DownloadUrlRequest(file_id=file_id, is_cdn=is_cdn,
|
528
530
|
expire_seconds=expire_seconds if expire_seconds else None)
|
529
531
|
|
530
532
|
# 构建元数据
|
@@ -27,85 +27,6 @@ class SyncBlobService(BaseFileService):
|
|
27
27
|
self.http_uploader = HttpUploader()
|
28
28
|
self.http_downloader = HttpDownloader()
|
29
29
|
|
30
|
-
def _generate_resumable_upload_url(
|
31
|
-
self,
|
32
|
-
file_name: str,
|
33
|
-
file_size: int,
|
34
|
-
folder_id: Optional[str] = None,
|
35
|
-
file_type: str = "dat",
|
36
|
-
mime_type: str = None,
|
37
|
-
file_hash: str = None,
|
38
|
-
is_temporary: Optional[bool] = False,
|
39
|
-
expire_seconds: Optional[int] = None,
|
40
|
-
request_id: Optional[str] = None,
|
41
|
-
**metadata
|
42
|
-
) -> UploadUrlResponse:
|
43
|
-
"""
|
44
|
-
生成断点续传URL
|
45
|
-
|
46
|
-
Args:
|
47
|
-
file_name: 文件名
|
48
|
-
file_size: 文件大小
|
49
|
-
folder_id: 文件夹ID
|
50
|
-
file_type: 文件类型
|
51
|
-
mime_type: MIME类型
|
52
|
-
file_hash: 文件哈希
|
53
|
-
is_temporary: 是否为临时文件
|
54
|
-
expire_seconds: 过期秒数
|
55
|
-
**metadata: 额外的元数据(如 x-org-id, x-user-id 等)
|
56
|
-
|
57
|
-
Returns:
|
58
|
-
上传URL响应
|
59
|
-
"""
|
60
|
-
from ...rpc.gen import file_service_pb2, file_service_pb2_grpc
|
61
|
-
|
62
|
-
stub = self.client.get_stub(file_service_pb2_grpc.FileServiceStub)
|
63
|
-
|
64
|
-
request = file_service_pb2.UploadUrlRequest(
|
65
|
-
file_name=file_name,
|
66
|
-
file_size=file_size,
|
67
|
-
file_type=file_type,
|
68
|
-
mime_type=mime_type or "application/octet-stream",
|
69
|
-
file_hash=file_hash,
|
70
|
-
is_temporary=is_temporary,
|
71
|
-
expire_seconds=expire_seconds if is_temporary and expire_seconds else None,
|
72
|
-
)
|
73
|
-
|
74
|
-
if folder_id:
|
75
|
-
request.folder_id = folder_id
|
76
|
-
|
77
|
-
# 构建元数据
|
78
|
-
grpc_metadata = self.client.build_metadata(request_id=request_id, **metadata)
|
79
|
-
|
80
|
-
response = stub.GenerateResumableUploadUrl(request, metadata=grpc_metadata)
|
81
|
-
|
82
|
-
return UploadUrlResponse(
|
83
|
-
file=self._convert_file_info(response.file),
|
84
|
-
upload_file=self._convert_upload_file_info(response.upload_file),
|
85
|
-
upload_url=response.url
|
86
|
-
)
|
87
|
-
|
88
|
-
def _confirm_upload_completed(self, file_id: str, request_id: Optional[str] = None,
|
89
|
-
**metadata) -> None:
|
90
|
-
"""
|
91
|
-
确认上传完成
|
92
|
-
|
93
|
-
Args:
|
94
|
-
file_id: 文件ID
|
95
|
-
request_id: 请求ID(可选,如果不提供则自动生成)
|
96
|
-
**metadata: 额外的元数据(如 x-org-id, x-user-id 等)
|
97
|
-
"""
|
98
|
-
from ...rpc.gen import file_service_pb2, file_service_pb2_grpc
|
99
|
-
|
100
|
-
stub = self.client.get_stub(file_service_pb2_grpc.FileServiceStub)
|
101
|
-
|
102
|
-
request = file_service_pb2.UploadCompletedRequest(file_id=file_id)
|
103
|
-
|
104
|
-
# 构建元数据
|
105
|
-
grpc_metadata = self.client.build_metadata(request_id=request_id, **metadata)
|
106
|
-
|
107
|
-
stub.ConfirmUploadCompleted(request, metadata=grpc_metadata)
|
108
|
-
|
109
30
|
@retry_with_backoff(max_retries=3)
|
110
31
|
def _upload_file(
|
111
32
|
self,
|
@@ -225,7 +146,7 @@ class SyncBlobService(BaseFileService):
|
|
225
146
|
)
|
226
147
|
|
227
148
|
# 确认上传完成
|
228
|
-
self.
|
149
|
+
self.confirm_upload_completed(
|
229
150
|
file_id=upload_url_resp.file.id,
|
230
151
|
request_id=request_id,
|
231
152
|
**metadata
|
@@ -253,7 +174,7 @@ class SyncBlobService(BaseFileService):
|
|
253
174
|
) -> FileUploadResponse:
|
254
175
|
"""断点续传实现"""
|
255
176
|
# 获取断点续传URL,以及对应的文件和上传文件信息
|
256
|
-
upload_url_resp = self.
|
177
|
+
upload_url_resp = self.generate_resumable_upload_url(
|
257
178
|
file_name=file_name,
|
258
179
|
file_size=file_size,
|
259
180
|
folder_id=folder_id,
|
@@ -290,7 +211,7 @@ class SyncBlobService(BaseFileService):
|
|
290
211
|
)
|
291
212
|
|
292
213
|
# 确认上传完成
|
293
|
-
self.
|
214
|
+
self.confirm_upload_completed(
|
294
215
|
file_id=upload_url_resp.file.id,
|
295
216
|
request_id=request_id,
|
296
217
|
**metadata
|
@@ -302,6 +223,85 @@ class SyncBlobService(BaseFileService):
|
|
302
223
|
upload_file=upload_url_resp.upload_file
|
303
224
|
)
|
304
225
|
|
226
|
+
def confirm_upload_completed(self, file_id: str, request_id: Optional[str] = None,
|
227
|
+
**metadata) -> None:
|
228
|
+
"""
|
229
|
+
确认上传完成
|
230
|
+
|
231
|
+
Args:
|
232
|
+
file_id: 文件ID
|
233
|
+
request_id: 请求ID(可选,如果不提供则自动生成)
|
234
|
+
**metadata: 额外的元数据(如 x-org-id, x-user-id 等)
|
235
|
+
"""
|
236
|
+
from ...rpc.gen import file_service_pb2, file_service_pb2_grpc
|
237
|
+
|
238
|
+
stub = self.client.get_stub(file_service_pb2_grpc.FileServiceStub)
|
239
|
+
|
240
|
+
request = file_service_pb2.UploadCompletedRequest(file_id=file_id)
|
241
|
+
|
242
|
+
# 构建元数据
|
243
|
+
grpc_metadata = self.client.build_metadata(request_id=request_id, **metadata)
|
244
|
+
|
245
|
+
stub.ConfirmUploadCompleted(request, metadata=grpc_metadata)
|
246
|
+
|
247
|
+
def generate_resumable_upload_url(
|
248
|
+
self,
|
249
|
+
file_name: str,
|
250
|
+
file_size: int,
|
251
|
+
folder_id: Optional[str] = None,
|
252
|
+
file_type: str = "dat",
|
253
|
+
mime_type: str = None,
|
254
|
+
file_hash: str = None,
|
255
|
+
is_temporary: Optional[bool] = False,
|
256
|
+
expire_seconds: Optional[int] = None,
|
257
|
+
request_id: Optional[str] = None,
|
258
|
+
**metadata
|
259
|
+
) -> UploadUrlResponse:
|
260
|
+
"""
|
261
|
+
生成断点续传URL
|
262
|
+
|
263
|
+
Args:
|
264
|
+
file_name: 文件名
|
265
|
+
file_size: 文件大小
|
266
|
+
folder_id: 文件夹ID
|
267
|
+
file_type: 文件类型
|
268
|
+
mime_type: MIME类型
|
269
|
+
file_hash: 文件哈希
|
270
|
+
is_temporary: 是否为临时文件
|
271
|
+
expire_seconds: 过期秒数
|
272
|
+
**metadata: 额外的元数据(如 x-org-id, x-user-id 等)
|
273
|
+
|
274
|
+
Returns:
|
275
|
+
上传URL响应
|
276
|
+
"""
|
277
|
+
from ...rpc.gen import file_service_pb2, file_service_pb2_grpc
|
278
|
+
|
279
|
+
stub = self.client.get_stub(file_service_pb2_grpc.FileServiceStub)
|
280
|
+
|
281
|
+
request = file_service_pb2.UploadUrlRequest(
|
282
|
+
file_name=file_name,
|
283
|
+
file_size=file_size,
|
284
|
+
file_type=file_type,
|
285
|
+
mime_type=mime_type or "application/octet-stream",
|
286
|
+
file_hash=file_hash,
|
287
|
+
is_temporary=is_temporary,
|
288
|
+
expire_seconds=expire_seconds if is_temporary and expire_seconds else None,
|
289
|
+
)
|
290
|
+
|
291
|
+
if folder_id:
|
292
|
+
request.folder_id = folder_id
|
293
|
+
|
294
|
+
# 构建元数据
|
295
|
+
grpc_metadata = self.client.build_metadata(request_id=request_id, **metadata)
|
296
|
+
|
297
|
+
response = stub.GenerateResumableUploadUrl(request, metadata=grpc_metadata)
|
298
|
+
|
299
|
+
return UploadUrlResponse(
|
300
|
+
file=self._convert_file_info(response.file),
|
301
|
+
upload_file=self._convert_upload_file_info(response.upload_file),
|
302
|
+
upload_url=response.url
|
303
|
+
)
|
304
|
+
|
305
305
|
def generate_upload_url(
|
306
306
|
self,
|
307
307
|
file_name: str,
|
@@ -502,6 +502,7 @@ class SyncBlobService(BaseFileService):
|
|
502
502
|
self,
|
503
503
|
file_id: str,
|
504
504
|
*,
|
505
|
+
is_cdn: Optional[bool] = True,
|
505
506
|
expire_seconds: Optional[int] = None,
|
506
507
|
request_id: Optional[str] = None,
|
507
508
|
**metadata
|
@@ -511,6 +512,7 @@ class SyncBlobService(BaseFileService):
|
|
511
512
|
|
512
513
|
Args:
|
513
514
|
file_id: 文件ID
|
515
|
+
is_cdn: 是否返回CDN的URL
|
514
516
|
expire_seconds: 过期时间(秒)
|
515
517
|
request_id: 请求ID(可选,如果不提供则自动生成)
|
516
518
|
**metadata: 额外的元数据(如 x-org-id, x-user-id 等)
|
@@ -522,7 +524,7 @@ class SyncBlobService(BaseFileService):
|
|
522
524
|
|
523
525
|
stub = self.client.get_stub(file_service_pb2_grpc.FileServiceStub)
|
524
526
|
|
525
|
-
request = file_service_pb2.DownloadUrlRequest(file_id=file_id,
|
527
|
+
request = file_service_pb2.DownloadUrlRequest(file_id=file_id, is_cdn=is_cdn,
|
526
528
|
expire_seconds=expire_seconds if expire_seconds else None)
|
527
529
|
|
528
530
|
# 构建元数据
|
@@ -13,13 +13,13 @@ file_hub_client/rpc/generate_grpc.py,sha256=opzstxWdW7vqR9OxrgUCSUkZe8IqgcOdruqW
|
|
13
13
|
file_hub_client/rpc/interceptors.py,sha256=UeQ8u-olMiYwScXJrlzqPS-odGomH-h3xJqOwPznRUo,22071
|
14
14
|
file_hub_client/rpc/sync_client.py,sha256=ZWBmP-TU8eeAfl2lV8sLu9nsxo_aOPAVmt9ww_T8Hwg,14054
|
15
15
|
file_hub_client/rpc/gen/__init__.py,sha256=NJLqr9ezUXeOyy1J0sMPn3Kl_8IyGw7GAzzzewO3MIw,45
|
16
|
-
file_hub_client/rpc/gen/file_service_pb2.py,sha256=
|
16
|
+
file_hub_client/rpc/gen/file_service_pb2.py,sha256=_0OKjhzI82aW71bRji4W6RK2yYHqbFlZgYtOBL-VxVM,8425
|
17
17
|
file_hub_client/rpc/gen/file_service_pb2_grpc.py,sha256=D-vs_udh-8YK2wxSClIKGVNdYFGg40IYMiLVkwe8QOs,20723
|
18
18
|
file_hub_client/rpc/gen/folder_service_pb2.py,sha256=OPNYHThmL1k2KH1ll2L_Gj76oWBWqcymXKHu8mk1Zvk,4126
|
19
19
|
file_hub_client/rpc/gen/folder_service_pb2_grpc.py,sha256=pOHFsVThdAu5DAKd8QK3_zQvUmFgGlh4KBqIYnYDZ_U,10411
|
20
20
|
file_hub_client/rpc/gen/taple_service_pb2.py,sha256=08TRlox7hxH2F_T-_0AgoV1xT2KIK9GrCUMkz-ZKxeo,48062
|
21
21
|
file_hub_client/rpc/gen/taple_service_pb2_grpc.py,sha256=DCL-45PlEZ0guLz1u2fFH_sDIT_awuSvp9Ak6fa2GO8,64773
|
22
|
-
file_hub_client/rpc/protos/file_service.proto,sha256=
|
22
|
+
file_hub_client/rpc/protos/file_service.proto,sha256=I0Px8pYmNERwnUECIuBEe_RAe4KUByEJ4d6K_8iDFFs,3694
|
23
23
|
file_hub_client/rpc/protos/folder_service.proto,sha256=cgIbJT2slXMMRGrtrzN3kjae9-4CB1zXCmceiUgE6fI,1542
|
24
24
|
file_hub_client/rpc/protos/taple_service.proto,sha256=sBCSECCFXamdMg65Jij29OFYlQSQGGFxwHJXq1FXpug,29639
|
25
25
|
file_hub_client/schemas/__init__.py,sha256=kA0jUV5C3EBZxXWd80hHiMvJw0KL068EintZJx-vkJw,2100
|
@@ -29,10 +29,10 @@ file_hub_client/schemas/folder.py,sha256=D7UFsLCou-7CCXCQvuRObaBQEGmETsm1cgGOG1c
|
|
29
29
|
file_hub_client/schemas/taple.py,sha256=qoH458xMAdYg8_jKdYqHJy5-gZ1ZFzOAkSPFROQuhQI,18172
|
30
30
|
file_hub_client/services/__init__.py,sha256=yh5mir0dKB_LtJMk2hTpQI9WSlguaxtVD2KomMnzxdM,514
|
31
31
|
file_hub_client/services/file/__init__.py,sha256=aJygo_AzYk5NN-ezp-a9YlugJ82wVIP9e5e54fl0UsI,342
|
32
|
-
file_hub_client/services/file/async_blob_service.py,sha256=
|
32
|
+
file_hub_client/services/file/async_blob_service.py,sha256=kIsz-tGDLgmk4J5I-h95Aummz1UPo55ffy5vIAFQxaU,20578
|
33
33
|
file_hub_client/services/file/async_file_service.py,sha256=QxVfwPoJe_oj8t7EOLHMQF3PQf4E1-HctQR7yvY9D3g,8585
|
34
34
|
file_hub_client/services/file/base_file_service.py,sha256=wTxplrTk9klfwIHOPfTL0TQd6gX4nEmkYtIhpiZ3GVo,4791
|
35
|
-
file_hub_client/services/file/sync_blob_service.py,sha256=
|
35
|
+
file_hub_client/services/file/sync_blob_service.py,sha256=I2_fcdpE6jyZ4Bs7-zWzr5PhWWPMfKQLcYMuYV2cDiE,20359
|
36
36
|
file_hub_client/services/file/sync_file_service.py,sha256=i1pLCcGNWMlWQfAW4dlhLsEiV3oc1jXKmKax35k0CGw,8439
|
37
37
|
file_hub_client/services/folder/__init__.py,sha256=vGbMOlNiEBdnWZB1xE74RJtoroI28hKHCWfQV1GqKQc,210
|
38
38
|
file_hub_client/services/folder/async_folder_service.py,sha256=uFEmtW8EXYvaKYT2JCitWbdTGR1EtHlx_eBN5P3JUZg,7293
|
@@ -51,7 +51,7 @@ file_hub_client/utils/logging.py,sha256=IxcvWkA0G9s9BMiXIeFAdJX5G-Lc5-JFlS2yxOX1
|
|
51
51
|
file_hub_client/utils/retry.py,sha256=A2MBdJCEY-Ks0guq8dd5wXX22sD27N30Qy3nQIW1B_s,18019
|
52
52
|
file_hub_client/utils/smart_retry.py,sha256=RjBhyG6SNDfMXxNxKU_qayWDD6Ihp7ow6_BPjhgflM0,16465
|
53
53
|
file_hub_client/utils/upload_helper.py,sha256=gEtn9OXVJiGUpVev_fqrDnRQ6AFiiP9goLzFrVpqXmU,22569
|
54
|
-
tamar_file_hub_client-0.0.
|
55
|
-
tamar_file_hub_client-0.0.
|
56
|
-
tamar_file_hub_client-0.0.
|
57
|
-
tamar_file_hub_client-0.0.
|
54
|
+
tamar_file_hub_client-0.0.10.dist-info/METADATA,sha256=Y13VzLkI8Z9yMtQ-VJm_Bp-7CtluviM-LH6kzngS1nI,64874
|
55
|
+
tamar_file_hub_client-0.0.10.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
56
|
+
tamar_file_hub_client-0.0.10.dist-info/top_level.txt,sha256=9wcR7hyAJQdJg_kuH6WR3nmpJ8O-j8aJNK8f_kcFy6U,16
|
57
|
+
tamar_file_hub_client-0.0.10.dist-info/RECORD,,
|
File without changes
|
{tamar_file_hub_client-0.0.8.dist-info → tamar_file_hub_client-0.0.10.dist-info}/top_level.txt
RENAMED
File without changes
|