improvement(sns-media): 悬停展示朋友圈媒体来源阶段

- SNS 页面在封面/媒体悬停时显示来源阶段标识

- 后端媒体接口补充 X-SNS-Source 响应头标记命中来源

- CORS 暴露 X-SNS-Source / X-SNS-Hit-Type / X-SNS-X-Enc 供前端读取
This commit is contained in:
2977094657
2026-02-22 11:56:45 +08:00
parent 949990d125
commit 9254d46802
3 changed files with 183 additions and 7 deletions
+1
View File
@@ -47,6 +47,7 @@ app.add_middleware(
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
expose_headers=["X-SNS-Source", "X-SNS-Hit-Type", "X-SNS-X-Enc"],
)
app.include_router(_health_router)
+10 -2
View File
@@ -2749,7 +2749,7 @@ async def get_sns_media(
print(f"===== Hit Bkg Cover ======= {bkg_path}")
return FileResponse(bkg_path, media_type="image/jpeg",
headers={"Cache-Control": "public, max-age=31536000"})
headers={"Cache-Control": "public, max-age=31536000", "X-SNS-Source": "bkg-cover"})
exact_match_path = None
hit_type = ""
@@ -2807,6 +2807,7 @@ async def get_sns_media(
if payload and str(media_type or "").startswith("image/"):
resp = Response(content=payload, media_type=str(media_type or "image/jpeg"))
resp.headers["Cache-Control"] = "public, max-age=86400"
resp.headers["X-SNS-Source"] = "manual-pick"
return resp
except Exception:
pass
@@ -2850,6 +2851,7 @@ async def get_sns_media(
if payload and str(media_type or "").startswith("image/"):
resp = Response(content=payload, media_type=str(media_type or "image/jpeg"))
resp.headers["Cache-Control"] = "public, max-age=86400"
resp.headers["X-SNS-Source"] = "local-heuristic"
return resp
except Exception:
pass
@@ -2881,6 +2883,7 @@ async def get_sns_media(
if payload and str(media_type or "").startswith("image/"):
resp = Response(content=payload, media_type=str(media_type or "image/jpeg"))
resp.headers["Cache-Control"] = "public, max-age=86400"
resp.headers["X-SNS-Source"] = "local-heuristic-next"
return resp
except Exception:
continue
@@ -2894,7 +2897,12 @@ async def get_sns_media(
from .chat_media import proxy_image # pylint: disable=import-outside-toplevel
try:
return await proxy_image(u)
resp0 = await proxy_image(u)
try:
resp0.headers["X-SNS-Source"] = "proxy"
except Exception:
pass
return resp0
except HTTPException:
raise
except Exception as e: