@@ -127,12 +127,32 @@ async def index(code: str, ip: str = Depends(error_ip_limit), s: AsyncSession =
127127 await s .execute (update (Codes ).where (Codes .id == info .id ).values (count = info .count - 1 ))
128128 await s .commit ()
129129 if info .type != 'text' :
130- info .text = f'/select?code={ code } '
131- return {
132- 'detail' : f'取件成功,文件将在{ settings .DELETE_EXPIRE_FILES_INTERVAL } 分钟后删除' ,
133- 'data' : {'type' : info .type , 'text' : info .text , 'name' : info .name , 'code' : info .code }
134- }
130+ if settings .STORAGE_ENGINE == 'filesystem' :
131+ info .text = f'/select?code={ code } '
132+ return {
133+ 'detail' : f'取件成功,文件将在{ settings .DELETE_EXPIRE_FILES_INTERVAL } 分钟后删除' ,
134+ 'data' : {'type' : info .type , 'text' : info .text , 'name' : info .name , 'code' : info .code }
135+ }
136+ elif settings .STORAGE_ENGINE == 'aliyunsystem' :
137+ info .text = await storage .get_filepath (info .text )
138+ return {
139+ 'detail' : f'取件成功,链接将在{ settings .ACCESSTIME } 秒后失效' ,
140+ 'data' : {'type' : info .type , 'text' : info .text , 'name' : info .name , 'code' : info .code }
141+ }
135142
143+ @app .post ('/adminDownloadFile' ,dependencies = [Depends (admin_required )], description = '管理员获取资源链接' )
144+ async def admindownloadfile (filetext : str , s : AsyncSession = Depends (get_session )):
145+ if storage .STORAGE_ENGINE == 'aliyunsystem' :
146+ filetext = await storage .get_filepath (filetext )
147+ return {
148+ 'detail' : f'获取文件链接成功,链接将在{ settings .ACCESSTIME } 秒后失效' ,
149+ 'fileURL' : filetext
150+ }
151+ elif storage .STORAGE_ENGINE == 'filesystem' :
152+ return {
153+ 'detail' : f'获取文件链接成功' ,
154+ 'fileURL' :filetext
155+ }
136156
137157@app .get ('/banner' )
138158async def banner (request : Request , s : AsyncSession = Depends (get_session )):
@@ -176,7 +196,10 @@ async def get_file(code: str, ip: str = Depends(error_ip_limit), s: AsyncSession
176196 # 如果是文件,返回文件
177197 else :
178198 filepath = await storage .get_filepath (info .text )
179- return FileResponse (filepath , filename = info .name )
199+ if settings .STORAGE_ENGINE == 'filesystem' :
200+ return FileResponse (filepath , filename = info .name )
201+ else :
202+ return {'detail' : '查询成功' , 'data' : filepath }
180203
181204
182205@app .post ('/share' , dependencies = [Depends (admin_required )], description = '分享文件' )
@@ -206,6 +229,8 @@ async def share(background_tasks: BackgroundTasks, text: str = Form(default=None
206229 background_tasks .add_task (storage .save_file , file , _text )
207230 else :
208231 size , _text , _type , name = len (text ), text , 'text' , '文本分享'
232+ if settings .STORAGE_ENGINE == 'aliyunsystem' :
233+ _text = f"https://{ settings .BUCKET_NAME } .{ settings .OSS_ENDPOINT } /" + _text
209234 info = Codes (code = code , text = _text , size = size , type = _type , name = name , count = exp_count , exp_time = exp_time , key = key )
210235 s .add (info )
211236 await s .commit ()
0 commit comments