Refactor to external scraper and update dependencies (#113)

This commit is contained in:
David
2022-06-15 23:37:15 +02:00
committed by GitHub
parent ff1ad202ae
commit 274e7f1a4b
49 changed files with 6952 additions and 4414 deletions

View File

@@ -1,6 +1,6 @@
import { NextApiHandler } from "next";
import NextCors from "nextjs-cors";
import { retrieveFromType, LangCode } from "@utils/language";
import { languageList, LangCode } from "lingva-scraper";
type Data = {
languages: {
@@ -38,7 +38,7 @@ const handler: NextApiHandler<Data> = async (req, res) => {
if (type !== undefined && type !== "source" && type !== "target")
return res.status(400).json({ error: "Type should be 'source', 'target' or empty" });
const langEntries = retrieveFromType(type);
const langEntries = Object.entries(languageList[type ?? "all"]) as [LangCode, string][];
const languages = langEntries.map(([code, name]) => ({ code, name }));
res.status(200).json({ languages });