2023-06-19 14:21:58 +05:00
|
|
|
module.exports = {
|
2023-06-22 19:36:52 +05:00
|
|
|
page: "/stats/shards/update",
|
|
|
|
execute: async (req, res, app, config, themeConfig, info, db) => {
|
|
|
|
if ("Bearer " + themeConfig.shardspage?.key !== req.headers.authorization) return res.json({ status: "Invalid sharding key" });
|
2023-06-19 14:21:58 +05:00
|
|
|
|
2023-06-22 19:36:52 +05:00
|
|
|
const stats = await db.get("stats");
|
2023-06-19 14:21:58 +05:00
|
|
|
|
2023-06-22 19:36:52 +05:00
|
|
|
const clean = req.body.map((s) => {
|
|
|
|
if (!stats) return {
|
|
|
|
...s,
|
|
|
|
ping: [0, 0, 0, 0, 0, 0, 0, 0, 0, s.ping],
|
|
|
|
};
|
2023-06-19 14:21:58 +05:00
|
|
|
|
2023-06-22 19:36:52 +05:00
|
|
|
const currentSaved = stats?.find((x) => x.id === s.id);
|
|
|
|
if (!currentSaved) return {
|
|
|
|
...s,
|
|
|
|
ping: [0, 0, 0, 0, 0, 0, 0, 0, 0, s.ping],
|
|
|
|
};
|
2023-06-19 14:21:58 +05:00
|
|
|
|
2023-06-22 19:36:52 +05:00
|
|
|
const nextPing = currentSaved?.ping?.slice(1, 10);
|
2023-06-19 14:21:58 +05:00
|
|
|
|
2023-06-22 19:36:52 +05:00
|
|
|
return {
|
|
|
|
...s,
|
|
|
|
ping: nextPing ? [...nextPing, s.ping] : [0, 0, 0, 0, 0, 0, 0, 0, 0, s.ping],
|
|
|
|
};
|
|
|
|
});
|
2023-06-19 14:21:58 +05:00
|
|
|
|
2023-06-22 19:36:52 +05:00
|
|
|
await db.set("stats", clean);
|
2023-06-19 14:21:58 +05:00
|
|
|
|
2023-06-22 19:36:52 +05:00
|
|
|
res.json({
|
|
|
|
status: "Completed",
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|