fix(relay): 通用卡激活携带 project_id(适配 CardAuth 新版)

- /activate payload 固定携带 project_id(PROJECT_ID env,默认 6=IT-TOOLS-PRO),
  CardAuth 新版通用卡激活必须指定项目,专属卡不受影响
- 新增 _is_this_project():project_id + 历史项目名(IT-Tools/IT-TOOLS-PRO)双重匹配,
  授权校验(_list_has_ittools_auth)与撤销(deactivate)统一走该函数,项目改名兼容
- 新增 env:PROJECT_ID / PROJECT_ALIASES;.env 补 PROJECT_ID=6
- 已重建部署(轻量补丁镜像 FROM it-tools-relay:latest),--restart always
This commit is contained in:
personal82555 committed 2026-10-21 18:18:34 +08:00
1 parent a0b63f9a18
commit 41f7f0671c
2 files changed
+38 -4

No files matched your search

+5
View File
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. See [standa
## Version 2026.10.16-it-tools-pro
### 🔧 授权系统:通用卡激活传 project_id(适配 CardAuth 新版)
- CardAuth 新版支持「通用卡」(不绑定项目的跨项目卡),激活时必须指定项目;relay 激活请求现在固定携带 `project_id`(IT-TOOLS-PRO=6),通用卡可在本站正常激活,专属卡不受影响
- 授权校验/撤销同步改用 `project_id` + 历史项目名(IT-Tools / IT-TOOLS-PRO)双重匹配,项目改名后新旧授权都能正确识别
- 新增环境变量 `PROJECT_ID`(默认 6)与 `PROJECT_ALIASES`(默认两个历史名),换项目无需改代码
### ✨ 图片工具新增「图片编辑」:改图中文字 + 加文字
- **改图中文字**:一键 OCR 自动定位图内文字(复用本机 rapidocr,带坐标),画布上画红色虚线框+文字标签;点框选中 → 输入新文字 → 「✓ 替换」自动采样框外圈中位色作底色覆盖原字,再在原位生成可编辑文字图层(字号按原文字高度推算,也可「只擦除」不加字)
- **涂改/加字**:画布拖拽框选任意区域按底色涂掉(自动取图/手动指定颜色);「+ 添加文字」放置新文字图层,支持字号/颜色/加粗
+33 -4
View File
@@ -42,6 +42,16 @@ CARD_AUTH_KEY = os.environ.get("CARD_AUTH_KEY", "")
AUTH_USER = os.environ.get("AUTH_USER", "")
AUTH_PASS = os.environ.get("AUTH_PASS", "")
PROJECT_NAME = os.environ.get("PROJECT_NAME", "IT-Tools")
# CardAuth project id of THIS deployment. Universal cards carry no project of
# their own -> activation must name one; the backend rejects them without it.
PROJECT_ID = int(os.environ.get("PROJECT_ID", "6")) # 6 = IT-TOOLS-PRO
# Names that also count as "this project": CardAuth renamed the project
# (old activations store project_name "IT-Tools", new ones "IT-TOOLS-PRO").
PROJECT_ALIASES = {
n.strip()
for n in os.environ.get("PROJECT_ALIASES", "IT-Tools,IT-TOOLS-PRO").split(",")
if n.strip()
} or {PROJECT_NAME}
TRIAL_FILE = os.environ.get("TRIAL_FILE", "/app/data/trials.json")
TRIAL_MS = int(os.environ.get("TRIAL_MS_MIN", "30")) * 60 * 1000
DAY_MS = 24 * 60 * 60 * 1000
@@ -72,6 +82,21 @@ _auth_cache: dict = {}
AUTH_CACHE_TTL = 60
def _is_this_project(item: dict) -> bool:
"""True when a query/admin result belongs to THIS site's project.
Matches by project_id (new records) or by any historical project name
(CardAuth renamed IT-Tools -> IT-TOOLS-PRO; old rows keep the old name).
"""
try:
pid = item.get("project_id")
if pid is not None and int(pid) == PROJECT_ID:
return True
except (TypeError, ValueError):
pass
return item.get("project_name") in PROJECT_ALIASES
def _list_has_ittools_auth(data: dict) -> bool:
"""Only cards of PROJECT_NAME with active status count.
@@ -89,12 +114,12 @@ def _list_has_ittools_auth(data: dict) -> bool:
if not isinstance(item, dict):
continue
name = item.get("project_name")
if name is None:
if name is None and item.get("project_id") is None:
# shape unknown -> do not filter
return bool(data.get("has_valid_auth"))
matched = True
if (
name == PROJECT_NAME
_is_this_project(item)
and item.get("status") == "active"
and not item.get("is_expired", False)
):
@@ -183,7 +208,7 @@ def deactivate_card(machine_id: str) -> tuple[int, dict]:
try:
res = _get_json(f"/authorizations?bot_qq={machine_id}&status=active&page=1&page_size=20", auth_hdr)
for item in ((res or {}).get("data") or {}).get("list") or []:
if item.get("project_name") != PROJECT_NAME:
if not _is_this_project(item):
continue
try:
r = _put_json(f"/authorizations/{item['id']}/revoke", {"reason": "用户在客户端自助撤销"}, auth_hdr)
@@ -631,12 +656,16 @@ def activate_card(card_key: str, machine_id: str, contact_qq: str, replace: bool
# NOTE: do NOT call /public/verify with an unused card here - in this
# CardAuth version the first verify call binds & consumes the card.
# activate (web channel, with admin session if configured)
# activate (web channel, with admin session if configured).
# project_id: universal cards carry no project of their own - the backend
# rejects them unless the caller names one. Named-card activations ignore
# it (their own project wins), so always send it.
payload = {
"card_key": card_key,
"bot_qq": machine_id,
"contact_qq": contact_qq or machine_id,
"device_info": "IT-Tools Web",
"project_id": PROJECT_ID,
}
# Retry ONLY on explicit 401 (stale token). Any other failure is returned
# as-is: re-sending an activate that already consumed the card would burn it.