35 lines
928 B
TypeScript
35 lines
928 B
TypeScript
import type { APIRoute } from 'astro';
|
|
import { GET as langs } from '../lang.json';
|
|
import { getLang } from '../../../lib/db/lang';
|
|
|
|
const supportedLanguages: { id: string, name: string }[] = await (await langs()).json();
|
|
|
|
export const GET: APIRoute = async ({ params, request }) => {
|
|
const id = params.id;
|
|
if (!supportedLanguages.find(lang => lang.id === id)) {
|
|
return new Response(
|
|
JSON.stringify({
|
|
code: 404,
|
|
message: "Language not found"
|
|
}), { status: 404 }
|
|
)
|
|
}
|
|
|
|
const lang = await getLang(id);
|
|
if (!lang) {
|
|
return new Response(
|
|
JSON.stringify({
|
|
code: 500,
|
|
message: "Internal Server Error"
|
|
}), { status: 500 }
|
|
)
|
|
}
|
|
|
|
return new Response(
|
|
JSON.stringify({
|
|
code: 200,
|
|
message: "OK",
|
|
data: lang
|
|
})
|
|
)
|
|
} |