From 10727aafc03aaf35e19848b95ca12c5c30e82179 Mon Sep 17 00:00:00 2001 From: h7ml Date: Tue, 10 Dec 2024 16:38:41 +0800 Subject: [PATCH] =?UTF-8?q?refactor(src):=20=E4=BC=98=E5=8C=96=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=20API=20=E5=AF=86=E9=92=A5=E8=8E=B7=E5=8F=96=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 使用 axios 替代 fetch 进行 HTTP 请求 - 简化请求配置和响应处理 - 更新版本号至 1.0.3 --- README-zh.md | 2 +- README.md | 2 +- package.json | 2 +- src/index.ts | 10 +++------- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/README-zh.md b/README-zh.md index dd15c8b..496f1d0 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.2 +- **当前版本**:1.0.3 - **NPM 包**:[ai-markdown-translator](https://www.npmjs.com/package/ai-markdown-translator) ## CI 信息 diff --git a/README.md b/README.md index 96fbf6f..a6331c3 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.2 +- **Current Version**: 1.0.3 - **NPM Package**: [ai-markdown-translator](https://www.npmjs.com/package/ai-markdown-translator) ## CI Information diff --git a/package.json b/package.json index d2e1e91..9649581 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ai-markdown-translator", - "version": "1.0.2", + "version": "1.0.3", "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 e84b185..e557163 100644 --- a/src/index.ts +++ b/src/index.ts @@ -21,7 +21,7 @@ function writeMarkdownFile(filePath: string, content: string): void { async function getDefaultApiKey(): Promise { try { - const response = await fetch('https://dash-api.302.ai/bot/v1/302aitool11-prompter', { + const response = await axios.get('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', @@ -38,14 +38,10 @@ async function getDefaultApiKey(): Promise { 'sec-fetch-user': '?1', 'upgrade-insecure-requests': '1', }, - referrerPolicy: 'strict-origin-when-cross-origin', - method: 'GET', - mode: 'cors', - credentials: 'omit', }); - if (response.ok) { - const data = await response.json(); + if (response.status === 200) { + const data = response.data; if (data.code === 0) { return data.data.api_key; }