add:通过接口直接下载文件,方便终端取件
This commit is contained in:
+25
-6
@@ -61,14 +61,33 @@ async def share_file(expire_value: int = Form(default=1, gt=0), expire_style: st
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
async def get_code_file_by_code(code):
|
||||||
|
file_code = await FileCodes.filter(code=code).first()
|
||||||
|
if not file_code:
|
||||||
|
return False, '文件不存在'
|
||||||
|
if await file_code.is_expired():
|
||||||
|
return False, '文件已过期',
|
||||||
|
return True, file_code
|
||||||
|
|
||||||
|
|
||||||
|
@share_api.get('/select/')
|
||||||
|
async def get_code_file(code: str, ip: str = Depends(error_ip_limit)):
|
||||||
|
has, file_code = await get_code_file_by_code(code)
|
||||||
|
if not has:
|
||||||
|
error_ip_limit.add_ip(ip)
|
||||||
|
return APIResponse(code=404, detail=file_code)
|
||||||
|
file_code.used_count += 1
|
||||||
|
file_code.expired_count -= 1
|
||||||
|
await file_code.save()
|
||||||
|
return await file_storage.get_file_response(file_code)
|
||||||
|
|
||||||
|
|
||||||
@share_api.post('/select/')
|
@share_api.post('/select/')
|
||||||
async def select_file(data: SelectFileModel, ip: str = Depends(error_ip_limit)):
|
async def select_file(data: SelectFileModel, ip: str = Depends(error_ip_limit)):
|
||||||
file_code = await FileCodes.filter(code=data.code).first()
|
has, file_code = await get_code_file_by_code(data.code)
|
||||||
if not file_code:
|
if not has:
|
||||||
error_ip_limit.add_ip(ip)
|
error_ip_limit.add_ip(ip)
|
||||||
return APIResponse(code=404, detail='文件不存在')
|
return APIResponse(code=404, detail=file_code)
|
||||||
if await file_code.is_expired():
|
|
||||||
return APIResponse(code=403, detail='文件已过期')
|
|
||||||
file_code.used_count += 1
|
file_code.used_count += 1
|
||||||
file_code.expired_count -= 1
|
file_code.expired_count -= 1
|
||||||
await file_code.save()
|
await file_code.save()
|
||||||
@@ -85,7 +104,7 @@ async def download_file(key: str, code: str, ip: str = Depends(error_ip_limit)):
|
|||||||
is_valid = await get_select_token(code) == key
|
is_valid = await get_select_token(code) == key
|
||||||
if not is_valid:
|
if not is_valid:
|
||||||
error_ip_limit.add_ip(ip)
|
error_ip_limit.add_ip(ip)
|
||||||
file_code = await FileCodes.filter(code=code).first()
|
has, file_code = await get_code_file_by_code(code)
|
||||||
if not file_code:
|
if not file_code:
|
||||||
return APIResponse(code=404, detail='文件不存在')
|
return APIResponse(code=404, detail='文件不存在')
|
||||||
if file_code.text:
|
if file_code.text:
|
||||||
|
|||||||
Reference in New Issue
Block a user