- git mv 保留历史:ui/(Vue3+Vite)、sdk/(BFF 中间层)
- 路径语义修正:db_path/figures_cache 改相对 sdk/(BFF cwd),
历史库 sdk/backend/data 迁移至 sdk/data/(会话/图片缓存无损)
- 引用修复 ~15 处:config.py、deploy/*.sh、vitest/playwright 配置、
单测导入路径、docs、README、gitignore、.env.example
- 骨架:agent/{qa,methodology,legacy-rag,vendor}、knowledge/manifest.yaml、
tooling/{compile,kb,crypto,assemble,audit,tools,scripts} + README
- 门禁验证:sdk pytest 125 通过、ui vitest 158 通过、
生产 BFF 脚本重启四上游全绿 + 静态托管 + 会话库无损
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
"""routers/figures.py —— 图片清单与代理端点(2026-08-28 图文并茂方案)。"""
|
|
from __future__ import annotations
|
|
|
|
from fastapi import APIRouter, Query
|
|
from fastapi.responses import Response
|
|
|
|
from ..services import figures as figs
|
|
|
|
router = APIRouter(prefix="/api/figures", tags=["figures"])
|
|
|
|
|
|
@router.get("/proxy")
|
|
async def figure_proxy(pmcid: str = Query(...), url: str = Query(...)):
|
|
"""图片代理:本地文件直接读 / 外网拉取 + 磁盘缓存。
|
|
|
|
注意:必须声明在 /{pmcid} 之前——否则 /proxy 会被 /{pmcid} 捕获(pmcid="proxy")。
|
|
"""
|
|
result = await figs.proxy_figure(pmcid, url)
|
|
if result is None:
|
|
return Response(status_code=404, content=b"")
|
|
content, content_type = result
|
|
return Response(
|
|
content=content,
|
|
media_type=content_type,
|
|
headers={"Cache-Control": "public, max-age=86400"},
|
|
)
|
|
|
|
|
|
@router.get("/{pmcid}")
|
|
async def figure_list(pmcid: str, limit: int = Query(4, ge=1, le=8)):
|
|
"""按 PMCID 返回图片清单(本地优先,PMC 兜底)。"""
|
|
return await figs.resolve_figures(pmcid, limit=limit)
|