fix(market): 详情接口浏览量+1,下载接口下载量+1(bump_stats 此前定义未调用)

This commit is contained in:
Pine
2026-09-02 14:41:33 +08:00
parent 5db03936f9
commit a689fbdf7f
+19
View File
@@ -93,6 +93,11 @@ async def market_item_detail(
raise HTTPException(status_code=404, detail=str(exc)) from exc
if user:
item["owned"] = await service.has_purchase(db, user["id"], item_id)
# 详情浏览量 +1(异步不阻塞响应)
try:
await service.bump_stats(db, item_id, views=1)
except Exception:
pass
return item
@@ -115,6 +120,11 @@ async def market_item_bundle(
if not owned:
raise HTTPException(status_code=403, detail="未购买该商品,请先完成购买")
if item["item_type"] == "skill":
# skill 下载量 +1
try:
await service.bump_stats(db, item_id, downloads=1)
except Exception:
pass
return JSONResponse(service.bundle_payload(item))
# plugin / appOSS 直链
if not item["bundle_url"]:
@@ -122,10 +132,19 @@ async def market_item_bundle(
key = item["bundle_url"].removeprefix("/oss/")
if key == item["bundle_url"]:
# 本地降级存储(/uploads/...)→ 直接重定向
try:
await service.bump_stats(db, item_id, downloads=1)
except Exception:
pass
return RedirectResponse(url=item["bundle_url"], status_code=302)
url = await oss.download_url(key)
resp = RedirectResponse(url=url, status_code=302)
resp.headers["X-Checksum-Sha256"] = item.get("bundle_sha256", "")
# 下载量 +1
try:
await service.bump_stats(db, item_id, downloads=1)
except Exception:
pass
return resp