dashboard-core/theme/dbd-soft-ui/pages/post/shards.js

37 lines
1 KiB
JavaScript
Raw Normal View History

2023-06-19 14:21:58 +05:00
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' })
}
}