Skip to content

Commit

Permalink
feat(next/api): add translate log
Browse files Browse the repository at this point in the history
  • Loading branch information
uffy committed Jun 6, 2024
1 parent 41c6e76 commit e523edc
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions next/api/src/controller/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@ export class TranslateController {
async translate(
@Body(new ZodValidationPipe(translateSchema)) { text }: z.infer<typeof translateSchema>
) {
const result = await translateService.translate(text);
if (!result) {
throw new HttpError(400, 'translation service is not configured');
const start = performance.now();
let translateResult;
try{
translateResult = await translateService.translate(text);
} finally {
const end = performance.now();
console.log(`translate ${text} cost ${end - start}ms, result: ${translateResult?.from}, ${translateResult?.text}`);
}
return result;

if (!translateResult) {
throw new HttpError(400, 'translation service is not available');
}
return translateResult;
}
}

0 comments on commit e523edc

Please sign in to comment.