Spaces:
Running
Running
Upload 3 files
Browse files- router_items.py +26 -0
router_items.py
CHANGED
|
@@ -309,6 +309,32 @@ async def create_item(item: ItemCreate):
|
|
| 309 |
db.save_data("items.json", items_db)
|
| 310 |
# 🗂️ 清除排序缓存
|
| 311 |
sort_cache.invalidate("items:")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
return {"status": "success", "data": new_item}
|
| 313 |
|
| 314 |
@router.put("/api/items/{item_id}")
|
|
|
|
| 309 |
db.save_data("items.json", items_db)
|
| 310 |
# 🗂️ 清除排序缓存
|
| 311 |
sort_cache.invalidate("items:")
|
| 312 |
+
|
| 313 |
+
# 🚀 首次发布立即触发版本检测与预缓存
|
| 314 |
+
try:
|
| 315 |
+
link = item.link or ""
|
| 316 |
+
if "github.com" in link:
|
| 317 |
+
from 云端_定时版本检测引擎 import fetch_latest_github_hash, precache_github_zip
|
| 318 |
+
|
| 319 |
+
async def _first_publish_precache():
|
| 320 |
+
try:
|
| 321 |
+
token = item.github_token or os.environ.get("GITHUB_PAT", "")
|
| 322 |
+
latest_hash = await fetch_latest_github_hash(link, token)
|
| 323 |
+
if latest_hash:
|
| 324 |
+
# 写入 versions.json
|
| 325 |
+
versions_db = db.load_data("versions.json", default_data={})
|
| 326 |
+
versions_db[new_item["id"]] = {"hash": latest_hash}
|
| 327 |
+
db.save_data("versions.json", versions_db)
|
| 328 |
+
# 触发预缓存
|
| 329 |
+
await precache_github_zip(link, token, new_item["id"], latest_hash)
|
| 330 |
+
print(f"[缓存刷新] 首次发布预缓存完成: {new_item['id']}")
|
| 331 |
+
except Exception as e:
|
| 332 |
+
print(f"[缓存刷新] 首次发布预缓存失败(不影响发布): {e}")
|
| 333 |
+
|
| 334 |
+
asyncio.create_task(_first_publish_precache())
|
| 335 |
+
except Exception as e:
|
| 336 |
+
print(f"[缓存刷新] 触发首次发布缓存异常(不影响发布): {e}")
|
| 337 |
+
|
| 338 |
return {"status": "success", "data": new_item}
|
| 339 |
|
| 340 |
@router.put("/api/items/{item_id}")
|