ZHIWEI666 commited on
Commit
ea92de7
·
verified ·
1 Parent(s): c3d648d

Upload router_items.py

Browse files
Files changed (1) hide show
  1. router_items.py +18 -1
router_items.py CHANGED
@@ -103,4 +103,21 @@ async def delete_item(item_id: str, author: str):
103
  del comments_db[item_id]
104
  db.save_data("comments.json", comments_db)
105
 
106
- return {"status": "success"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  del comments_db[item_id]
104
  db.save_data("comments.json", comments_db)
105
 
106
+ return {"status": "success"}
107
+
108
+ # =========================================================
109
+ # 【核心新增】:使用量累加同步接口
110
+ # =========================================================
111
+ @router.post("/api/items/{item_id}/use")
112
+ async def record_item_use(item_id: str):
113
+ """记录资源被获取/使用的次数"""
114
+ items_db = db.load_data("items.json", default_data=[])
115
+
116
+ for item in items_db:
117
+ if item["id"] == item_id:
118
+ # 原有的使用量 + 1 (如果没有则默认为0再+1)
119
+ item["uses"] = item.get("uses", 0) + 1
120
+ db.save_data("items.json", items_db)
121
+ return {"status": "success", "uses": item["uses"]}
122
+
123
+ raise HTTPException(status_code=404, detail="找不到该内容记录")