From 4969cf013a2716788743f65fb47194973b3fee3a Mon Sep 17 00:00:00 2001 From: h7ml Date: Tue, 10 Dec 2024 17:02:30 +0800 Subject: [PATCH] =?UTF-8?q?fix(version):=20=E6=9B=B4=E6=96=B0=E8=BD=AF?= =?UTF-8?q?=E4=BB=B6=E5=8C=85=E7=89=88=E6=9C=AC=E8=87=B3=201.0.4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 README-zh.md 和 README.md 中将当前版本从 1.0.3 修改为 1.0.4 - 在 package.json 中更新版本号至 1.0.4 - 优化了 getDefaultApiKey 函数,增加了对响应数据的校验 --- README-zh.md | 2 +- README.md | 2 +- package.json | 2 +- src/index.ts | 21 +++++++-------------- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/README-zh.md b/README-zh.md index 496f1d0..590f169 100644 --- a/README-zh.md +++ b/README-zh.md @@ -133,7 +133,7 @@ npx ai-markdown-translator -i input.md -o output.md -l "Italian" ## 版本信息 -- **当前版本**:1.0.3 +- **当前版本**:1.0.4 - **NPM 包**:[ai-markdown-translator](https://www.npmjs.com/package/ai-markdown-translator) ## CI 信息 diff --git a/README.md b/README.md index a6331c3..19f54e9 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ npx ai-markdown-translator -i input.md -o output.md -l "Italian" ## Version Information -- **Current Version**: 1.0.3 +- **Current Version**: 1.0.4 - **NPM Package**: [ai-markdown-translator](https://www.npmjs.com/package/ai-markdown-translator) ## CI Information diff --git a/package.json b/package.json index 9649581..1ac780b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ai-markdown-translator", - "version": "1.0.3", + "version": "1.0.4", "description": "CLI tool to translate Markdown files using OpenAI's language models while preserving the original formatting.", "main": "dist/index.js", "type": "module", diff --git a/src/index.ts b/src/index.ts index e557163..91f1635 100644 --- a/src/index.ts +++ b/src/index.ts @@ -21,31 +21,24 @@ function writeMarkdownFile(filePath: string, content: string): void { async function getDefaultApiKey(): Promise { try { - const response = await axios.get('https://dash-api.302.ai/bot/v1/302aitool11-prompter', { + const response = await axios({ + method: 'get', + url: 'https://dash-api.302.ai/bot/v1/302aitool11-prompter', headers: { - accept: - 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', + accept: 'application/json', 'accept-language': 'zh-CN,zh;q=0.9', 'cache-control': 'no-cache', pragma: 'no-cache', - priority: 'u=0, i', - 'sec-ch-ua': '"Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"', - 'sec-ch-ua-mobile': '?0', - 'sec-ch-ua-platform': '"Windows"', - 'sec-fetch-dest': 'document', - 'sec-fetch-mode': 'navigate', - 'sec-fetch-site': 'none', - 'sec-fetch-user': '?1', - 'upgrade-insecure-requests': '1', }, }); - if (response.status === 200) { + if (response.status === 200 && response.data) { const data = response.data; - if (data.code === 0) { + if (data.code === 0 && data.data && data.data.api_key) { return data.data.api_key; } } + console.error('获取默认API Key失败: 接口返回数据格式错误'); return ''; } catch (error) { console.error('获取默认API Key失败:', error);