Prepare Soundbox Ops deployment
This commit is contained in:
@ -1,6 +1,21 @@
|
||||
const ADMIN_TOKEN_KEY = "admin_token";
|
||||
const ADMIN_PROFILE_KEY = "admin_profile";
|
||||
|
||||
function resolveAdminApiBase() {
|
||||
const host = window.location.hostname;
|
||||
const port = window.location.port;
|
||||
const configured = window.SOUNDBOX_ADMIN_API_BASE || "";
|
||||
if (configured) {
|
||||
return configured.replace(/\/$/, "");
|
||||
}
|
||||
if ((host === "127.0.0.1" || host === "localhost") && port === "4173") {
|
||||
return "http://127.0.0.1:3100";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
const ADMIN_API_BASE = resolveAdminApiBase();
|
||||
|
||||
function formatMoney(value) {
|
||||
const number = Number(value || 0);
|
||||
if (!Number.isFinite(number)) {
|
||||
@ -50,7 +65,8 @@ async function adminFetch(path, options = {}) {
|
||||
} = options;
|
||||
|
||||
const suffix = buildQuery(query || {});
|
||||
const url = suffix ? `${path}?${suffix}` : path;
|
||||
const relativeUrl = suffix ? `${path}?${suffix}` : path;
|
||||
const url = `${ADMIN_API_BASE}${relativeUrl}`;
|
||||
const headers = {
|
||||
...extraHeaders
|
||||
};
|
||||
@ -203,8 +219,65 @@ window.AdminUIAPI = {
|
||||
}),
|
||||
listTerminals: (query) => adminFetch("/admin/terminals", { query }),
|
||||
getTerminal: (id) => adminFetch(`/admin/terminals/${id}`),
|
||||
listSoundboxVendors: (query) => adminFetch("/admin/soundbox-vendors", { query }),
|
||||
createSoundboxVendor: (payload) =>
|
||||
adminFetch("/admin/soundbox-vendors", {
|
||||
method: "POST",
|
||||
body: payload || {}
|
||||
}),
|
||||
patchSoundboxVendor: (id, payload) =>
|
||||
adminFetch(`/admin/soundbox-vendors/${id}`, {
|
||||
method: "PATCH",
|
||||
body: payload || {}
|
||||
}),
|
||||
deleteSoundboxVendor: (id) =>
|
||||
adminFetch(`/admin/soundbox-vendors/${id}`, {
|
||||
method: "DELETE"
|
||||
}),
|
||||
listSoundboxModels: (query) => adminFetch("/admin/soundbox-models", { query }),
|
||||
createSoundboxModel: (payload) =>
|
||||
adminFetch("/admin/soundbox-models", {
|
||||
method: "POST",
|
||||
body: payload || {}
|
||||
}),
|
||||
patchSoundboxModel: (id, payload) =>
|
||||
adminFetch(`/admin/soundbox-models/${id}`, {
|
||||
method: "PATCH",
|
||||
body: payload || {}
|
||||
}),
|
||||
deleteSoundboxModel: (id) =>
|
||||
adminFetch(`/admin/soundbox-models/${id}`, {
|
||||
method: "DELETE"
|
||||
}),
|
||||
listDevices: (query) => adminFetch("/admin/devices", { query }),
|
||||
createDevice: (payload) =>
|
||||
adminFetch("/admin/devices", {
|
||||
method: "POST",
|
||||
body: payload || {}
|
||||
}),
|
||||
getDevice: (id) => adminFetch(`/admin/devices/${id}`),
|
||||
patchDevice: (id, payload) =>
|
||||
adminFetch(`/admin/devices/${id}`, {
|
||||
method: "PATCH",
|
||||
body: payload || {}
|
||||
}),
|
||||
bindDevice: (id, payload) =>
|
||||
adminFetch(`/admin/devices/${id}/bind`, {
|
||||
method: "POST",
|
||||
body: payload || {}
|
||||
}),
|
||||
unbindDevice: (id) =>
|
||||
adminFetch(`/admin/devices/${id}/unbind`, {
|
||||
method: "POST",
|
||||
body: {}
|
||||
}),
|
||||
createDeviceCommand: (id, payload) =>
|
||||
adminFetch(`/admin/devices/${id}/commands`, {
|
||||
method: "POST",
|
||||
body: payload || {}
|
||||
}),
|
||||
listDeviceCommands: (id, query) =>
|
||||
adminFetch(`/admin/devices/${id}/commands`, { query }),
|
||||
rotateDeviceCredential: (id) =>
|
||||
adminFetch(`/admin/devices/${id}/credentials/rotate`, {
|
||||
method: "POST",
|
||||
|
||||
Reference in New Issue
Block a user