fix: apply quota point conversion

This commit is contained in:
Alex committed 2026-11-09 09:56:06 +08:00
1 parent 2553e482a9
commit ad66ae5f10
12 files changed
+205 -25

No files matched your search

+19
View File
@@ -0,0 +1,19 @@
export const QUOTA_PER_POINT = 5000;
export function pointsToQuota(points: unknown): number {
const value = Number(points);
if (!Number.isSafeInteger(value) || value < 0) {
throw new Error("积分必须是非负安全整数");
}
const quota = value * QUOTA_PER_POINT;
if (!Number.isSafeInteger(quota)) {
throw new Error("积分换算后的 quota 超出安全整数范围");
}
return quota;
}
export function quotaToPoints(quota: unknown): number {
const value = Number(quota ?? 0);
if (!Number.isFinite(value)) return 0;
return Math.ceil(value / QUOTA_PER_POINT);
}