Skip to content

Commit

Permalink
0.36.13:
Browse files Browse the repository at this point in the history
    1. alist版本支持到3.36.0
    2. 现在可以使用AlistPath(path, username="", password="", token="")的方式快速登录。
    3. 登录失败现在抛出异常。
  • Loading branch information
lee-cq committed Aug 17, 2024
1 parent 8914ee6 commit 93c27e4
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
max-parallel: 3
matrix:
python-version: ['3.10', '3.11', '3.12']
alist-version: [ '3.30.0', '3.31.0', '3.32.0']
alist-version: [ '3.34.0', '3.35.0', '3.36.0']
fail-fast: false

steps:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ celerybeat.pid
.env
.venv
env/
venv/
venv*/
ENV/
env.bak/
venv.bak/
Expand Down
3 changes: 2 additions & 1 deletion alist_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from httpx import Client as HttpClient, Response
from alist_sdk.models import *
from alist_sdk.verify import verify
from alist_sdk.err import *
from alist_sdk.version import __version__

logger = logging.getLogger("alist-sdk.client")
Expand Down Expand Up @@ -135,7 +136,7 @@ def login(self, username, password, has_opt=False) -> bool:
if res.status_code == 200 and res.json()["code"] == 200:
return self.set_token(res.json()["data"]["token"])
logger.error("登陆失败[%s] %d: %s", self.base_url, res.status_code, res.text)
return False
raise NotLogin("登陆失败[%s] %d: %s" % (self.base_url, res.status_code, res.text))

# ================ FS 相关方法 =================

Expand Down
22 changes: 20 additions & 2 deletions alist_sdk/path_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def login_server(
has_opt=has_opt,
**kwargs,
)

else:
_client = server
ALIST_SERVER_INFO[_client.server_info] = _client
Expand Down Expand Up @@ -104,6 +105,20 @@ def relative_to(self, other, /, *_deprecated, walk_up=False) -> str:
class AlistPath(PureAlistPath):
""""""

def __init__(
self,
*args,
username: str = None,
password: str = None,
token: str = None,
**kwargs,
):
super().__init__(*args)
if username:
login_server(
self.drive, username=username, password=password, token=token, **kwargs
)

@classmethod
def from_client(cls, client: Client, path: str | PurePosixPath) -> "AlistPath":
"""从客户端实例构造
Expand Down Expand Up @@ -133,7 +148,11 @@ def client(self) -> Client:
_server_info = _u.scheme, _u.host, _u.port
return ALIST_SERVER_INFO[_server_info]
except KeyError:
raise AlistError(f"当前服务器[{self.drive}]尚未登陆")
raise AlistError(
f"当前服务器[{self.drive}]尚未登陆。\n"
f"使用AlistPath.from_client构造。\n"
f"或构造AlistPath时传入username等相关信息。"
)

# def is_absolute(self) -> bool:
def get_download_uri(self) -> str:
Expand All @@ -147,7 +166,6 @@ def as_download_uri(self):
return self.get_download_uri()

def raw_stat(self, retry=1, timeout=0.1) -> RawItem:

try:
_raw = self.client.get_item_info(self.as_posix())
if _raw.code == 200:
Expand Down
9 changes: 7 additions & 2 deletions alist_sdk/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,13 @@
4. 修复tools.config.import_configs_from_dict无法忽略本地存储的错误。
5. Client Put AsTask 修复
6. Verify 日志优化
0.36.13:
1. alist版本支持到3.36.0
2. 现在可以使用AlistPath(path, username="", password="", token="")的方式快速登录。
3. 登录失败现在抛出异常。
"""

__version__ = "0.32.12a6"
__version__ = "0.36.13a3"

ALIST_VERSION = "v3.32.0"
ALIST_VERSION = "v3.36.0"
2 changes: 1 addition & 1 deletion tests/init_alist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ fi

rm -rf alist/data/ alist/test_dir/ alist/test_dir_dst/
./alist admin set 123456
sed -i '' 's/: 5244/: 5245/' data/config.json
sed -i'' 's/: 5244/: 5245/' data/config.json
./alist restart

0 comments on commit 93c27e4

Please sign in to comment.