1
This commit is contained in:
@@ -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}` };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user