From 3512e7df4a5ba5bf2c2191623d12f58ad33884d5 Mon Sep 17 00:00:00 2001 From: InfinityPacer <160988576+InfinityPacer@users.noreply.github.com> Date: Thu, 26 Sep 2024 01:01:27 +0800 Subject: [PATCH] fix(storage): handle null values in file sorting to prevent crashes --- app/api/endpoints/storage.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/api/endpoints/storage.py b/app/api/endpoints/storage.py index a793bb356..69384e488 100644 --- a/app/api/endpoints/storage.py +++ b/app/api/endpoints/storage.py @@ -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