Harden bot, storage and web API
This commit is contained in:
parent
e974bc6660
commit
20624a5c9c
43 changed files with 1265 additions and 1012 deletions
|
|
@ -2,11 +2,11 @@ const API_KEY_STORAGE_KEY = "palico-api-key";
|
|||
const DISPLAY_NAME_STORAGE_KEY = "palico-display-name";
|
||||
|
||||
export function getStoredApiKey() {
|
||||
return localStorage.getItem(API_KEY_STORAGE_KEY) || "";
|
||||
return sessionStorage.getItem(API_KEY_STORAGE_KEY) || "";
|
||||
}
|
||||
|
||||
export function setStoredApiKey(value) {
|
||||
localStorage.setItem(API_KEY_STORAGE_KEY, value || "");
|
||||
sessionStorage.setItem(API_KEY_STORAGE_KEY, value || "");
|
||||
}
|
||||
|
||||
export function getStoredDisplayName() {
|
||||
|
|
|
|||
|
|
@ -41,9 +41,11 @@ const elements = {
|
|||
heroQueueBtn: document.getElementById("heroQueueBtn"),
|
||||
uploadSection: document.getElementById("uploadSection"),
|
||||
queueSection: document.getElementById("queueSection"),
|
||||
backHomeBtn: document.getElementById("backHomeBtn"),
|
||||
};
|
||||
|
||||
let pollIntervalId = null;
|
||||
let refreshPromise = null;
|
||||
|
||||
const { setStatus, clearStatus } = createStatusManager(elements.status);
|
||||
const apiFetch = createApiClient({
|
||||
|
|
@ -51,7 +53,18 @@ const apiFetch = createApiClient({
|
|||
getApiKey: () => state.apiKey,
|
||||
});
|
||||
|
||||
async function refreshAll({ silent = false } = {}) {
|
||||
function refreshAll(options = {}) {
|
||||
if (refreshPromise) {
|
||||
return refreshPromise;
|
||||
}
|
||||
|
||||
refreshPromise = performRefresh(options).finally(() => {
|
||||
refreshPromise = null;
|
||||
});
|
||||
return refreshPromise;
|
||||
}
|
||||
|
||||
async function performRefresh({ silent = false } = {}) {
|
||||
if (!silent) {
|
||||
clearStatus();
|
||||
}
|
||||
|
|
@ -293,6 +306,9 @@ function bindEvents() {
|
|||
elements.heroQueueBtn?.addEventListener("click", () =>
|
||||
elements.queueSection?.scrollIntoView({ behavior: "smooth" })
|
||||
);
|
||||
elements.backHomeBtn?.addEventListener("click", () => {
|
||||
window.location.href = "/";
|
||||
});
|
||||
|
||||
elements.playerButtons?.forEach((button) => {
|
||||
button.addEventListener("click", async () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue