mirror of
https://github.com/DeveloLongScript/MHSF.git
synced 2026-05-09 16:45:00 -05:00
37 lines
991 B
TypeScript
37 lines
991 B
TypeScript
|
|
import { NextApiRequest, NextApiResponse } from "next";
|
||
|
|
import parseToHTML from "@/lib/miniMessage2HTML";
|
||
|
|
|
||
|
|
let num = 0;
|
||
|
|
|
||
|
|
export default async function handler(
|
||
|
|
req: NextApiRequest,
|
||
|
|
res: NextApiResponse,
|
||
|
|
) {
|
||
|
|
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." });
|
||
|
|
}
|
||
|
|
}
|