fix: toNum 对 null/空串返回 null,修正测试脚本 glob

This commit is contained in:
GeekRicardo
2026-08-18 21:48:44 +08:00
parent 6103f290c2
commit c034eeef31
2 changed files with 12 additions and 10 deletions
+11 -9
View File
@@ -65,10 +65,21 @@ function round2(n) {
}
function toNum(v) {
if (v === null || v === undefined || v === "") return null;
const n = Number(v);
return n === n ? n : null;
}
// Codex rate_limit 窗口秒数 → 展示名(18000s=5小时、604800s=7天、2592000s=30天)
function codexWindowName(secs) {
if (secs === 18000) return { label: "5小时", key: "5h" };
if (secs === 604800) return { label: "7天", key: "7d" };
if (secs === 2592000) return { label: "30天", key: "30d" };
const hours = Math.floor(secs / 3600);
if (hours >= 24) return { label: Math.floor(hours / 24) + "天", key: Math.floor(hours / 24) + "d" };
return { label: hours + "小时", key: hours + "h" };
}
function writeJson(res, status, body) {
const payload = JSON.stringify(body);
res.writeHead(status, {
@@ -932,15 +943,6 @@ function apply(ctx) {
// rate_limit.primary/secondary_windowused_percent=已用%、limit_window_seconds=窗口秒数、
// reset_at=重置时间戳(秒)。
function codexWindowName(secs) {
if (secs === 18000) return { label: "5小时", key: "5h" };
if (secs === 604800) return { label: "7天", key: "7d" };
if (secs === 2592000) return { label: "30天", key: "30d" };
const hours = Math.floor(secs / 3600);
if (hours >= 24) return { label: Math.floor(hours / 24) + "天", key: Math.floor(hours / 24) + "d" };
return { label: hours + "小时", key: hours + "h" };
}
async function queryCodexUsage() {
let key;
try {
+1 -1
View File
@@ -47,6 +47,6 @@
}
},
"scripts": {
"test": "node --test test/"
"test": "node --test test/*.test.mjs"
}
}