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
|
|
|
) {
|
2024-08-08 17:56:40 -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) => {
|
2024-08-08 17:56:40 -05:00
|
|
|
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(() => {
|
2024-08-08 17:56:40 -05:00
|
|
|
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 {
|
2024-08-08 17:56:40 -05:00
|
|
|
res.status(400).send({
|
|
|
|
|
message: "Wrong structure.. you might be using the legacy MOTD.",
|
|
|
|
|
});
|
2024-07-23 18:49:21 -05:00
|
|
|
}
|
|
|
|
|
}
|