feat(webui): boosters #2140

Merged
Sainan merged 9 commits from nyaoouo/SpaceNinjaServer:Web-UI-Add-Boosters into main 2025-06-12 04:54:17 -07:00
Showing only changes of commit 7957dc1e24 - Show all commits

View File

@ -23,13 +23,21 @@ export const setBoosterController: RequestHandler = async (req, res) => {
res.status(400).send("Invalid ItemType provided.");
return;
}
// Remove if ExpiryDate lower than current time?
const now = Math.floor(Date.now() / 1000);
for (const { ItemType, ExpiryDate } of requests) {
const boosterItem = boosters.find(item => item.ItemType === ItemType);
if (boosterItem) {
boosterItem.ExpiryDate = ExpiryDate;
if (ExpiryDate > now) {
// remove expired boosters
const index = boosters.findIndex(item => item.ItemType === ItemType);
if (index !== -1) {
boosters.splice(index, 1);
}
} else {
boosters.push({ ItemType, ExpiryDate });
const boosterItem = boosters.find(item => item.ItemType === ItemType);
if (boosterItem) {
boosterItem.ExpiryDate = ExpiryDate;
} else {
boosters.push({ ItemType, ExpiryDate });
}
}
}
await inventory.save();