mhsf-dev/src/pages/api/v1/motd.ts

37 lines
984 B
TypeScript
Raw Normal View History

2024-07-23 18:49:21 -05:00
import { NextApiRequest, NextApiResponse } from "next";
2024-08-03 09:51:45 -05:00
import parseToHTML from "@/lib/motdEngine";
2024-07-23 18:49:21 -05:00
let num = 0;
export default async function handler(
req: NextApiRequest,
2024-08-03 09:51:45 -05:00
res: NextApiResponse
2024-07-23 18:49:21 -05:00
) {
num++;
var body: Array<{ server: string; motd: string }> = req.body.motd;
var list: Array<{ server: string; motd: string }> = [];
var yes = 0;
if (body != undefined && body.forEach != undefined) {
body.forEach((c, i) => {
parseToHTML(c.motd)
.then((m) => {
yes++;
list.push({ motd: m, server: c.server });
if (yes == body.length) {
res.send({ result: list });
}
})
.catch(() => {
list.push({ motd: "Error to grab MOTD", server: c.server });
if (i == body.length - 1) {
res.send({ result: list });
}
});
});
} else {
res
.status(400)
.send({ mes: "Wrong structure.. you might be using the legacy MOTD." });
}
}