Skip to content

Commit 775d109

Browse files
committed
fix: 修复 alist 会缓存链接的问题
1 parent 49fd95f commit 775d109

File tree

2 files changed

+42
-51
lines changed

2 files changed

+42
-51
lines changed

core/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def rank_clusters_url(self):
170170

171171
const = Const()
172172

173-
VERSION = "3.3.3"
173+
VERSION = "3.3.4"
174174
API_VERSION = "1.13.1"
175175
USER_AGENT = f"openbmclapi/{API_VERSION} python-openbmclapi/{VERSION}"
176176
PYTHON_VERSION = ".".join(map(str, (sys.version_info.major, sys.version_info.minor, sys.version_info.micro)))

core/storages/__init__.py

Lines changed: 41 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,9 @@ def __str__(self) -> str:
281281
def __repr__(self) -> str:
282282
return f"AlistStorage({self.path})"
283283

284-
async def _action_data(self, action: str, url: str, data: Any, headers: dict[str, str] = {}, session: Optional[aiohttp.ClientSession] = None, _authentication: bool = False) -> AlistResult:
284+
async def _action_data(self, action: str, url: str, data: Any, headers: dict[str, str] = {}, session: Optional[aiohttp.ClientSession] = None, _authentication: bool = False, cache: bool = True) -> AlistResult:
285285
hash = hashlib.sha256(f"{action},{url},{data},{headers}".encode()).hexdigest()
286-
if hash in self.cache:
286+
if cache and hash in self.cache:
287287
return self.cache.get(hash)
288288
session = self.session
289289
async with session.request(
@@ -305,7 +305,7 @@ async def _action_data(self, action: str, url: str, data: Any, headers: dict[str
305305
self.last_token = 0
306306
self.wait_token.acquire()
307307
await self.wait_token.wait()
308-
return await self._action_data(action, url, data, headers, session, True)
308+
return await self._action_data(action, url, data, headers, session, True, cache)
309309
if result.code != 200:
310310
logger.terror("storage.error.action_alist", method=action, url=url, status=result.code, message=result.message)
311311
logger.debug(data)
@@ -324,7 +324,8 @@ async def __info_file(self, file_hash: str) -> AlistFileInfo:
324324
{
325325
"path": self.get_path(file_hash),
326326
"password": ""
327-
}
327+
},
328+
cache=False
328329
)
329330
if r.code == 500:
330331
return AlistFileInfo(
@@ -382,28 +383,23 @@ def empty():
382383
files: defaultdict[str, deque[File]] = defaultdict(deque)
383384
async def get_files(root_id: int):
384385
root = f"{self.path}/{root_id:02x}"
385-
if f"listfile_{root}" in self.cache:
386-
result = self.cache.get(f"listfile_{root}")
387-
else:
388-
try:
389-
async with session.post(
390-
"/api/fs/list",
391-
data={
392-
"path": str(root)
393-
},
394-
) as resp:
395-
result = AlistResult(
396-
**await resp.json()
397-
)
398-
if result.code != 200:
399-
logger.tdebug("storage.debug.error_alist", status=result.code, message=result.message)
400-
else:
401-
self.cache.set(f"listfile_{root}", result, 600)
402-
except:
403-
logger.traceback()
404-
return []
405-
finally:
406-
update_tqdm()
386+
try:
387+
async with session.post(
388+
"/api/fs/list",
389+
data={
390+
"path": str(root)
391+
},
392+
) as resp:
393+
result = AlistResult(
394+
**await resp.json()
395+
)
396+
if result.code != 200:
397+
logger.tdebug("storage.debug.error_alist", status=result.code, message=result.message)
398+
except:
399+
logger.traceback()
400+
return []
401+
finally:
402+
update_tqdm()
407403
return ((result.data or {}).get("content", None) or [])
408404
async with aiohttp.ClientSession(
409405
self.url,
@@ -533,30 +529,25 @@ def empty():
533529
files: defaultdict[str, deque[File]] = defaultdict(deque)
534530
async def get_files(root_id: int):
535531
root = f"{self.path}/{root_id:02x}/"
536-
if f"listfile_{root}" in self.cache:
537-
result = self.cache.get(f"listfile_{root}")
538-
return result
539-
else:
540-
try:
541-
result = await self.client.list(
542-
root,
543-
True
544-
)
545-
res = [WebDavFileInfo(
546-
created=utils.parse_isotime_to_timestamp(r["created"]),
547-
modified=utils.parse_gmttime_to_timestamp(r["modified"]),
548-
name=r["name"],
549-
size=int(r["size"])
550-
) for r in result if not r["isdir"]]
551-
self.cache.set(f"listfile_{root}", res, 600)
552-
except webdav3_exceptions.RemoteResourceNotFound:
553-
return []
554-
except:
555-
logger.traceback()
556-
return []
557-
finally:
558-
update_tqdm()
559-
return res
532+
try:
533+
result = await self.client.list(
534+
root,
535+
True
536+
)
537+
res = [WebDavFileInfo(
538+
created=utils.parse_isotime_to_timestamp(r["created"]),
539+
modified=utils.parse_gmttime_to_timestamp(r["modified"]),
540+
name=r["name"],
541+
size=int(r["size"])
542+
) for r in result if not r["isdir"]]
543+
except webdav3_exceptions.RemoteResourceNotFound:
544+
return []
545+
except:
546+
logger.traceback()
547+
return []
548+
finally:
549+
update_tqdm()
550+
return res
560551
for root_id in range(256):
561552
for r in await get_files(root_id):
562553
files[f"{root_id:02x}"].append(File(

0 commit comments

Comments
 (0)