feat(cli): sub2api-admin 支持 SUB2API_JWT 认证回退

This commit is contained in:
wucm667
2026-06-26 14:11:25 +08:00
parent 5f022663ac
commit ac6e36f96b
3 changed files with 17 additions and 5 deletions
@@ -5,6 +5,7 @@ const path = require("path");
const BASE_URL = (process.env.SUB2API_BASE_URL || "").replace(/\/$/, "");
const ADMIN_API_KEY = process.env.SUB2API_ADMIN_API_KEY || "";
const ADMIN_JWT = process.env.SUB2API_JWT || "";
function usage() {
console.log(`Usage:
@@ -91,7 +92,8 @@ function parseArgs(argv) {
function authHeaders() {
if (!BASE_URL) throw new Error("Missing SUB2API_BASE_URL");
if (ADMIN_API_KEY) return { "x-api-key": ADMIN_API_KEY };
throw new Error("Missing SUB2API_ADMIN_API_KEY");
if (ADMIN_JWT) return { Authorization: `Bearer ${ADMIN_JWT}` };
throw new Error("Missing SUB2API_ADMIN_API_KEY or SUB2API_JWT");
}
async function apiRequest(method, pathname, body, extraHeaders = {}) {