fix(storage): handle null values in file sorting to prevent crashes

This commit is contained in:
InfinityPacer
2024-09-26 01:01:27 +08:00
parent 5b1d111a97
commit 3512e7df4a

View File

@@ -1,3 +1,4 @@
from datetime import datetime
from pathlib import Path
from typing import Any, List
@@ -68,9 +69,9 @@ def list(fileitem: schemas.FileItem,
file_list = StorageChain().list_files(fileitem)
if file_list:
if sort == "name":
file_list.sort(key=lambda x: x.name)
file_list.sort(key=lambda x: x.name or "")
else:
file_list.sort(key=lambda x: x.modify_time, reverse=True)
file_list.sort(key=lambda x: x.modify_time or datetime.min, reverse=True)
return file_list