INNER CODE UNIT · JavaScript
post
guobao2333/DeepLX-Serverless · src/server.js:50
async function post(req, res) {
const startTime = Date.now();
let { text, source_lang, target_lang, alt_count } = req.body;
source_lang = source_lang.toUpperCase();
target_lang = target_lang.toUpperCase();
// 检查请求体
if (!req.body || !text || !target_lang || alt_count !== undefined && typeof alt_count !== 'number' || alt_count > 3 || alt_count < 0) {
const duration = Date.now() - startTime;
console.log(`[WARN] ${new Date().toISOString()} | POST "translate" | 400 | Bad Request | ${duration}ms`);
return res.status(400).json({
code: 400,
message: "Bad Request"
});
}
try {