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

34 lines
1.0 KiB
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
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
) {
const initalList: Array<{ server: string; motd: string }> = req.body.motd;
const resultedList: Array<{ server: string; motd: string }> = [];
var interval = 0;
if (initalList != undefined && initalList.forEach != undefined) {
initalList.forEach((c, i) => {
2024-07-23 18:49:21 -05:00
parseToHTML(c.motd)
.then((m) => {
interval++;
resultedList.push({ motd: m, server: c.server });
if (interval == initalList.length) {
res.send({ result: resultedList });
2024-07-23 18:49:21 -05:00
}
})
.catch(() => {
resultedList.push({ motd: "Error to grab MOTD", server: c.server });
if (i == initalList.length - 1) {
res.send({ result: resultedList });
2024-07-23 18:49:21 -05:00
}
});
});
} else {
res.status(400).send({
message: "Wrong structure.. you might be using the legacy MOTD.",
});
2024-07-23 18:49:21 -05:00
}
}