chore(webui): unify Boosters code
All checks were successful
Build / build (pull_request) Successful in 1m3s
All checks were successful
Build / build (pull_request) Successful in 1m3s
This commit is contained in:
parent
32c95b6715
commit
32d22eca98
@ -1,44 +1,19 @@
|
|||||||
import { getAccountIdForRequest } from "../../services/loginService.ts";
|
import { getAccountIdForRequest } from "../../services/loginService.ts";
|
||||||
import { getInventory } from "../../services/inventoryService.ts";
|
import { getInventory } from "../../services/inventoryService.ts";
|
||||||
import type { RequestHandler } from "express";
|
import type { RequestHandler } from "express";
|
||||||
import { ExportBoosters } from "warframe-public-export-plus";
|
import type { IBooster } from "../../types/inventoryTypes/inventoryTypes.ts";
|
||||||
import { broadcastInventoryUpdate } from "../../services/wsService.ts";
|
import { broadcastInventoryUpdate } from "../../services/wsService.ts";
|
||||||
|
|
||||||
const I32_MAX = 0x7fffffff;
|
|
||||||
|
|
||||||
export const setBoosterController: RequestHandler = async (req, res) => {
|
export const setBoosterController: RequestHandler = async (req, res) => {
|
||||||
const accountId = await getAccountIdForRequest(req);
|
const accountId = await getAccountIdForRequest(req);
|
||||||
const requests = req.body as { ItemType: string; ExpiryDate: number }[];
|
const requests = req.body as IBooster[];
|
||||||
const inventory = await getInventory(accountId, "Boosters");
|
const inventory = await getInventory(accountId, "Boosters");
|
||||||
const boosters = inventory.Boosters;
|
for (const request of requests) {
|
||||||
if (
|
const index = inventory.Boosters.findIndex(item => item.ItemType === request.ItemType);
|
||||||
requests.some(request => {
|
if (index !== -1) {
|
||||||
if (typeof request.ItemType !== "string") return true;
|
inventory.Boosters[index].ExpiryDate = request.ExpiryDate;
|
||||||
if (Object.entries(ExportBoosters).find(([_, item]) => item.typeName === request.ItemType) === undefined)
|
|
||||||
return true;
|
|
||||||
if (typeof request.ExpiryDate !== "number") return true;
|
|
||||||
if (request.ExpiryDate < 0 || request.ExpiryDate > I32_MAX) return true;
|
|
||||||
return false;
|
|
||||||
})
|
|
||||||
) {
|
|
||||||
res.status(400).send("Invalid ItemType provided.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const now = Math.trunc(Date.now() / 1000);
|
|
||||||
for (const { ItemType, ExpiryDate } of requests) {
|
|
||||||
if (ExpiryDate <= now) {
|
|
||||||
// remove expired boosters
|
|
||||||
const index = boosters.findIndex(item => item.ItemType === ItemType);
|
|
||||||
if (index !== -1) {
|
|
||||||
boosters.splice(index, 1);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
const boosterItem = boosters.find(item => item.ItemType === ItemType);
|
inventory.Boosters.push(request);
|
||||||
if (boosterItem) {
|
|
||||||
boosterItem.ExpiryDate = ExpiryDate;
|
|
||||||
} else {
|
|
||||||
boosters.push({ ItemType, ExpiryDate });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await inventory.save();
|
await inventory.save();
|
||||||
|
|||||||
@ -476,9 +476,9 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col-lg-6">
|
<div class="col-lg-6">
|
||||||
<div class="card" style="height: 400px;">
|
<div class="card" style="height: 400px;">
|
||||||
<h5 class="card-header" data-loc="inventory_Boosters"></h5>
|
<h5 class="card-header" data-loc="inventory_boosters"></h5>
|
||||||
<div class="card-body d-flex flex-column">
|
<div class="card-body d-flex flex-column">
|
||||||
<form class="input-group mb-3" onsubmit="doAcquireBoosters();return false;">
|
<form class="input-group mb-3" onsubmit="doAcquireBooster();return false;">
|
||||||
<input class="form-control" id="acquire-type-Boosters" list="datalist-Boosters" />
|
<input class="form-control" id="acquire-type-Boosters" list="datalist-Boosters" />
|
||||||
<button class="btn btn-primary" type="submit" data-loc="general_addButton"></button>
|
<button class="btn btn-primary" type="submit" data-loc="general_addButton"></button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@ -1007,6 +1007,67 @@ function updateInventory() {
|
|||||||
document.getElementById("EvolutionProgress-list").appendChild(tr);
|
document.getElementById("EvolutionProgress-list").appendChild(tr);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.getElementById("Boosters-list").innerHTML = "";
|
||||||
|
data.Boosters.forEach(item => {
|
||||||
|
if (item.ExpiryDate < Math.floor(Date.now() / 1000)) {
|
||||||
|
// Booster has expired, skip it
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const tr = document.createElement("tr");
|
||||||
|
{
|
||||||
|
const td = document.createElement("td");
|
||||||
|
td.textContent = itemMap[item.ItemType]?.name ?? item.ItemType;
|
||||||
|
tr.appendChild(td);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const td = document.createElement("td");
|
||||||
|
td.classList = "text-end text-nowrap";
|
||||||
|
{
|
||||||
|
const form = document.createElement("form");
|
||||||
|
form.style.display = "inline-block";
|
||||||
|
form.onsubmit = function (event) {
|
||||||
|
event.preventDefault();
|
||||||
|
const maxDate = new Date(input.max);
|
||||||
|
const selectedDate = new Date(input.value);
|
||||||
|
if (selectedDate > maxDate) {
|
||||||
|
input.value = maxDate.toISOString().slice(0, 16);
|
||||||
|
}
|
||||||
|
doChangeBoosterExpiry(item.ItemType, input);
|
||||||
|
};
|
||||||
|
|
||||||
|
const input = document.createElement("input");
|
||||||
|
input.type = "datetime-local";
|
||||||
|
input.classList = "form-control form-control-sm";
|
||||||
|
input.value = formatDatetime("%Y-%m-%d %H:%M:%s", item.ExpiryDate * 1000);
|
||||||
|
input.max = "2038-01-19T03:14";
|
||||||
|
input.onblur = function () {
|
||||||
|
const maxDate = new Date(input.max);
|
||||||
|
const selectedDate = new Date(input.value);
|
||||||
|
if (selectedDate > maxDate) {
|
||||||
|
input.value = maxDate.toISOString().slice(0, 16);
|
||||||
|
}
|
||||||
|
doChangeBoosterExpiry(item.ItemType, input);
|
||||||
|
};
|
||||||
|
|
||||||
|
form.appendChild(input);
|
||||||
|
td.appendChild(form);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const a = document.createElement("a");
|
||||||
|
a.href = "#";
|
||||||
|
a.onclick = function (event) {
|
||||||
|
event.preventDefault();
|
||||||
|
setBooster(item.ItemType, 0);
|
||||||
|
};
|
||||||
|
a.title = loc("code_remove");
|
||||||
|
a.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M135.2 17.7L128 32H32C14.3 32 0 46.3 0 64S14.3 96 32 96H416c17.7 0 32-14.3 32-32s-14.3-32-32-32H320l-7.2-14.3C307.4 6.8 296.3 0 284.2 0H163.8c-12.1 0-23.2 6.8-28.6 17.7zM416 128H32L53.2 467c1.6 25.3 22.6 45 47.9 45H346.9c25.3 0 46.3-19.7 47.9-45L416 128z"/></svg>`;
|
||||||
|
td.appendChild(a);
|
||||||
|
}
|
||||||
|
tr.appendChild(td);
|
||||||
|
}
|
||||||
|
document.getElementById("Boosters-list").appendChild(tr);
|
||||||
|
});
|
||||||
|
|
||||||
document.getElementById("FlavourItems-list").innerHTML = "";
|
document.getElementById("FlavourItems-list").innerHTML = "";
|
||||||
data.FlavourItems.forEach(item => {
|
data.FlavourItems.forEach(item => {
|
||||||
const datalist = document.getElementById("datalist-FlavourItems");
|
const datalist = document.getElementById("datalist-FlavourItems");
|
||||||
@ -1619,63 +1680,6 @@ function updateInventory() {
|
|||||||
}
|
}
|
||||||
document.getElementById("changeSyndicate").value = data.SupportedSyndicate ?? "";
|
document.getElementById("changeSyndicate").value = data.SupportedSyndicate ?? "";
|
||||||
|
|
||||||
document.getElementById("Boosters-list").innerHTML = "";
|
|
||||||
const now = Math.floor(Date.now() / 1000);
|
|
||||||
data.Boosters.forEach(({ ItemType, ExpiryDate }) => {
|
|
||||||
if (ExpiryDate < now) {
|
|
||||||
// Booster has expired, skip it
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const tr = document.createElement("tr");
|
|
||||||
{
|
|
||||||
const td = document.createElement("td");
|
|
||||||
td.textContent = itemMap[ItemType]?.name ?? ItemType;
|
|
||||||
tr.appendChild(td);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
const td = document.createElement("td");
|
|
||||||
td.classList = "text-end text-nowrap";
|
|
||||||
const timeString = formatDatetime("%Y-%m-%d %H:%M:%s", ExpiryDate * 1000);
|
|
||||||
const inlineForm = document.createElement("form");
|
|
||||||
const input = document.createElement("input");
|
|
||||||
|
|
||||||
inlineForm.style.display = "inline-block";
|
|
||||||
inlineForm.onsubmit = function (event) {
|
|
||||||
event.preventDefault();
|
|
||||||
doChangeBoosterExpiry(ItemType, input);
|
|
||||||
};
|
|
||||||
input.type = "datetime-local";
|
|
||||||
input.classList.add("form-control");
|
|
||||||
input.classList.add("form-control-sm");
|
|
||||||
input.value = timeString;
|
|
||||||
let changed = false;
|
|
||||||
input.onchange = function () {
|
|
||||||
changed = true;
|
|
||||||
};
|
|
||||||
input.onblur = function () {
|
|
||||||
if (changed) {
|
|
||||||
doChangeBoosterExpiry(ItemType, input);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
inlineForm.appendChild(input);
|
|
||||||
|
|
||||||
td.appendChild(inlineForm);
|
|
||||||
|
|
||||||
const removeButton = document.createElement("a");
|
|
||||||
removeButton.title = loc("code_remove");
|
|
||||||
removeButton.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M135.2 17.7L128 32H32C14.3 32 0 46.3 0 64S14.3 96 32 96H416c17.7 0 32-14.3 32-32s-14.3-32-32-32H320l-7.2-14.3C307.4 6.8 296.3 0 284.2 0H163.8c-12.1 0-23.2 6.8-28.6 17.7zM416 128H32L53.2 467c1.6 25.3 22.6 45 47.9 45H346.9c25.3 0 46.3-19.7 47.9-45L416 128z"/></svg>`;
|
|
||||||
removeButton.href = "#";
|
|
||||||
removeButton.onclick = function (event) {
|
|
||||||
event.preventDefault();
|
|
||||||
setBooster(ItemType, 0);
|
|
||||||
};
|
|
||||||
td.appendChild(removeButton);
|
|
||||||
|
|
||||||
tr.appendChild(td);
|
|
||||||
}
|
|
||||||
document.getElementById("Boosters-list").appendChild(tr);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (single.getCurrentPath().startsWith("/webui/guildView")) {
|
if (single.getCurrentPath().startsWith("/webui/guildView")) {
|
||||||
const guildReq = $.get("/custom/getGuild?guildId=" + window.guildId);
|
const guildReq = $.get("/custom/getGuild?guildId=" + window.guildId);
|
||||||
guildReq.done(guildData => {
|
guildReq.done(guildData => {
|
||||||
@ -3542,7 +3546,7 @@ function handleModularSelection(category) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function setBooster(ItemType, ExpiryDate, callback) {
|
function setBooster(ItemType, ExpiryDate) {
|
||||||
revalidateAuthz().then(() => {
|
revalidateAuthz().then(() => {
|
||||||
$.post({
|
$.post({
|
||||||
url: "/custom/setBooster?" + window.authz,
|
url: "/custom/setBooster?" + window.authz,
|
||||||
@ -3555,33 +3559,27 @@ function setBooster(ItemType, ExpiryDate, callback) {
|
|||||||
])
|
])
|
||||||
}).done(function () {
|
}).done(function () {
|
||||||
updateInventory();
|
updateInventory();
|
||||||
if (callback) callback();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function doAcquireBoosters() {
|
function doAcquireBooster() {
|
||||||
const uniqueName = getKey(document.getElementById("acquire-type-Boosters"));
|
const uniqueName = getKey(document.getElementById("acquire-type-Boosters"));
|
||||||
if (!uniqueName) {
|
if (!uniqueName) {
|
||||||
$("#acquire-type-Boosters").addClass("is-invalid").focus();
|
$("#acquire-type-Boosters").addClass("is-invalid").focus();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const ExpiryDate = Date.now() / 1000 + 3 * 24 * 60 * 60; // default 3 days
|
setBooster(uniqueName, Math.floor(Date.now() / 1000 + 3 * 24 * 60 * 60));
|
||||||
setBooster(uniqueName, ExpiryDate, () => {
|
document.getElementById("acquire-type-Boosters").value = "";
|
||||||
$("#acquire-type-Boosters").val("");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function doChangeBoosterExpiry(ItemType, ExpiryDateInput) {
|
function doChangeBoosterExpiry(ItemType, ExpiryDateInput) {
|
||||||
console.log("Changing booster expiry for", ItemType, "to", ExpiryDateInput.value);
|
const ExpiryDate = Math.floor(new Date(ExpiryDateInput.value).getTime() / 1000);
|
||||||
// cast local datetime string to unix timestamp
|
|
||||||
const ExpiryDate = Math.trunc(new Date(ExpiryDateInput.value).getTime() / 1000);
|
|
||||||
if (isNaN(ExpiryDate)) {
|
if (isNaN(ExpiryDate)) {
|
||||||
ExpiryDateInput.addClass("is-invalid").focus();
|
ExpiryDateInput.addClass("is-invalid").focus();
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
setBooster(ItemType, ExpiryDate);
|
setBooster(ItemType, ExpiryDate);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatDatetime(fmt, date) {
|
function formatDatetime(fmt, date) {
|
||||||
|
|||||||
@ -109,7 +109,7 @@ dict = {
|
|||||||
inventory_moaPets: `Moas`,
|
inventory_moaPets: `Moas`,
|
||||||
inventory_kubrowPets: `Bestien`,
|
inventory_kubrowPets: `Bestien`,
|
||||||
inventory_evolutionProgress: `Incarnon-Entwicklungsfortschritte`,
|
inventory_evolutionProgress: `Incarnon-Entwicklungsfortschritte`,
|
||||||
inventory_Boosters: `Booster`,
|
inventory_boosters: `Booster`,
|
||||||
inventory_flavourItems: `<abbr title="Animationssets, Glyphen, Farbpaletten usw.">Sammlerstücke</abbr>`,
|
inventory_flavourItems: `<abbr title="Animationssets, Glyphen, Farbpaletten usw.">Sammlerstücke</abbr>`,
|
||||||
inventory_shipDecorations: `Schiffsdekorationen`,
|
inventory_shipDecorations: `Schiffsdekorationen`,
|
||||||
inventory_bulkAddSuits: `Fehlende Warframes hinzufügen`,
|
inventory_bulkAddSuits: `Fehlende Warframes hinzufügen`,
|
||||||
|
|||||||
@ -108,7 +108,7 @@ dict = {
|
|||||||
inventory_moaPets: `Moas`,
|
inventory_moaPets: `Moas`,
|
||||||
inventory_kubrowPets: `Beasts`,
|
inventory_kubrowPets: `Beasts`,
|
||||||
inventory_evolutionProgress: `Incarnon Evolution Progress`,
|
inventory_evolutionProgress: `Incarnon Evolution Progress`,
|
||||||
inventory_Boosters: `Boosters`,
|
inventory_boosters: `Boosters`,
|
||||||
inventory_flavourItems: `<abbr title="Animation Sets, Glyphs, Palettes, etc.">Flavour Items</abbr>`,
|
inventory_flavourItems: `<abbr title="Animation Sets, Glyphs, Palettes, etc.">Flavour Items</abbr>`,
|
||||||
inventory_shipDecorations: `Ship Decorations`,
|
inventory_shipDecorations: `Ship Decorations`,
|
||||||
inventory_bulkAddSuits: `Add Missing Warframes`,
|
inventory_bulkAddSuits: `Add Missing Warframes`,
|
||||||
|
|||||||
@ -109,7 +109,7 @@ dict = {
|
|||||||
inventory_moaPets: `Moas`,
|
inventory_moaPets: `Moas`,
|
||||||
inventory_kubrowPets: `Bestias`,
|
inventory_kubrowPets: `Bestias`,
|
||||||
inventory_evolutionProgress: `Progreso de evolución Incarnon`,
|
inventory_evolutionProgress: `Progreso de evolución Incarnon`,
|
||||||
inventory_Boosters: `Potenciadores`,
|
inventory_boosters: `Potenciadores`,
|
||||||
inventory_flavourItems: `<abbr title="Conjuntos de animaciones, glifos, paletas, etc.">Ítems estéticos</abbr>`,
|
inventory_flavourItems: `<abbr title="Conjuntos de animaciones, glifos, paletas, etc.">Ítems estéticos</abbr>`,
|
||||||
inventory_shipDecorations: `Decoraciones de nave`,
|
inventory_shipDecorations: `Decoraciones de nave`,
|
||||||
inventory_bulkAddSuits: `Agregar Warframes faltantes`,
|
inventory_bulkAddSuits: `Agregar Warframes faltantes`,
|
||||||
|
|||||||
@ -109,7 +109,7 @@ dict = {
|
|||||||
inventory_moaPets: `Moas`,
|
inventory_moaPets: `Moas`,
|
||||||
inventory_kubrowPets: `Bêtes`,
|
inventory_kubrowPets: `Bêtes`,
|
||||||
inventory_evolutionProgress: `Progrès de l'évolution Incarnon`,
|
inventory_evolutionProgress: `Progrès de l'évolution Incarnon`,
|
||||||
inventory_Boosters: `Boosters`,
|
inventory_boosters: `Boosters`,
|
||||||
inventory_flavourItems: `[UNTRANSLATED] <abbr title="Animation Sets, Glyphs, Palettes, etc.">Flavour Items</abbr>`,
|
inventory_flavourItems: `[UNTRANSLATED] <abbr title="Animation Sets, Glyphs, Palettes, etc.">Flavour Items</abbr>`,
|
||||||
inventory_shipDecorations: `Décorations du vaisseau`,
|
inventory_shipDecorations: `Décorations du vaisseau`,
|
||||||
inventory_bulkAddSuits: `Ajouter les Warframes manquantes`,
|
inventory_bulkAddSuits: `Ajouter les Warframes manquantes`,
|
||||||
|
|||||||
@ -109,7 +109,7 @@ dict = {
|
|||||||
inventory_moaPets: `МОА`,
|
inventory_moaPets: `МОА`,
|
||||||
inventory_kubrowPets: `Звери`,
|
inventory_kubrowPets: `Звери`,
|
||||||
inventory_evolutionProgress: `Прогресс эволюции Инкарнонов`,
|
inventory_evolutionProgress: `Прогресс эволюции Инкарнонов`,
|
||||||
inventory_Boosters: `Бустеры`,
|
inventory_boosters: `Бустеры`,
|
||||||
inventory_flavourItems: `<abbr title="Наборы анимаций, глифы, палитры и т. д.">Уникальные предметы</abbr>`,
|
inventory_flavourItems: `<abbr title="Наборы анимаций, глифы, палитры и т. д.">Уникальные предметы</abbr>`,
|
||||||
inventory_shipDecorations: `Украшения корабля`,
|
inventory_shipDecorations: `Украшения корабля`,
|
||||||
inventory_bulkAddSuits: `Добавить отсутствующие Варфреймы`,
|
inventory_bulkAddSuits: `Добавить отсутствующие Варфреймы`,
|
||||||
|
|||||||
@ -109,7 +109,7 @@ dict = {
|
|||||||
inventory_moaPets: `МОА`,
|
inventory_moaPets: `МОА`,
|
||||||
inventory_kubrowPets: `Тварини`,
|
inventory_kubrowPets: `Тварини`,
|
||||||
inventory_evolutionProgress: `Прогрес еволюції Інкарнонів`,
|
inventory_evolutionProgress: `Прогрес еволюції Інкарнонів`,
|
||||||
inventory_Boosters: `Посилення`,
|
inventory_boosters: `Посилення`,
|
||||||
inventory_flavourItems: `<abbr title="Набори анімацій, гліфи, палітри і т. д.">Унікальні предмети</abbr>`,
|
inventory_flavourItems: `<abbr title="Набори анімацій, гліфи, палітри і т. д.">Унікальні предмети</abbr>`,
|
||||||
inventory_shipDecorations: `Прикраси судна`,
|
inventory_shipDecorations: `Прикраси судна`,
|
||||||
inventory_bulkAddSuits: `Додати відсутні Ворфрейми`,
|
inventory_bulkAddSuits: `Додати відсутні Ворфрейми`,
|
||||||
|
|||||||
@ -109,7 +109,7 @@ dict = {
|
|||||||
inventory_moaPets: `恐鸟`,
|
inventory_moaPets: `恐鸟`,
|
||||||
inventory_kubrowPets: `动物同伴`,
|
inventory_kubrowPets: `动物同伴`,
|
||||||
inventory_evolutionProgress: `灵化之源进度`,
|
inventory_evolutionProgress: `灵化之源进度`,
|
||||||
inventory_Boosters: `加成器`,
|
inventory_boosters: `加成器`,
|
||||||
inventory_flavourItems: `<abbr title="动作表情、浮印、调色板等">装饰物品</abbr>`,
|
inventory_flavourItems: `<abbr title="动作表情、浮印、调色板等">装饰物品</abbr>`,
|
||||||
inventory_shipDecorations: `飞船装饰`,
|
inventory_shipDecorations: `飞船装饰`,
|
||||||
inventory_bulkAddSuits: `添加缺失战甲`,
|
inventory_bulkAddSuits: `添加缺失战甲`,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user