Skip to content

Commit

Permalink
Merge pull request #143 from yanlong-li/master
Browse files Browse the repository at this point in the history
feat: 管理后台文件列表支持下载文件&管理后台文件列表格式化过期时间
  • Loading branch information
vastsa authored Mar 29, 2024
2 parents 77a0fed + 651eeb8 commit e21bee9
Show file tree
Hide file tree
Showing 24 changed files with 152 additions and 40 deletions.
24 changes: 24 additions & 0 deletions apps/admin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,27 @@ async def update_config(data: dict):
for k, v in data.items():
settings.__setattr__(k, v)
return APIResponse()


# 根据id获取文件
async def get_file_by_id(id):
# 查询文件
file_code = await FileCodes.filter(id=id).first()
# 检查文件是否存在
if not file_code:
return False, '文件不存在'
return True, file_code


@admin_api.get('/file/download', dependencies=[Depends(admin_required)])
async def file_download(id: int):
has, file_code = await get_file_by_id(id)
# 检查文件是否存在
if not has:
# 返回API响应
return APIResponse(code=404, detail='文件不存在')
# 如果文件是文本,返回文本内容,否则返回文件响应
if file_code.text:
return APIResponse(detail=file_code.text)
else:
return await file_storage.get_file_response(file_code)

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

20 changes: 0 additions & 20 deletions fcb-fronted/dist/assets/FileView-6d7e8e79.js

This file was deleted.

20 changes: 20 additions & 0 deletions fcb-fronted/dist/assets/FileView-b6badf99.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e21bee9

Please sign in to comment.