Spaces:
Running
Running
Upload router_items.py
Browse files- router_items.py +33 -0
router_items.py
CHANGED
|
@@ -23,6 +23,20 @@ def _get_version_str(versions_db: dict, item_id: str) -> str:
|
|
| 23 |
return val.get("hash", "") or ""
|
| 24 |
return val or ""
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
def get_last_6_months():
|
| 27 |
res = []
|
| 28 |
today = datetime.date.today()
|
|
@@ -74,17 +88,29 @@ async def get_items(type: str = "tool", sort: str = "time", limit: int = 50): #
|
|
| 74 |
|
| 75 |
filtered_items = sort_cache.get_sorted(cache_key, filtered_items, sort_fn)
|
| 76 |
|
|
|
|
| 77 |
for item in filtered_items:
|
| 78 |
item["commentsData"] = comments_db.get(item["id"], [])
|
| 79 |
item["comments"] = len(item["commentsData"])
|
| 80 |
item["latest_version"] = _get_version_str(versions_db, item["id"])
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
# 🔴 【绝对核心防线】:在下发给前端前,强行在内存中抹除敏感信息!
|
| 83 |
item["has_private_token"] = bool(item.get("github_token"))
|
| 84 |
item.pop("github_token", None)
|
| 85 |
item.pop("netdisk_password", None) # ☁️ 网盘密码不在列表中显示
|
| 86 |
item.pop("viewed_by", None) # 👁️ 访问者列表不暴露给前端
|
| 87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
return {"status": "success", "data": filtered_items[:limit]}
|
| 89 |
|
| 90 |
def _build_creator_trend_data(account: str, u_items: list, months: list) -> dict:
|
|
@@ -554,6 +580,13 @@ async def get_item_by_id(item_id: str):
|
|
| 554 |
item["comments"] = len(item["commentsData"])
|
| 555 |
item["latest_version"] = _get_version_str(versions_db, item_id)
|
| 556 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 557 |
# 🔴 【安全防线】:抹除敏感信息
|
| 558 |
item["has_private_token"] = bool(item.get("github_token"))
|
| 559 |
item.pop("github_token", None)
|
|
|
|
| 23 |
return val.get("hash", "") or ""
|
| 24 |
return val or ""
|
| 25 |
|
| 26 |
+
def _apply_effective_price(item: dict) -> None:
|
| 27 |
+
"""检查 pending_price 是否已过生效时间,若是则更新 price 字段供前端显示"""
|
| 28 |
+
pending_price = item.get("pending_price")
|
| 29 |
+
pending_effective = item.get("pending_price_effective_at")
|
| 30 |
+
if pending_price is not None and pending_effective:
|
| 31 |
+
try:
|
| 32 |
+
effective_time = datetime.datetime.fromisoformat(pending_effective)
|
| 33 |
+
if datetime.datetime.now() >= effective_time:
|
| 34 |
+
item["price"] = pending_price
|
| 35 |
+
item["pending_price"] = None
|
| 36 |
+
item["pending_price_effective_at"] = None
|
| 37 |
+
except (ValueError, TypeError):
|
| 38 |
+
pass
|
| 39 |
+
|
| 40 |
def get_last_6_months():
|
| 41 |
res = []
|
| 42 |
today = datetime.date.today()
|
|
|
|
| 88 |
|
| 89 |
filtered_items = sort_cache.get_sorted(cache_key, filtered_items, sort_fn)
|
| 90 |
|
| 91 |
+
price_updated = False
|
| 92 |
for item in filtered_items:
|
| 93 |
item["commentsData"] = comments_db.get(item["id"], [])
|
| 94 |
item["comments"] = len(item["commentsData"])
|
| 95 |
item["latest_version"] = _get_version_str(versions_db, item["id"])
|
| 96 |
|
| 97 |
+
# 💰 检查延迟价格是否已生效
|
| 98 |
+
old_price = item.get("price", 0)
|
| 99 |
+
_apply_effective_price(item)
|
| 100 |
+
if item.get("price", 0) != old_price:
|
| 101 |
+
price_updated = True
|
| 102 |
+
|
| 103 |
# 🔴 【绝对核心防线】:在下发给前端前,强行在内存中抹除敏感信息!
|
| 104 |
item["has_private_token"] = bool(item.get("github_token"))
|
| 105 |
item.pop("github_token", None)
|
| 106 |
item.pop("netdisk_password", None) # ☁️ 网盘密码不在列表中显示
|
| 107 |
item.pop("viewed_by", None) # 👁️ 访问者列表不暴露给前端
|
| 108 |
|
| 109 |
+
# 如果有价格生效了,持久化回 items.json
|
| 110 |
+
if price_updated:
|
| 111 |
+
db.save_data("items.json", items_db)
|
| 112 |
+
invalidate_cache("items.json")
|
| 113 |
+
|
| 114 |
return {"status": "success", "data": filtered_items[:limit]}
|
| 115 |
|
| 116 |
def _build_creator_trend_data(account: str, u_items: list, months: list) -> dict:
|
|
|
|
| 580 |
item["comments"] = len(item["commentsData"])
|
| 581 |
item["latest_version"] = _get_version_str(versions_db, item_id)
|
| 582 |
|
| 583 |
+
# 💰 检查延迟价格是否已生效
|
| 584 |
+
old_price = item.get("price", 0)
|
| 585 |
+
_apply_effective_price(item)
|
| 586 |
+
if item.get("price", 0) != old_price:
|
| 587 |
+
db.save_data("items.json", items_db)
|
| 588 |
+
invalidate_cache("items.json")
|
| 589 |
+
|
| 590 |
# 🔴 【安全防线】:抹除敏感信息
|
| 591 |
item["has_private_token"] = bool(item.get("github_token"))
|
| 592 |
item.pop("github_token", None)
|