Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

合并:优化actions和细节调整 #14

Merged
merged 24 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
更新:优化注释和一些小调整
  • Loading branch information
guobao2333 committed Sep 13, 2024
commit df4217b1f4bb7341707d099a249966ddab30e8b9
3 changes: 2 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const app = express(),
preflightContinue: false
};

// 其他平台支持配置CORS,我就不兼容了
app.use(cors(CORS));
app.use(bodyParser.json());

Expand All @@ -33,7 +34,7 @@ async function post(req, res) {
});
}

// 判断是否备选翻译
// 是否允许备选翻译
if (!allowAlternative) alt_count = 0;
const { text, source_lang, target_lang, alt_count } = req.body;

Expand Down
8 changes: 3 additions & 5 deletions translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function getTimestamp(iCount) {
}

async function translate(
text,
text = 'Error: The original text cannot be empty!',
sourceLang = 'AUTO',
targetLang = 'ZH',
alternativeCount = 0,
Expand Down Expand Up @@ -75,9 +75,7 @@ async function translate(
});

if (response.status === 429) {
throw new Error(
`Too many requests, your IP has been blocked by DeepL temporarily, please don't request it frequently in a short time.`
);
throw new Error(`Too many requests, your IP has been blocked by DeepL temporarily, please don't request it frequently in a short time.`);
}

if (response.status !== 200) {
Expand All @@ -94,7 +92,7 @@ async function translate(
}
return result;
} catch (err) {
console.error(err);
console.error(err, err.stack);
}
}

Expand Down