Skip to content

Commit 3d95b30

Browse files
committed
fix(AlistClient, AlistPath, alist2strm): 更新属性引用,将 path 字段替换为 full_path
1 parent 713654c commit 3d95b30

4 files changed

Lines changed: 24 additions & 19 deletions

File tree

app/modules/alist/v3/client.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,13 @@ async def async_api_fs_list(self, dir_path: str) -> list[AlistPath]:
213213

214214
if result["data"]["total"] == 0:
215215
return []
216-
216+
217217
return [
218218
AlistPath(
219219
server_url=self.url,
220220
base_path=self.base_path,
221-
**{**alist_path, "path": dir_path + "/" + alist_path["name"]}, # 将 V3.45 的 path 字段替换掉
221+
full_path=dir_path + "/" + alist_path["name"],
222+
**alist_path,
222223
)
223224
for alist_path in result["data"]["content"]
224225
]
@@ -255,7 +256,7 @@ async def async_api_fs_get(self, path: str) -> AlistPath:
255256
return AlistPath(
256257
server_url=self.url,
257258
base_path=self.base_path,
258-
_path=path,
259+
full_path=path,
259260
**result["data"],
260261
)
261262

@@ -376,7 +377,7 @@ async def iter_path(
376377
await sleep(wait_time)
377378
if path.is_dir:
378379
async for child_path in self.iter_path(
379-
dir_path=path.path,
380+
dir_path=path.full_path,
380381
wait_time=wait_time,
381382
is_detail=is_detail,
382383
filter=filter,
@@ -385,7 +386,7 @@ async def iter_path(
385386

386387
if filter(path):
387388
if is_detail:
388-
yield await self.async_api_fs_get(path.path)
389+
yield await self.async_api_fs_get(path.full_path)
389390
else:
390391
yield path
391392

app/modules/alist/v3/path.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ class AlistPath(BaseModel):
1313
"""
1414

1515
server_url: str # 服务器地址
16-
base_path: str # 基础路径(用于计算文件/目录在 Alist 服务器上的绝对地址)
17-
path: str # 文件/目录路径
16+
base_path: str # 用户基础路径(用于计算文件/目录在 Alist 服务器上的绝对地址)
17+
full_path: str # 相对用户根文件/目录路径
1818

19-
# id: str | None = None # 文件/目录 ID(Alist V3.45)
20-
# path: str | None = None # 文件/目录路径(Alist V3.45)
19+
id: str | None = None # 文件/目录 ID(Alist V3.45)
20+
path: str | None = None # 相对存储器根目录的文件/目录路径(Alist V3.45)
2121
name: str # 文件/目录名称
2222
size: int # 文件大小
2323
is_dir: bool # 是否为目录
@@ -39,7 +39,7 @@ def abs_path(self) -> str:
3939
"""
4040
文件/目录在 Alist 服务器上的绝对路径
4141
"""
42-
return self.base_path.rstrip("/") + self.path
42+
return self.base_path.rstrip("/") + self.full_path
4343

4444
@property
4545
def download_url(self) -> str:
@@ -58,7 +58,7 @@ def proxy_download_url(self) -> str:
5858
"""
5959
Alist代理下载地址
6060
"""
61-
return sub(r"/d/", "/p/", self.download_url, 1)
61+
return sub("/d/", "/p/", self.download_url, 1)
6262

6363
@property
6464
def suffix(self) -> str:

app/modules/alist2strm/alist2strm.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def filter(path: AlistPath) -> bool:
114114
try:
115115
local_path = self.__get_local_path(path)
116116
except OSError as e: # 可能是文件名过长
117-
logger.warning(f"获取 {path.path} 本地路径失败:{e}")
117+
logger.warning(f"获取 {path.full_path} 本地路径失败:{e}")
118118
return False
119119

120120
self.processed_local_paths.add(local_path)
@@ -124,15 +124,17 @@ def filter(path: AlistPath) -> bool:
124124
local_path_stat = local_path.stat()
125125
if local_path_stat.st_mtime < path.modified_timestamp:
126126
logger.debug(
127-
f"文件 {local_path.name} 已过期,需要重新处理 {path.path}"
127+
f"文件 {local_path.name} 已过期,需要重新处理 {path.full_path}"
128128
)
129129
return True
130130
if local_path_stat.st_size < path.size:
131131
logger.debug(
132-
f"文件 {local_path.name} 大小不一致,可能是本地文件损坏,需要重新处理 {path.path}"
132+
f"文件 {local_path.name} 大小不一致,可能是本地文件损坏,需要重新处理 {path.full_path}"
133133
)
134134
return True
135-
logger.debug(f"文件 {local_path.name} 已存在,跳过处理 {path.path}")
135+
logger.debug(
136+
f"文件 {local_path.name} 已存在,跳过处理 {path.full_path}"
137+
)
136138
return False
137139

138140
return True
@@ -177,7 +179,7 @@ async def __file_processer(self, path: AlistPath) -> None:
177179
elif self.mode == "RawURL":
178180
content = path.raw_url
179181
elif self.mode == "AlistPath":
180-
content = path.path
182+
content = path.full_path
181183
else:
182184
raise ValueError(f"AlistStrm 未知的模式 {self.mode}")
183185

@@ -203,7 +205,7 @@ def __get_local_path(self, path: AlistPath) -> Path:
203205
if self.flatten_mode:
204206
local_path = self.target_dir / path.name
205207
else:
206-
relative_path = path.path.replace(self.source_dir, "", 1)
208+
relative_path = path.full_path.replace(self.source_dir, "", 1)
207209
if relative_path.startswith("/"):
208210
relative_path = relative_path[1:]
209211
local_path = self.target_dir / relative_path

tests/test_alist.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ def test_alist_path_initialization_old(self) -> None:
219219
path = AlistPath(
220220
server_url="https://alist.nn.ci",
221221
base_path="/",
222-
**{**item, "path": "/" + item["name"]},
222+
full_path="/" + item["name"],
223+
**item,
223224
)
224225
self.assertIsInstance(path, AlistPath)
225226
self.assertEqual(path.name, item["name"])
@@ -298,7 +299,8 @@ def test_alist_path_initialization_new(self) -> None:
298299
path = AlistPath(
299300
server_url="https://alist.nn.ci",
300301
base_path="/",
301-
**{**item, "path": "/" + item["name"]},
302+
full_path="/" + item["name"],
303+
**item,
302304
)
303305

304306
self.assertIsInstance(path, AlistPath)

0 commit comments

Comments
 (0)