Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,21 @@ async def list_avatars():
})
return result

_CDN_CACHE_HEADERS = {"Cache-Control": "public, max-age=86400"}


@app.get("/api/avatars/{avatar_id}/image")
async def get_avatar_image(avatar_id: str):
p = _find_preset(avatar_id)
if p:
path = AVATARS_DIR / p["file"]
if path.exists():
return FileResponse(path, media_type="image/png")
return FileResponse(path, media_type="image/png", headers=_CDN_CACHE_HEADERS)
meta = _load_meta()
if avatar_id in meta:
path = UPLOADS_DIR / meta[avatar_id]["file"]
if path.exists():
return FileResponse(path)
return FileResponse(path, headers=_CDN_CACHE_HEADERS)
Comment on lines 163 to +167
raise HTTPException(404, "角色不存在")


Expand Down Expand Up @@ -190,7 +193,7 @@ async def get_avatar_thumbnail(avatar_id: str):
if not source_path or not source_path.exists():
raise HTTPException(404, "角色不存在")
thumb_path = _make_thumbnail(source_path, avatar_id)
return FileResponse(thumb_path, media_type="image/webp")
return FileResponse(thumb_path, media_type="image/webp", headers=_CDN_CACHE_HEADERS)


@app.post("/api/avatars/upload")
Expand Down