Skip to content

Commit

Permalink
更新一下
Browse files Browse the repository at this point in the history
  • Loading branch information
lemisky committed Aug 15, 2023
1 parent 2aee412 commit 8894ce9
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 23 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
datclass>=0.2.6
datclass>=0.2.15
requests
qrcode[pil]
coloredlogs
Expand Down
3 changes: 1 addition & 2 deletions src/aligo/core/Auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import tempfile
import time
import uuid
from dataclasses import asdict
from http.server import HTTPServer
from pathlib import Path
from typing import Callable, overload, List, Dict
Expand Down Expand Up @@ -242,7 +241,7 @@ def _init_x_headers(self):
def _save(self):
"""保存配置文件"""
self.log.info(f'保存配置文件 {self._name}')
json.dump(asdict(self.token), self._name.open('w', encoding='utf8'))
json.dump(self.token.to_dict(), self._name.open('w', encoding='utf8'))

# noinspection PyPep8Naming
def _login(self):
Expand Down
6 changes: 3 additions & 3 deletions src/aligo/core/BaseAligo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
import subprocess
import traceback
from dataclasses import asdict, is_dataclass
from dataclasses import is_dataclass
from typing import Generic, List, Iterator, Dict, Callable, Union
from typing import Type, Optional

Expand Down Expand Up @@ -95,7 +95,7 @@ def post(
if body is None:
body = {}
elif isinstance(body, DatClass):
body = asdict(body)
body = body.to_dict()

if 'drive_id' in body and body['drive_id'] is None:
# 如果存在 attr drive_id 并且它是 None,并将 default_drive_id 设置为它
Expand Down Expand Up @@ -238,7 +238,7 @@ def batch_request(self, body: BatchRequest, body_type: Type[DataType]) -> Iterat
response = self.post(V3_BATCH, body={
"requests": [
{
"body": asdict(request.body) if is_dataclass(request.body) else request.body,
"body": request.body.to_dict() if is_dataclass(request.body) else request.body,
"headers": request.headers,
"id": request.id,
"method": request.method,
Expand Down
3 changes: 1 addition & 2 deletions src/aligo/core/Create.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import hashlib
import math
import os
from dataclasses import asdict
from typing import Union, List

import requests.exceptions
Expand Down Expand Up @@ -40,7 +39,7 @@ def create_file(self, body: CreateFileRequest) -> CreateFileResponse:

def _core_create_folder(self, body: CreateFolderRequest) -> CreateFileResponse:
"""..."""
return self.create_file(CreateFileRequest(**asdict(body)))
return self.create_file(CreateFileRequest(**body.to_dict()))

def complete_file(self, body: CompleteFileRequest) -> BaseFile:
"""
Expand Down
19 changes: 9 additions & 10 deletions src/aligo/core/Share.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""分享相关"""
from dataclasses import asdict
from typing import Iterator

from aligo.core import BaseAligo
from aligo.core.Config import *
from aligo.request import *
from aligo.response import *
from aligo.types import *
from aligo.types import ShareLinkSchema, BaseShareFile, Null


class Share(BaseAligo):
Expand Down Expand Up @@ -78,7 +77,7 @@ def _core_get_share_file_list(
x_share_token: GetShareTokenResponse
) -> Iterator[BaseShareFile]:
"""..."""
response = self._auth.post(ADRIVE_V3_FILE_LIST, body=asdict(body), headers={'x-share-token': x_share_token},
response = self._auth.post(ADRIVE_V3_FILE_LIST, body=body.to_dict(), headers={'x-share-token': x_share_token},
ignore_auth=True)
file_list = self._result(response, GetShareFileListResponse)
if isinstance(file_list, Null):
Expand All @@ -95,7 +94,7 @@ def _core_list_by_share(
x_share_token: GetShareTokenResponse
) -> Iterator[BaseShareFile]:
"""..."""
response = self._auth.post(ADRIVE_V2_FILE_LIST_BY_SHARE, body=asdict(body),
response = self._auth.post(ADRIVE_V2_FILE_LIST_BY_SHARE, body=body.to_dict(),
headers={'x-share-token': x_share_token}, ignore_auth=True)
file_list = self._result(response, GetShareFileListResponse)
if isinstance(file_list, Null):
Expand All @@ -112,7 +111,7 @@ def _core_get_share_file(
x_share_token: GetShareTokenResponse
) -> BaseShareFile:
"""..."""
response = self._auth.post(V2_FILE_GET, body=asdict(body), headers={'x-share-token': x_share_token},
response = self._auth.post(V2_FILE_GET, body=body.to_dict(), headers={'x-share-token': x_share_token},
ignore_auth=True)
share_file = self._result(response, BaseShareFile)
return share_file
Expand All @@ -123,7 +122,7 @@ def _core_get_by_share(
x_share_token: GetShareTokenResponse
) -> BaseShareFile:
"""..."""
response = self._auth.post(ADRIVE_V2_FILE_GET_BY_SHARE, body=asdict(body),
response = self._auth.post(ADRIVE_V2_FILE_GET_BY_SHARE, body=body.to_dict(),
headers={'x-share-token': x_share_token},
ignore_auth=True)
share_file = self._result(response, BaseShareFile)
Expand All @@ -137,7 +136,7 @@ def _core_get_share_link_download_url(
"""..."""
response = self._auth.post(
V2_FILE_GET_SHARE_LINK_DOWNLOAD_URL,
body=asdict(body),
body=body.to_dict(),
headers={'x-share-token': x_share_token})
download_url = self._result(response, GetShareLinkDownloadUrlResponse)
return download_url
Expand All @@ -149,7 +148,7 @@ def _core_share_file_saveto_drive(
"""..."""
if body.to_drive_id is None:
body.to_drive_id = self.default_drive_id
response = self._auth.post(V2_FILE_COPY, body=asdict(body), headers={'x-share-token': x_share_token})
response = self._auth.post(V2_FILE_COPY, body=body.to_dict(), headers={'x-share-token': x_share_token})
return self._result(response, ShareFileSaveToDriveResponse, [201, 202])

def _core_batch_share_file_saveto_drive(
Expand All @@ -164,13 +163,13 @@ def _core_batch_share_file_saveto_drive(
response = self._auth.post(ADRIVE_V2_BATCH, body={
"requests": [
{
"body": asdict(ShareFileSaveToDriveRequest(
"body": ShareFileSaveToDriveRequest(
file_id=file_id,
share_id=body.share_id,
to_parent_file_id=body.to_parent_file_id,
to_drive_id=body.to_drive_id,
auto_rename=body.auto_rename,
)),
).to_dict(),
"headers": {
'Content-Type': 'application/json',
},
Expand Down
3 changes: 1 addition & 2 deletions src/aligo/core/Star.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""收藏相关"""
from dataclasses import asdict
from typing import Iterator

from aligo.core.Config import V2_FILE_LIST_BY_CUSTOM_INDEX_KEY
Expand All @@ -16,7 +15,7 @@ class Star(Update):

def _core_starred_file(self, body: StarredFileRequest) -> BaseFile:
"""收藏(或取消) 文件"""
return self.update_file(UpdateFileRequest(**asdict(body)))
return self.update_file(UpdateFileRequest(**body.to_dict()))

def _core_batch_star_files(self, body: BatchStarFilesRequest) -> Iterator[BatchSubResponse[BaseFile]]:
"""批量收藏文件"""
Expand Down
4 changes: 1 addition & 3 deletions src/aligo/core/Update.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""..."""
from dataclasses import asdict

from aligo.core import BaseAligo
from aligo.core.Config import V3_FILE_UPDATE
from aligo.request import UpdateFileRequest, RenameFileRequest
Expand All @@ -27,4 +25,4 @@ def update_file(self, body: UpdateFileRequest) -> BaseFile:

def _core_rename_file(self, body: RenameFileRequest) -> BaseFile:
"""..."""
return self.update_file(UpdateFileRequest(**asdict(body)))
return self.update_file(UpdateFileRequest(**body.to_dict()))

0 comments on commit 8894ce9

Please sign in to comment.