mirror of
https://github.com/GMGNAI/gmgn-skills.git
synced 2026-08-25 22:18:06 +00:00
fix(config): distinguish auth vs network failures in verify step
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
b782743c8c
commit
ac1ea2e336
+22
-7
@@ -47,6 +47,11 @@ const MESSAGES = {
|
|||||||
"配置驗證失敗:API Key 與本地密鑰不匹配。\n請確認:\n1. API Key 是否填寫正確;\n2. 創建 API Key 時,是否使用的是頁面自動填入的公鑰。",
|
"配置驗證失敗:API Key 與本地密鑰不匹配。\n請確認:\n1. API Key 是否填寫正確;\n2. 創建 API Key 時,是否使用的是頁面自動填入的公鑰。",
|
||||||
en: "Configuration verification failed: API Key does not match your local key pair.\nPlease confirm:\n1. Whether the API Key was entered correctly.\n2. Whether you used the public key that was pre-filled on the page when creating the API Key.",
|
en: "Configuration verification failed: API Key does not match your local key pair.\nPlease confirm:\n1. Whether the API Key was entered correctly.\n2. Whether you used the public key that was pre-filled on the page when creating the API Key.",
|
||||||
},
|
},
|
||||||
|
verifyNetworkFail: {
|
||||||
|
"zh-CN": "配置已写入,但验证请求失败(可能是网络问题)。你可以先尝试使用,如遇接口报错再重新配置。",
|
||||||
|
"zh-TW": "配置已寫入,但驗證請求失敗(可能是網路問題)。你可以先嘗試使用,如遇介面報錯再重新配置。",
|
||||||
|
en: "Configuration saved, but the verification request failed (possibly a network issue). You can try using it now and reconfigure if you encounter API errors.",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
function getOrCreateKeypair(): string {
|
function getOrCreateKeypair(): string {
|
||||||
@@ -83,12 +88,20 @@ function writeEnv(apiKey: string, privatePem: string): void {
|
|||||||
fs.writeFileSync(ENV_FILE, content, { mode: 0o600 });
|
fs.writeFileSync(ENV_FILE, content, { mode: 0o600 });
|
||||||
}
|
}
|
||||||
|
|
||||||
function verify(): boolean {
|
function verify(): "ok" | "auth_fail" | "network_fail" {
|
||||||
try {
|
try {
|
||||||
execSync("gmgn-cli track follow-wallet --chain sol --limit 1", { stdio: "pipe" });
|
execSync("gmgn-cli track follow-wallet --chain sol --limit 1", { stdio: "pipe" });
|
||||||
return true;
|
return "ok";
|
||||||
} catch {
|
} catch (e: unknown) {
|
||||||
return false;
|
const output = (() => {
|
||||||
|
if (e && typeof e === "object" && "stderr" in e) return String((e as { stderr: unknown }).stderr);
|
||||||
|
if (e && typeof e === "object" && "stdout" in e) return String((e as { stdout: unknown }).stdout);
|
||||||
|
return String(e);
|
||||||
|
})();
|
||||||
|
if (/401|403|unauthorized|forbidden|invalid.*key|key.*invalid|signature/i.test(output)) {
|
||||||
|
return "auth_fail";
|
||||||
|
}
|
||||||
|
return "network_fail";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,12 +136,14 @@ export function registerConfigCommands(program: Command): void {
|
|||||||
}
|
}
|
||||||
writeEnv(opts.apply, match[1]);
|
writeEnv(opts.apply, match[1]);
|
||||||
|
|
||||||
const ok = verify();
|
const result = verify();
|
||||||
if (ok) {
|
if (result === "ok") {
|
||||||
console.log(MESSAGES.verifySuccess[lang]);
|
console.log(MESSAGES.verifySuccess[lang]);
|
||||||
} else {
|
} else if (result === "auth_fail") {
|
||||||
console.error(MESSAGES.verifyFail[lang]);
|
console.error(MESSAGES.verifyFail[lang]);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
} else {
|
||||||
|
console.log(MESSAGES.verifyNetworkFail[lang]);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user