Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/api/fs/list 接口验证失败 #3

Closed
wugifer opened this issue Mar 19, 2024 · 3 comments
Closed

/api/fs/list 接口验证失败 #3

wugifer opened this issue Mar 19, 2024 · 3 comments

Comments

@wugifer
Copy link

wugifer commented Mar 19, 2024

执行

client.list_files("/xxx", page=1, per_page=100)

失败,从输出来看,alist 已返回 200,但 list_files() 接口的装饰器 @verify() 执行

resp = Resp.model_validate(res_dict)

失败,错误信息如下

RESP验证错误:
>>> POST http://xxx:5244/api/fs/list
========= Request End =========
<<< content-length: 328

{"code":200,"message":"success","data":{"content":[{"name":"xxx","size":4,"is_dir":false,"modified":"2024-03-19T15:21:13Z","sign":"","thumb":"","type":4},{"name":"xxx","size":3,"is_dir":false,"modified":"2024-03-19T15:10:41Z","sign":"","thumb":"","type":4}],"total":2,"readme":"","write":true,"provider":"xxx"}}
========= Resp End =========

貌似 Resp 的定义覆盖不足

class Resp(_BaseModel):
    code: int
    message: str
    # data: ListTask
    data: (
        None
        | str
        | Me
        | list[DirItem]
        | list[Setting]
        | ListItem
        | ListContents
        | RawItem
        | ListTask
        | list[Task]
        | ID
    )

谢谢!

@wugifer
Copy link
Author

wugifer commented Mar 19, 2024

最接近的类型是 ListItem, 仅报错缺少 created 字段,但 created 字段是 Optional 的:

class Item(BaseModel):
    """文件对象"""
    name: str  # 文件名
    size: int  # 文件大小
    is_dir: bool  # 是否是目录
    hashinfo: Optional[str] = "null"  # v3.29.0
    hash_info: Optional[HashInfo | None] = None  # v3.29.0
    modified: datetime.datetime  # 修改时间
    created: Optional[datetime.datetime]  # v3.29.0 创建时间
    sign: str  # 签名
    thumb: str  # 缩略图
    type: int  # 类型

报错:

data.ListItem.content.0.created
  Field required [type=missing, input_value={'name': 'xxx', 'siz... 'thumb': '', 'type': 4}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.6/v/missing
data.ListItem.content.1.created
  Field required [type=missing, input_value={'name': 'xxx', ... 'thumb': '', 'type': 4}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.6/v/missing

@wugifer
Copy link
Author

wugifer commented Mar 19, 2024

created: Optional[datetime.datetime]

改成

created: Optional[datetime.datetime] = None

可解决

lee-cq added a commit that referenced this issue Aug 17, 2024
    1. alist版本支持到3.36.0
    2. 现在可以使用AlistPath(path, username="", password="", token="")的方式快速登录。
    3. 登录失败现在抛出异常。
    4. #3 Bugfix 为models中的全部可选字段添加默认值。
@lee-cq
Copy link
Owner

lee-cq commented Aug 17, 2024

是的, 所有的Optional字段都应该有一个默认值。

created 字段是 0.29.0 新增的,在之前版本没有此字段会报错。

现在已经修复此Bug

@lee-cq lee-cq closed this as completed Aug 17, 2024
lee-cq added a commit that referenced this issue Aug 17, 2024
    1. alist版本支持到3.36.0
    2. 现在可以使用AlistPath(path, username="", password="", token="")的方式快速登录。
    3. 登录失败现在抛出异常。
    4. #3 Bugfix 为models中的全部可选字段添加默认值。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants