@@ -19,16 +19,18 @@ async def delete_file(self, file_id: int):
1919 await self .file_storage .delete_file (file_code )
2020 await file_code .delete ()
2121
22- async def list_files (self , page : int , size : int , keyword : str = '' ):
22+ async def list_files (self , page : int , size : int , keyword : str = "" ):
2323 offset = (page - 1 ) * size
24- files = await FileCodes .filter (prefix__icontains = keyword ).limit (size ).offset (offset )
24+ files = (
25+ await FileCodes .filter (prefix__icontains = keyword ).limit (size ).offset (offset )
26+ )
2527 total = await FileCodes .filter (prefix__icontains = keyword ).count ()
2628 return files , total
2729
2830 async def download_file (self , file_id : int ):
2931 file_code = await FileCodes .filter (id = file_id ).first ()
3032 if not file_code :
31- raise HTTPException (status_code = 404 , detail = ' 文件不存在' )
33+ raise HTTPException (status_code = 404 , detail = " 文件不存在" )
3234 if file_code .text :
3335 return APIResponse (detail = file_code .text )
3436 else :
@@ -37,10 +39,12 @@ async def download_file(self, file_id: int):
3739 async def share_local_file (self , item ):
3840 local_file = LocalFileClass (item .filename )
3941 if not await local_file .exists ():
40- raise HTTPException (status_code = 404 , detail = ' 文件不存在' )
42+ raise HTTPException (status_code = 404 , detail = " 文件不存在" )
4143
4244 text = await local_file .read ()
43- expired_at , expired_count , used_count , code = await get_expire_info (item .expire_value , item .expire_style )
45+ expired_at , expired_count , used_count , code = await get_expire_info (
46+ item .expire_value , item .expire_style
47+ )
4448 path , suffix , prefix , uuid_file_name , save_path = await get_file_path_name (item )
4549
4650 await self .file_storage .save_file (text , save_path )
@@ -58,8 +62,8 @@ async def share_local_file(self, item):
5862 )
5963
6064 return {
61- ' code' : code ,
62- ' name' : local_file .file ,
65+ " code" : code ,
66+ " name" : local_file .file ,
6367 }
6468
6569
@@ -68,54 +72,67 @@ def get_config(self):
6872 return settings .items ()
6973
7074 async def update_config (self , data : dict ):
71- admin_token = data .get (' admin_token' )
72- if admin_token is None or admin_token == '' :
73- raise HTTPException (status_code = 400 , detail = ' 管理员密码不能为空' )
75+ admin_token = data .get (" admin_token" )
76+ if admin_token is None or admin_token == "" :
77+ raise HTTPException (status_code = 400 , detail = " 管理员密码不能为空" )
7478
7579 for key , value in data .items ():
7680 if key not in settings .default_config :
7781 continue
78- if key in ['errorCount' , 'errorMinute' , 'max_save_seconds' , 'onedrive_proxy' , 'openUpload' , 'port' , 's3_proxy' , 'uploadCount' , 'uploadMinute' , 'uploadSize' ]:
82+ if key in [
83+ "errorCount" ,
84+ "errorMinute" ,
85+ "max_save_seconds" ,
86+ "onedrive_proxy" ,
87+ "openUpload" ,
88+ "port" ,
89+ "s3_proxy" ,
90+ "uploadCount" ,
91+ "uploadMinute" ,
92+ "uploadSize" ,
93+ ]:
7994 data [key ] = int (value )
80- elif key in [' opacity' ]:
95+ elif key in [" opacity" ]:
8196 data [key ] = float (value )
8297 else :
8398 data [key ] = value
8499
85- await KeyValue .filter (key = ' settings' ).update (value = data )
100+ await KeyValue .filter (key = " settings" ).update (value = data )
86101 for k , v in data .items ():
87102 settings .__setattr__ (k , v )
88103
89104
90105class LocalFileService :
91106 async def list_files (self ):
92107 files = []
93- if not os .path .exists (data_root / ' local' ):
94- os .makedirs (data_root / ' local' )
95- for file in os .listdir (data_root / ' local' ):
108+ if not os .path .exists (data_root / " local" ):
109+ os .makedirs (data_root / " local" )
110+ for file in os .listdir (data_root / " local" ):
96111 files .append (LocalFileClass (file ))
97112 return files
98113
99114 async def delete_file (self , filename : str ):
100115 file = LocalFileClass (filename )
101116 if await file .exists ():
102117 await file .delete ()
103- return ' 删除成功'
104- raise HTTPException (status_code = 404 , detail = ' 文件不存在' )
118+ return " 删除成功"
119+ raise HTTPException (status_code = 404 , detail = " 文件不存在" )
105120
106121
107122class LocalFileClass :
108123 def __init__ (self , file ):
109124 self .file = file
110- self .path = data_root / 'local' / file
111- self .ctime = time .strftime ('%Y-%m-%d %H:%M:%S' , time .localtime (os .path .getctime (self .path )))
125+ self .path = data_root / "local" / file
126+ self .ctime = time .strftime (
127+ "%Y-%m-%d %H:%M:%S" , time .localtime (os .path .getctime (self .path ))
128+ )
112129 self .size = os .path .getsize (self .path )
113130
114131 async def read (self ):
115- return open (self .path , 'rb' )
132+ return open (self .path , "rb" )
116133
117134 async def write (self , data ):
118- with open (self .path , 'w' ) as f :
135+ with open (self .path , "w" ) as f :
119136 f .write (data )
120137
121138 async def delete (self ):
0 commit comments