From a689fbdf7f80b85701b8e282d397f5f4f6d62c90 Mon Sep 17 00:00:00 2001 From: Pine Date: Wed, 2 Sep 2026 14:41:33 +0800 Subject: [PATCH] =?UTF-8?q?fix(market):=20=E8=AF=A6=E6=83=85=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=B5=8F=E8=A7=88=E9=87=8F+1=EF=BC=8C=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E6=8E=A5=E5=8F=A3=E4=B8=8B=E8=BD=BD=E9=87=8F+1?= =?UTF-8?q?=EF=BC=88bump=5Fstats=20=E6=AD=A4=E5=89=8D=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E6=9C=AA=E8=B0=83=E7=94=A8=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/market/routers.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/market/routers.py b/app/market/routers.py index 293e4cc..50ebf96 100644 --- a/app/market/routers.py +++ b/app/market/routers.py @@ -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 / app:OSS 直链 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