This commit is contained in:
张成
2026-04-01 13:26:41 +08:00
parent fa9abf83ae
commit d03916290a
7 changed files with 315 additions and 30 deletions

View File

@@ -135,12 +135,21 @@ async function incrementApiCallCount(userId, planId, statMonth) {
*/
function checkApiPathAllowed(plan, apiPath) {
const allowed = plan.allowed_apis;
// null / undefined不限制接口
if (allowed == null) return { ok: true };
let list = allowed;
if (typeof list === "string") {
try { list = JSON.parse(list); } catch { return { ok: true }; }
try {
list = JSON.parse(list);
} catch {
return { ok: true };
}
}
if (!Array.isArray(list)) return { ok: true };
// 空数组:明确配置为「不允许任何转发接口」
if (list.length === 0) {
return { ok: false, error_code: "API_NOT_ALLOWED", message: "当前套餐未开放任何接口" };
}
if (!Array.isArray(list) || list.length === 0) return { ok: true };
if (list.includes(apiPath)) return { ok: true };
return { ok: false, error_code: "API_NOT_ALLOWED", message: `当前套餐不支持该接口: ${apiPath}` };
}