Add language endpoint to developer APIs (#41)

* Added languages endpoint and its tests
This commit is contained in:
David
2021-08-30 21:35:22 +02:00
committed by GitHub
parent 1b6c324560
commit 870ec2db64
11 changed files with 360 additions and 74 deletions

View File

@@ -3,9 +3,11 @@ import NextCors from "nextjs-cors";
import { googleScrape, textToSpeechScrape } from "@utils/translate";
type Data = {
translation?: string,
audio?: number[],
error?: string
translation: string,
} | {
audio: number[]
} | {
error: string
};
const methods = ["GET"];
@@ -39,11 +41,11 @@ const handler: NextApiHandler<Data> = async (req, res) => {
: res.status(500).json({ error: "An error occurred while retrieving the audio" });
}
const { translationRes, errorMsg } = await googleScrape(source, target, query);
const textScrape = await googleScrape(source, target, query);
if (errorMsg)
return res.status(500).json({ error: errorMsg });
res.status(200).json({ translation: translationRes });
if ("errorMsg" in textScrape)
return res.status(500).json({ error: textScrape.errorMsg });
res.status(200).json({ translation: textScrape.translationRes });
}
export default handler;