yymaxapi 1.0.87 → 1.0.88
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/yymaxapi.js +16 -35
- package/package.json +1 -1
package/bin/yymaxapi.js
CHANGED
|
@@ -56,6 +56,20 @@ function safeExec(cmd, options = {}) {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
function shouldSuppressProcessWarning(warning) {
|
|
60
|
+
const message = typeof warning === 'string' ? warning : String(warning?.message || '');
|
|
61
|
+
return message.includes("Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0'");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (!process.__yymaxapiWarningFilterInstalled && typeof process.emitWarning === 'function') {
|
|
65
|
+
const originalEmitWarning = process.emitWarning.bind(process);
|
|
66
|
+
process.emitWarning = function patchedEmitWarning(warning, ...args) {
|
|
67
|
+
if (shouldSuppressProcessWarning(warning)) return;
|
|
68
|
+
return originalEmitWarning(warning, ...args);
|
|
69
|
+
};
|
|
70
|
+
process.__yymaxapiWarningFilterInstalled = true;
|
|
71
|
+
}
|
|
72
|
+
|
|
59
73
|
// ============ 预设 (由 build.js 从 provider config 生成) ============
|
|
60
74
|
const DEFAULT_ENDPOINTS = [
|
|
61
75
|
{
|
|
@@ -493,41 +507,8 @@ async function validateApiKey(nodeUrl, apiKey) {
|
|
|
493
507
|
try {
|
|
494
508
|
const res = await httpGetJson(verifyUrl, { Authorization: `Bearer ${apiKey}` });
|
|
495
509
|
if (res.status === 200 && res.data) {
|
|
496
|
-
spinner.succeed('API Key
|
|
497
|
-
|
|
498
|
-
// 基本信息
|
|
499
|
-
if (d.service_type) console.log(chalk.gray(` 服务类型: ${d.service_type}`));
|
|
500
|
-
if (d.billing_mode) console.log(chalk.gray(` 计费模式: ${d.billing_mode}`));
|
|
501
|
-
if (d.status && d.status !== 'active') console.log(chalk.yellow(` ⚠ 状态: ${d.status}`));
|
|
502
|
-
// 配额信息
|
|
503
|
-
if (d.total_quota !== undefined || d.remaining_quota !== undefined) {
|
|
504
|
-
const total = d.total_quota || 0;
|
|
505
|
-
const remaining = d.remaining_quota !== undefined ? d.remaining_quota : total;
|
|
506
|
-
const used = total - remaining;
|
|
507
|
-
const pct = total > 0 ? Math.round((used / total) * 100) : 0;
|
|
508
|
-
const barLen = 20;
|
|
509
|
-
const filled = Math.round(barLen * pct / 100);
|
|
510
|
-
const bar = chalk.green('█'.repeat(filled)) + chalk.gray('░'.repeat(barLen - filled));
|
|
511
|
-
console.log(chalk.gray(` 总配额: ${total}`) + (d.max_requests ? chalk.gray(` | 最大请求: ${d.max_requests}`) : ''));
|
|
512
|
-
console.log(chalk.gray(` 已用/剩余: ${used} / ${remaining}`));
|
|
513
|
-
console.log(` [${bar}] ${pct}%`);
|
|
514
|
-
}
|
|
515
|
-
// 每日配额
|
|
516
|
-
if (d.daily_quota !== undefined || d.daily_remaining !== undefined) {
|
|
517
|
-
const dTotal = d.daily_quota || 0;
|
|
518
|
-
const dRemain = d.daily_remaining !== undefined ? d.daily_remaining : dTotal;
|
|
519
|
-
const dUsed = d.daily_used !== undefined ? d.daily_used : (dTotal - dRemain);
|
|
520
|
-
console.log(chalk.gray(` 今日配额: ${dTotal} | 已用: ${dUsed} | 剩余: ${dRemain}`));
|
|
521
|
-
}
|
|
522
|
-
// 有效期
|
|
523
|
-
if (d.activated_at) console.log(chalk.gray(` 激活时间: ${new Date(d.activated_at).toLocaleDateString()}`));
|
|
524
|
-
if (d.expires_at) {
|
|
525
|
-
const exp = new Date(d.expires_at);
|
|
526
|
-
const daysLeft = Math.ceil((exp - Date.now()) / 86400000);
|
|
527
|
-
const expColor = daysLeft <= 7 ? chalk.red : daysLeft <= 30 ? chalk.yellow : chalk.gray;
|
|
528
|
-
console.log(expColor(` 有效期至: ${exp.toLocaleDateString()} (${daysLeft > 0 ? `剩余 ${daysLeft} 天` : '已过期'})`));
|
|
529
|
-
}
|
|
530
|
-
return { valid: true, data: d };
|
|
510
|
+
spinner.succeed('API Key 可用');
|
|
511
|
+
return { valid: true, data: res.data };
|
|
531
512
|
} else {
|
|
532
513
|
spinner.fail('API Key 验证失败');
|
|
533
514
|
console.log(chalk.red(` HTTP ${res.status}`));
|