fix(openlist): request full directory pages

This commit is contained in:
jxxghp
2026-05-26 18:12:10 +08:00
parent 31554bdcb5
commit db8363fee1
2 changed files with 22 additions and 8 deletions

View File

@@ -16,6 +16,10 @@ from app.utils.singleton import WeakSingleton
from app.utils.url import UrlUtils
# OpenList/AList 在 per_page<=0 时会退回后端默认 200显式指定最大页大小避免大目录被截断。
OPENLIST_MAX_LIST_PAGE_SIZE = 500
class Alist(StorageBase, metaclass=WeakSingleton):
"""
Openlist相关操作
@@ -201,6 +205,8 @@ class Alist(StorageBase, metaclass=WeakSingleton):
return []
items = []
current_page = page
auto_page = per_page <= 0
effective_per_page = OPENLIST_MAX_LIST_PAGE_SIZE if auto_page else per_page
while True:
resp = RequestUtils(headers=self.__get_header_with_token()).post_res(
self.__get_api_url("/api/fs/list"),
@@ -208,7 +214,7 @@ class Alist(StorageBase, metaclass=WeakSingleton):
"path": fileitem.path,
"password": password,
"page": current_page,
"per_page": per_page,
"per_page": effective_per_page,
"refresh": refresh,
},
)
@@ -267,7 +273,8 @@ class Alist(StorageBase, metaclass=WeakSingleton):
)
return []
page_content = result["data"].get("content") or []
page_data = result["data"]
page_content = page_data.get("content") or []
items.extend(
[
schemas.FileItem(
@@ -286,12 +293,16 @@ class Alist(StorageBase, metaclass=WeakSingleton):
]
)
if per_page > 0:
if not auto_page:
return items
total = result["data"].get("total") or 0
total = page_data.get("filtered_total") or page_data.get("total") or 0
pages_total = page_data.get("pages_total") or 0
has_more = page_data.get("has_more")
if not page_content or len(items) >= total:
return items
if has_more is False or (pages_total and current_page >= pages_total):
return items
current_page += 1