44from core .response import APIResponse
55from core .storage import FileStorageInterface , storages
66from core .settings import settings
7- from apps .base .models import FileCodes , KeyValue
7+ from apps .base .models import FileCodes , KeyValue , file_codes_pydantic
88from apps .base .utils import get_expire_info , get_file_path_name
99from fastapi import HTTPException
1010from core .settings import data_root
@@ -26,7 +26,10 @@ async def list_files(self, page: int, size: int, keyword: str = ""):
2626 await FileCodes .filter (prefix__icontains = keyword ).limit (size ).offset (offset )
2727 )
2828 total = await FileCodes .filter (prefix__icontains = keyword ).count ()
29- return files , total
29+ files_pydantic = [
30+ await file_codes_pydantic .from_tortoise_orm (f ) for f in files
31+ ]
32+ return files_pydantic , total
3033
3134 async def download_file (self , file_id : int ):
3235 file_code = await FileCodes .filter (id = file_id ).first ()
@@ -112,7 +115,12 @@ async def list_files(self):
112115 if not os .path .exists (data_root / "local" ):
113116 os .makedirs (data_root / "local" )
114117 for file in os .listdir (data_root / "local" ):
115- files .append (LocalFileClass (file ))
118+ local_file = LocalFileClass (file )
119+ files .append ({
120+ "file" : local_file .file ,
121+ "ctime" : local_file .ctime ,
122+ "size" : local_file .size ,
123+ })
116124 return files
117125
118126 async def delete_file (self , filename : str ):
0 commit comments