v0.0.2
This commit is contained in:
1 parent
c7d09077fc
commit
f813441bf0
45 files changed
+938
-334
No files matched your search
+5
-4
@@ -9,7 +9,7 @@
|
||||
theme: read(localStorage, 'routeros_theme') === 'light' ? 'light' : 'dark',
|
||||
collapsed: read(localStorage, 'mbs_sidebar') === 'collapsed', mobile: false,
|
||||
routeId: 0, cache: {}, selected: new Set(), page: 1, pageSize: 20,
|
||||
health: { online: null, latency: null }, diff: null, diffMode: 'split', diffChangesOnly: true, diffSearch: '', diffPage: 1, diffPageSize: 200,
|
||||
health: { online: null, latency: null }, diff: null, diffMode: 'split', diffChangesOnly: true, diffSearch: '', diffPage: 1, diffPageSize: 200, diffShowAll: false,
|
||||
filters: { search: '', backup_type: '', router_id: '', created_on: '', sort_by: 'created_at', order: 'desc' }
|
||||
};
|
||||
M.$ = (selector, root = document) => root.querySelector(selector);
|
||||
@@ -119,18 +119,19 @@
|
||||
M.card = (title, body, extras = '', classes = '') => `<section class="card ${classes}"><header class="card-header"><h2>${M.tr(title)}</h2>${extras}</header>${body}</section>`;
|
||||
M.errorMessage = error => error && error.message ? error.message : M.t('ui.operationError');
|
||||
M.api = async (path, options = {}) => {
|
||||
const { method = 'GET', body, blob = false, text = false, timeout = 180000, quietAuth = false, signal } = options;
|
||||
const { method = 'GET', body, blob = false, text = false, raw = false, timeout = 180000, quietAuth = false, signal } = options;
|
||||
const controller = new AbortController();
|
||||
const timer = setTimeout(() => controller.abort(), timeout);
|
||||
const forwardAbort = () => controller.abort();
|
||||
if (signal) signal.addEventListener('abort', forwardAbort, { once: true });
|
||||
const headers = { Accept: blob ? '*/*' : text ? 'text/html' : 'application/json' };
|
||||
if (M.state.token) headers.Authorization = `Bearer ${M.state.token}`;
|
||||
if (body !== undefined) headers['Content-Type'] = 'application/json';
|
||||
if (body !== undefined && raw) headers['Content-Type'] = 'application/octet-stream';
|
||||
else if (body !== undefined) headers['Content-Type'] = 'application/json';
|
||||
let response;
|
||||
try {
|
||||
response = await fetch(`${M.$('meta[name="api-prefix"]')?.content || '/api'}${path}`, {
|
||||
method, headers, body: body === undefined ? undefined : JSON.stringify(body), signal: controller.signal,
|
||||
method, headers, body: body === undefined ? undefined : raw ? body : JSON.stringify(body), signal: controller.signal,
|
||||
cache: 'no-store', credentials: 'same-origin', redirect: 'error'
|
||||
});
|
||||
if (!response.ok) {
|
||||
|
||||
Reference in new issue
Block a user