feat: 新增EHR系统花名册检查插件及多个插件版本更新
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
"""文件接口:上传 / 列表 / 删除 / 下载。"""
|
||||
from __future__ import annotations
|
||||
|
||||
import mimetypes
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, UploadFile
|
||||
from fastapi.responses import FileResponse
|
||||
|
||||
@@ -44,14 +46,41 @@ def api_delete(fid: str, _: str = Depends(auth.check_admin)) -> dict:
|
||||
return {"ok": True, "removed": removed, "id": fid}
|
||||
|
||||
|
||||
def _inline_media(name: str) -> str:
|
||||
"""按文件名推断可内联预览的 Content-Type;非图片/音视频/PDF/纯文本返回空(仍按附件下载)。"""
|
||||
media = mimetypes.guess_type(name or "")[0] or ""
|
||||
if media.startswith(("image/", "video/", "audio/")) or media in ("application/pdf", "text/plain"):
|
||||
return media
|
||||
return ""
|
||||
|
||||
|
||||
@router.get("/files/{fid}/{name}")
|
||||
def api_download_named(fid: str, name: str):
|
||||
"""带文件名的开放直链(/files/{fid}/xxx.png):按扩展名 inline 返回,便于钉钉等聊天工具渲染图片。"""
|
||||
p = store.path_of(fid)
|
||||
if p is None:
|
||||
raise HTTPException(404, "文件不存在")
|
||||
store.increment_downloads(fid)
|
||||
media = _inline_media(name)
|
||||
if media:
|
||||
return FileResponse(p, filename=name, media_type=media,
|
||||
content_disposition_type="inline")
|
||||
return FileResponse(p, filename=name, media_type="application/octet-stream")
|
||||
|
||||
|
||||
@router.get("/files/{fid}")
|
||||
def api_download(fid: str, dl: str = ""):
|
||||
"""开放下载(内网直链);?dl=文件名 时以该名 attachment 落盘;统计下载次数。"""
|
||||
"""开放下载(内网直链);?dl=文件名 时以该名 attachment 落盘;图片等按扩展名 inline 便于群内直接显示。"""
|
||||
p = store.path_of(fid)
|
||||
if p is None:
|
||||
raise HTTPException(404, "文件不存在")
|
||||
store.increment_downloads(fid)
|
||||
m = store.meta(fid)
|
||||
default_name = m.get("filename") or fid
|
||||
return FileResponse(p, filename=dl or default_name,
|
||||
media_type="application/octet-stream")
|
||||
if dl:
|
||||
return FileResponse(p, filename=dl, media_type="application/octet-stream")
|
||||
media = _inline_media(default_name)
|
||||
if media:
|
||||
return FileResponse(p, filename=default_name, media_type=media,
|
||||
content_disposition_type="inline")
|
||||
return FileResponse(p, filename=default_name, media_type="application/octet-stream")
|
||||
|
||||
Reference in New Issue
Block a user