add:支持使用阿里云OSS进行对象存储服务

fix:删除utils中未使用的第三方库chardet
This commit is contained in:
ZHYCarge
2023-01-15 22:06:01 +08:00
parent a142242bca
commit f87571e693
7 changed files with 93 additions and 10 deletions
+9 -3
View File
@@ -127,7 +127,8 @@ async def index(code: str, ip: str = Depends(error_ip_limit), s: AsyncSession =
await s.execute(update(Codes).where(Codes.id == info.id).values(count=info.count - 1))
await s.commit()
if info.type != 'text':
info.text = f'/select?code={code}'
if settings.STORAGE_ENGINE == 'filesystem':
info.text = f'/select?code={code}'
return {
'detail': f'取件成功,文件将在{settings.DELETE_EXPIRE_FILES_INTERVAL}分钟后删除',
'data': {'type': info.type, 'text': info.text, 'name': info.name, 'code': info.code}
@@ -175,8 +176,11 @@ async def get_file(code: str, ip: str = Depends(error_ip_limit), s: AsyncSession
return {'detail': '查询成功', 'data': info.text}
# 如果是文件,返回文件
else:
filepath = await storage.get_filepath(info.text)
return FileResponse(filepath, filename=info.name)
if settings.STORAGE_ENGINE == 'filesystem':
filepath = await storage.get_filepath(info.text)
return FileResponse(filepath, filename=info.name)
else:
return {'detail': '查询成功', 'data': info.text}
@app.post('/share', dependencies=[Depends(admin_required)], description='分享文件')
@@ -206,6 +210,8 @@ async def share(background_tasks: BackgroundTasks, text: str = Form(default=None
background_tasks.add_task(storage.save_file, file, _text)
else:
size, _text, _type, name = len(text), text, 'text', '文本分享'
if settings.STORAGE_ENGINE == 'aliyunsystem':
_text = f"https://{settings.BUCKET_NAME}.{settings.OSS_ENDPOINT}/"+_text
info = Codes(code=code, text=_text, size=size, type=_type, name=name, count=exp_count, exp_time=exp_time, key=key)
s.add(info)
await s.commit()