Default languages with env & langcodes typed (#94)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { NextApiHandler } from "next";
|
||||
import NextCors from "nextjs-cors";
|
||||
import { googleScrape, textToSpeechScrape } from "@utils/translate";
|
||||
import { isValid } from "@utils/language";
|
||||
|
||||
type Data = {
|
||||
translation: string,
|
||||
@@ -34,6 +35,9 @@ const handler: NextApiHandler<Data> = async (req, res) => {
|
||||
|
||||
const [source, target, query] = slug;
|
||||
|
||||
if (!isValid(target))
|
||||
return res.status(400).json({ error: "Invalid target language" });
|
||||
|
||||
if (source === "audio") {
|
||||
const audio = await textToSpeechScrape(target, query);
|
||||
return audio
|
||||
@@ -41,6 +45,9 @@ const handler: NextApiHandler<Data> = async (req, res) => {
|
||||
: res.status(500).json({ error: "An error occurred while retrieving the audio" });
|
||||
}
|
||||
|
||||
if (!isValid(source))
|
||||
return res.status(400).json({ error: "Invalid source language" });
|
||||
|
||||
const textScrape = await googleScrape(source, target, query);
|
||||
|
||||
if ("errorMsg" in textScrape)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { NextApiHandler } from "next";
|
||||
import NextCors from "nextjs-cors";
|
||||
import { retrieveFromType } from "@utils/language";
|
||||
import { retrieveFromType, LangCode } from "@utils/language";
|
||||
|
||||
type Data = {
|
||||
languages: {
|
||||
code: string,
|
||||
code: LangCode,
|
||||
name: string
|
||||
}[]
|
||||
} | {
|
||||
|
||||
Reference in New Issue
Block a user