@@ -51,9 +51,13 @@ async def delete_expire_files():
5151 async with AsyncSession (engine , expire_on_commit = False ) as s :
5252 query = select (Codes ).where (or_ (Codes .exp_time < datetime .datetime .now (), Codes .count == 0 ))
5353 exps = (await s .execute (query )).scalars ().all ()
54- files = [{'type' : old .type , 'text' : old .text } for old in exps ]
54+ files = []
55+ exps_ids = []
56+ for exp in exps :
57+ if exp .type != "text" :
58+ files .append (exp .text )
59+ exps_ids .append (exp .id )
5560 await storage .delete_files (files )
56- exps_ids = [exp .id for exp in exps ]
5761 query = delete (Codes ).where (Codes .id .in_ (exps_ids ))
5862 await s .execute (query )
5963 await s .commit ()
@@ -83,9 +87,11 @@ async def admin_post(s: AsyncSession = Depends(get_session)):
8387async def admin_delete (code : str , s : AsyncSession = Depends (get_session )):
8488 query = select (Codes ).where (Codes .code == code )
8589 file = (await s .execute (query )).scalars ().first ()
86- await storage .delete_file ({'type' : file .type , 'text' : file .text })
87- await s .delete (file )
88- await s .commit ()
90+ if file :
91+ if file .type != 'text' :
92+ await storage .delete_file (file .text )
93+ await s .delete (file )
94+ await s .commit ()
8995 return {'detail' : '删除成功' }
9096
9197
@@ -115,7 +121,8 @@ async def index(code: str, ip: str = Depends(ip_limit), s: AsyncSession = Depend
115121 error_count = settings .ERROR_COUNT - ip_limit .add_ip (ip )
116122 raise HTTPException (status_code = 404 , detail = f"取件码错误,错误{ error_count } 次将被禁止10分钟" )
117123 if info .exp_time < datetime .datetime .now () or info .count == 0 :
118- await storage .delete_file ({'type' : info .type , 'text' : info .text })
124+ if info .type != "text" :
125+ await storage .delete_file (info .text )
119126 await s .delete (info )
120127 await s .commit ()
121128 raise HTTPException (status_code = 404 , detail = "取件码已过期,请联系寄件人" )
0 commit comments