dashboard-core/theme/dbd-soft-ui/pages/post/shards.js
Jonny_Bro (Nikita) 849a93887a
2023-06-22 19:36:52 +05:00

34 lines
No EOL
823 B
JavaScript

module.exports = {
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" });
const stats = await db.get("stats");
const clean = req.body.map((s) => {
if (!stats) return {
...s,
ping: [0, 0, 0, 0, 0, 0, 0, 0, 0, s.ping],
};
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],
};
const nextPing = currentSaved?.ping?.slice(1, 10);
return {
...s,
ping: nextPing ? [...nextPing, s.ping] : [0, 0, 0, 0, 0, 0, 0, 0, 0, s.ping],
};
});
await db.set("stats", clean);
res.json({
status: "Completed",
});
},
};