bot
commited on
Commit
·
f20376d
1
Parent(s):
ed1a6a3
完善分享功能
Browse files- .DS_Store +0 -0
- main.py +61 -19
- pikpakapi/__init__.py +81 -37
.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
main.py
CHANGED
@@ -153,7 +153,9 @@ async def home(request: Request):
|
|
153 |
return templates.TemplateResponse("index.html", {"request": request})
|
154 |
|
155 |
|
156 |
-
@api_router.post(
|
|
|
|
|
157 |
async def get_files(item: FileRequest):
|
158 |
return await THUNDERX_CLIENT.file_list(
|
159 |
item.size, item.parent_id, item.next_page_token, item.additional_filters
|
@@ -161,44 +163,74 @@ async def get_files(item: FileRequest):
|
|
161 |
|
162 |
|
163 |
@api_router.get(
|
164 |
-
"/files/{file_id}", summary="文件信息", description="获取文件信息", tags=["
|
165 |
)
|
166 |
async def get_file_info(file_id: str):
|
167 |
return await THUNDERX_CLIENT.get_download_url(file_id)
|
168 |
|
169 |
|
170 |
@api_router.post(
|
171 |
-
"/emptytrash", summary="清空回收站", description="清空回收站【慎用】", tags=["
|
172 |
)
|
173 |
async def emptytrash():
|
174 |
return await THUNDERX_CLIENT.emptytrash()
|
175 |
|
176 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
|
178 |
@api_router.post(
|
179 |
-
"/file_batch_share", summary="创建分享", description="创建分享", tags=["
|
180 |
)
|
181 |
-
async def file_batch_share(
|
182 |
-
|
|
|
|
|
|
|
|
|
183 |
|
184 |
|
|
|
|
|
|
|
|
|
|
|
|
|
185 |
|
186 |
@api_router.post(
|
187 |
-
"/get_share_folder",
|
|
|
|
|
|
|
188 |
)
|
189 |
-
async def get_share_folder(
|
190 |
-
|
|
|
|
|
191 |
|
192 |
|
193 |
@api_router.post(
|
194 |
-
"/restore", summary="转存分享文件", description="转存分享文件", tags=["
|
195 |
)
|
196 |
-
async def restore(
|
197 |
-
|
|
|
|
|
|
|
|
|
|
|
198 |
|
199 |
|
200 |
@api_router.get(
|
201 |
-
"/offline", summary="离线任务列表", description="离线任务列表", tags=["
|
202 |
)
|
203 |
async def offline_list(size: int = 10000, next_page_token: str | None = None):
|
204 |
return await THUNDERX_CLIENT.offline_list(
|
@@ -207,8 +239,9 @@ async def offline_list(size: int = 10000, next_page_token: str | None = None):
|
|
207 |
phase=None,
|
208 |
)
|
209 |
|
|
|
210 |
@api_router.post(
|
211 |
-
"/offline", summary="添加离线任务", description="添加离线任务", tags=["
|
212 |
)
|
213 |
async def offline(item: OfflineRequest):
|
214 |
return await THUNDERX_CLIENT.offline_download(
|
@@ -216,28 +249,37 @@ async def offline(item: OfflineRequest):
|
|
216 |
)
|
217 |
|
218 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
219 |
@api_router.get(
|
220 |
-
"/userinfo", summary="用户信息", description="获取用户登陆信息", tags=["
|
221 |
)
|
222 |
async def userinfo():
|
223 |
return THUNDERX_CLIENT.get_user_info()
|
224 |
|
225 |
|
226 |
@api_router.get(
|
227 |
-
"/quota", summary="空间使用信息", description="获取空间使用信息", tags=["
|
228 |
)
|
229 |
async def quota_info():
|
230 |
return await THUNDERX_CLIENT.get_quota_info()
|
231 |
|
232 |
|
233 |
-
|
234 |
@api_router.get(
|
235 |
-
"/invite_code", summary="查看邀请码", description="查看邀请码", tags=["
|
236 |
)
|
237 |
async def get_invite_code():
|
238 |
return await THUNDERX_CLIENT.get_invite_code()
|
239 |
|
240 |
|
241 |
-
|
242 |
app.include_router(front_router)
|
243 |
app.include_router(api_router)
|
|
|
153 |
return templates.TemplateResponse("index.html", {"request": request})
|
154 |
|
155 |
|
156 |
+
@api_router.post(
|
157 |
+
"/files", summary="文件列表", description="获取文件列表", tags=["文件"]
|
158 |
+
)
|
159 |
async def get_files(item: FileRequest):
|
160 |
return await THUNDERX_CLIENT.file_list(
|
161 |
item.size, item.parent_id, item.next_page_token, item.additional_filters
|
|
|
163 |
|
164 |
|
165 |
@api_router.get(
|
166 |
+
"/files/{file_id}", summary="文件信息", description="获取文件信息", tags=["文件"]
|
167 |
)
|
168 |
async def get_file_info(file_id: str):
|
169 |
return await THUNDERX_CLIENT.get_download_url(file_id)
|
170 |
|
171 |
|
172 |
@api_router.post(
|
173 |
+
"/emptytrash", summary="清空回收站", description="清空回收站【慎用】", tags=["文件"]
|
174 |
)
|
175 |
async def emptytrash():
|
176 |
return await THUNDERX_CLIENT.emptytrash()
|
177 |
|
178 |
|
179 |
+
############## 分享 ################
|
180 |
+
@api_router.post(
|
181 |
+
"/get_share_list",
|
182 |
+
summary="获取账号分享列表",
|
183 |
+
description="获取账号分享列表",
|
184 |
+
tags=["分享"],
|
185 |
+
)
|
186 |
+
async def get_share_list(page_token: str | None = None):
|
187 |
+
return await THUNDERX_CLIENT.get_share_list(page_token)
|
188 |
+
|
189 |
|
190 |
@api_router.post(
|
191 |
+
"/file_batch_share", summary="创建分享", description="创建分享", tags=["分享"]
|
192 |
)
|
193 |
+
async def file_batch_share(
|
194 |
+
ids: List[str] = None,
|
195 |
+
need_password: bool | None = False,
|
196 |
+
expiration_days: int | None = -1,
|
197 |
+
):
|
198 |
+
return await THUNDERX_CLIENT.file_batch_share(ids, need_password, expiration_days)
|
199 |
|
200 |
|
201 |
+
@api_router.post(
|
202 |
+
"/file_batch_delete", summary="取消分享", description="取消分享", tags=["分享"]
|
203 |
+
)
|
204 |
+
async def file_batch_delete(ids: List[str]):
|
205 |
+
return await THUNDERX_CLIENT.file_batch_delete(ids)
|
206 |
+
|
207 |
|
208 |
@api_router.post(
|
209 |
+
"/get_share_folder",
|
210 |
+
summary="获取分享信息",
|
211 |
+
description="获取分享信息",
|
212 |
+
tags=["分享"],
|
213 |
)
|
214 |
+
async def get_share_folder(
|
215 |
+
share_id: str, pass_code_token: str | None = None, parent_id: str | None = None
|
216 |
+
):
|
217 |
+
return await THUNDERX_CLIENT.get_share_folder(share_id, pass_code_token, parent_id)
|
218 |
|
219 |
|
220 |
@api_router.post(
|
221 |
+
"/restore", summary="转存分享文件", description="转存分享文件", tags=["分享"]
|
222 |
)
|
223 |
+
async def restore(
|
224 |
+
share_id: str, pass_code_token: str | None = None, file_ids: List[str] | None = None
|
225 |
+
):
|
226 |
+
return await THUNDERX_CLIENT.restore(share_id, pass_code_token, file_ids)
|
227 |
+
|
228 |
+
|
229 |
+
############## 离线任务 ################
|
230 |
|
231 |
|
232 |
@api_router.get(
|
233 |
+
"/offline", summary="离线任务列表", description="离线任务列表", tags=["离线任务"]
|
234 |
)
|
235 |
async def offline_list(size: int = 10000, next_page_token: str | None = None):
|
236 |
return await THUNDERX_CLIENT.offline_list(
|
|
|
239 |
phase=None,
|
240 |
)
|
241 |
|
242 |
+
|
243 |
@api_router.post(
|
244 |
+
"/offline", summary="添加离线任务", description="添加离线任务", tags=["离线任务"]
|
245 |
)
|
246 |
async def offline(item: OfflineRequest):
|
247 |
return await THUNDERX_CLIENT.offline_download(
|
|
|
249 |
)
|
250 |
|
251 |
|
252 |
+
@api_router.post(
|
253 |
+
"/delete_tasks",
|
254 |
+
summary="删除离线任务",
|
255 |
+
description="删除离线任务",
|
256 |
+
tags=["离线任务"],
|
257 |
+
)
|
258 |
+
async def delete_tasks(task_ids: List[str], delete_files: bool = False):
|
259 |
+
return await THUNDERX_CLIENT.delete_tasks(task_ids, delete_files)
|
260 |
+
|
261 |
+
|
262 |
+
############## 账号 ################
|
263 |
@api_router.get(
|
264 |
+
"/userinfo", summary="用户信息", description="获取用户登陆信息", tags=["账号"]
|
265 |
)
|
266 |
async def userinfo():
|
267 |
return THUNDERX_CLIENT.get_user_info()
|
268 |
|
269 |
|
270 |
@api_router.get(
|
271 |
+
"/quota", summary="空间使用信息", description="获取空间使用信息", tags=["账号"]
|
272 |
)
|
273 |
async def quota_info():
|
274 |
return await THUNDERX_CLIENT.get_quota_info()
|
275 |
|
276 |
|
|
|
277 |
@api_router.get(
|
278 |
+
"/invite_code", summary="查看邀请码", description="查看邀请码", tags=["账号"]
|
279 |
)
|
280 |
async def get_invite_code():
|
281 |
return await THUNDERX_CLIENT.get_invite_code()
|
282 |
|
283 |
|
|
|
284 |
app.include_router(front_router)
|
285 |
app.include_router(api_router)
|
pikpakapi/__init__.py
CHANGED
@@ -908,43 +908,6 @@ class PikPakApi:
|
|
908 |
)
|
909 |
return result
|
910 |
|
911 |
-
async def file_batch_share(
|
912 |
-
self,
|
913 |
-
ids: List[str],
|
914 |
-
need_password: Optional[bool] = False,
|
915 |
-
expiration_days: Optional[int] = -1,
|
916 |
-
) -> Dict[str, Any]:
|
917 |
-
"""
|
918 |
-
ids: List[str] - 文件id列表
|
919 |
-
need_password: Optional[bool] - 是否需要分享密码
|
920 |
-
expiration_days: Optional[int] - 分享天数
|
921 |
-
|
922 |
-
批量分享文件,并生成分享链接
|
923 |
-
返回数据结构:
|
924 |
-
{
|
925 |
-
"share_id": "xxx", //分享ID
|
926 |
-
"share_url": "https://mypikpak.com/s/xxx", // 分享链接
|
927 |
-
"pass_code": "53fe", // 分享密码
|
928 |
-
"share_text": "https://mypikpak.com/s/xxx",
|
929 |
-
"share_list": []
|
930 |
-
}
|
931 |
-
"""
|
932 |
-
data = {
|
933 |
-
"file_ids": ids,
|
934 |
-
"share_to": "copy",
|
935 |
-
"restore_limit":"-1",
|
936 |
-
"expiration_days":"-1",
|
937 |
-
"expiration_days": expiration_days,
|
938 |
-
"pass_code_option": "REQUIRED" if need_password else "NOT_REQUIRED",
|
939 |
-
}
|
940 |
-
captcha_result = await self.captcha_init(f"POST:/drive/v1/share")
|
941 |
-
self.captcha_token = captcha_result.get("captcha_token")
|
942 |
-
result = await self._request_post(
|
943 |
-
url=f"https://{self.PIKPAK_API_HOST}/drive/v1/share",
|
944 |
-
data=data,
|
945 |
-
)
|
946 |
-
return result
|
947 |
-
|
948 |
async def get_quota_info(self) -> Dict[str, Any]:
|
949 |
"""
|
950 |
获取当前空间的quota信息
|
@@ -998,6 +961,87 @@ class PikPakApi:
|
|
998 |
result = await self._request_get(url)
|
999 |
return result
|
1000 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1001 |
async def get_share_folder(
|
1002 |
self, share_id: str, pass_code_token: str, parent_id: str = None
|
1003 |
) -> Dict[str, Any]:
|
|
|
908 |
)
|
909 |
return result
|
910 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
911 |
async def get_quota_info(self) -> Dict[str, Any]:
|
912 |
"""
|
913 |
获取当前空间的quota信息
|
|
|
961 |
result = await self._request_get(url)
|
962 |
return result
|
963 |
|
964 |
+
async def file_batch_share(
|
965 |
+
self,
|
966 |
+
ids: List[str],
|
967 |
+
need_password: Optional[bool] = False,
|
968 |
+
expiration_days: Optional[int] = -1,
|
969 |
+
) -> Dict[str, Any]:
|
970 |
+
"""
|
971 |
+
ids: List[str] - 文件id列表
|
972 |
+
need_password: Optional[bool] - 是否需要分享密码
|
973 |
+
expiration_days: Optional[int] - 分享天数
|
974 |
+
|
975 |
+
批量分享文件,并生成分享链接
|
976 |
+
返回数据结构:
|
977 |
+
{
|
978 |
+
"share_id": "xxx", //分享ID
|
979 |
+
"share_url": "https://mypikpak.com/s/xxx", // 分享链接
|
980 |
+
"pass_code": "53fe", // 分享密码
|
981 |
+
"share_text": "https://mypikpak.com/s/xxx",
|
982 |
+
"share_list": []
|
983 |
+
}
|
984 |
+
"""
|
985 |
+
data = {
|
986 |
+
"file_ids": ids,
|
987 |
+
"share_to": "copy",
|
988 |
+
"restore_limit": "-1",
|
989 |
+
"expiration_days": "-1",
|
990 |
+
"expiration_days": expiration_days,
|
991 |
+
"pass_code_option": "REQUIRED" if need_password else "NOT_REQUIRED",
|
992 |
+
}
|
993 |
+
captcha_result = await self.captcha_init(f"POST:/drive/v1/share")
|
994 |
+
self.captcha_token = captcha_result.get("captcha_token")
|
995 |
+
result = await self._request_post(
|
996 |
+
url=f"https://{self.PIKPAK_API_HOST}/drive/v1/share",
|
997 |
+
data=data,
|
998 |
+
)
|
999 |
+
return result
|
1000 |
+
|
1001 |
+
async def file_batch_delete(
|
1002 |
+
self,
|
1003 |
+
ids: List[str],
|
1004 |
+
) -> Dict[str, Any]:
|
1005 |
+
"""
|
1006 |
+
ids: List[str] - 文件id列表
|
1007 |
+
|
1008 |
+
批量分享文件,并生成分享链接
|
1009 |
+
返回数据结构:
|
1010 |
+
{
|
1011 |
+
"share_id": "xxx", //分享ID
|
1012 |
+
"share_url": "https://mypikpak.com/s/xxx", // 分享链接
|
1013 |
+
"pass_code": "53fe", // 分享密码
|
1014 |
+
"share_text": "https://mypikpak.com/s/xxx",
|
1015 |
+
"share_list": []
|
1016 |
+
}
|
1017 |
+
"""
|
1018 |
+
data = {
|
1019 |
+
"ids": ids,
|
1020 |
+
}
|
1021 |
+
captcha_result = await self.captcha_init(f"POST:/drive/v1/share:batchDelete")
|
1022 |
+
self.captcha_token = captcha_result.get("captcha_token")
|
1023 |
+
result = await self._request_post(
|
1024 |
+
url=f"https://{self.PIKPAK_API_HOST}/drive/v1/share:batchDelete",
|
1025 |
+
data=data,
|
1026 |
+
)
|
1027 |
+
return result
|
1028 |
+
|
1029 |
+
async def get_share_list(
|
1030 |
+
self, next_page_token: Optional[str] = None
|
1031 |
+
) -> Dict[str, Any]:
|
1032 |
+
"""
|
1033 |
+
获取账号下所有分享信息
|
1034 |
+
"""
|
1035 |
+
data = {
|
1036 |
+
"limit": "100",
|
1037 |
+
"thumbnail_size": "SIZE_SMALL",
|
1038 |
+
"page_token": next_page_token,
|
1039 |
+
}
|
1040 |
+
url = f"https://{self.PIKPAK_API_HOST}/drive/v1/share/list"
|
1041 |
+
captcha_result = await self.captcha_init(f"GET:/drive/v1/share/list")
|
1042 |
+
self.captcha_token = captcha_result.get("captcha_token")
|
1043 |
+
return await self._request_get(url, params=data)
|
1044 |
+
|
1045 |
async def get_share_folder(
|
1046 |
self, share_id: str, pass_code_token: str, parent_id: str = None
|
1047 |
) -> Dict[str, Any]:
|