1
This commit is contained in:
@@ -29,11 +29,11 @@ function hasPositiveDelta(delta) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 对外鉴权:Token + 用户 + 有效订阅 + 功能点 + 可选用量上报与额度
|
||||
* body: { token, feature?, usage_delta?: { msg?, mass?, ... } }
|
||||
* 对外鉴权:Token + 用户 + 有效订阅 + 功能点 + 接口权限 + API调用量 + 可选用量上报
|
||||
* body: { token, feature?, api_path?, usage_delta?: { msg?, mass?, ... } }
|
||||
*/
|
||||
async function verifyRequest(body) {
|
||||
const { token, feature } = body || {};
|
||||
const { token, feature, api_path } = body || {};
|
||||
if (!token) {
|
||||
return { ok: false, error_code: "TOKEN_INVALID", message: "缺少 token" };
|
||||
}
|
||||
@@ -71,9 +71,26 @@ async function verifyRequest(body) {
|
||||
return { ok: false, error_code: "FEATURE_NOT_ALLOWED", message: "功能未在套餐内" };
|
||||
}
|
||||
|
||||
// 接口路径级权限校验
|
||||
if (api_path) {
|
||||
const apiCheck = usageSvc.checkApiPathAllowed(plan, api_path);
|
||||
if (!apiCheck.ok) {
|
||||
return { ok: false, error_code: apiCheck.error_code, message: apiCheck.message };
|
||||
}
|
||||
}
|
||||
|
||||
const statMonth = usageSvc.currentStatMonth();
|
||||
let usageRow = await usageSvc.getOrCreateUsage(row.user_id, sub.plan_id, statMonth);
|
||||
|
||||
// API 调用次数配额校验
|
||||
if (api_path) {
|
||||
const callCheck = usageSvc.checkApiCallQuota(plan, usageRow);
|
||||
if (!callCheck.ok) {
|
||||
return { ok: false, error_code: callCheck.error_code, message: callCheck.message };
|
||||
}
|
||||
usageRow = await usageSvc.incrementApiCallCount(row.user_id, sub.plan_id, statMonth);
|
||||
}
|
||||
|
||||
const delta = normalizeUsageDelta(body.usage_delta || body.usage_report);
|
||||
if (hasPositiveDelta(delta)) {
|
||||
const q = usageSvc.checkQuotaAfterDelta(plan, usageRow, delta);
|
||||
@@ -99,6 +116,7 @@ async function verifyRequest(body) {
|
||||
friend_count: usageSvc.num(usageRow.friend_count),
|
||||
sns_count: usageSvc.num(usageRow.sns_count),
|
||||
active_user_count: usageSvc.num(usageRow.active_user_count),
|
||||
api_call_count: usageSvc.num(usageRow.api_call_count),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user