fix: 令牌不再走 query(白名单除外)、订阅额度发成功才扣、测试临时目录移出仓库、kpt 外置 json、README 产品优先

This commit is contained in:
agent
2026-11-18 20:31:09 +08:00
parent 9348d5ad81
commit 1aaff9f679
17 changed files with 1709 additions and 24 deletions
+13 -1
View File
@@ -40,6 +40,18 @@ ROUTES: list[tuple[str, re.Pattern, object, str]] = []
PROD = os.environ.get("QINGLING_ENV", "dev").strip().lower() in ("prod", "production")
DEV_ONLY_PREFIXES = ("/api/dev/", "/api/auth/sms-")
MAX_BODY = 16 * 1024 * 1024 # 与 Caddy 的 request_body max_size 对齐
# 只有「要贴到新标签页/发给他人的链接」才允许把令牌放在 query 里。
# 其它接口一律走 Authorization 头——令牌进 URL 会被反代 access log 明文记下来。
QUERY_TOKEN_PATHS = (
re.compile(r"^/api/export/csv$"),
re.compile(r"^/api/print/weekly$"),
re.compile(r"^/api/papers/[^/]+/clean$"),
)
def query_token_ok(path: str) -> bool:
return any(p.match(path) for p in QUERY_TOKEN_PATHS)
CORS_ORIGINS = [o.strip() for o in
(os.environ.get("QINGLING_CORS") or ("*" if not PROD else "")).split(",")
if o.strip()]
@@ -544,7 +556,7 @@ class App(BaseHTTPRequestHandler):
return
auth = self.headers.get("Authorization") or ""
token = auth[7:].strip() if auth.lower().startswith("bearer ") else None
if not token:
if not token and query_token_ok(ctx.path):
token = (ctx.query.get("token") or [None])[0]
if not token:
raise ApiError(401, "UNAUTHORIZED", "缺少 Authorization: Bearer <token>")