2024-07-07 09:32:30 -06:00
|
|
|
import {toggleElem} from '../../utils/dom.ts';
|
|
|
|
import {POST} from '../../modules/fetch.ts';
|
2024-05-10 06:07:01 -06:00
|
|
|
|
|
|
|
const {appSubUrl} = window.config;
|
|
|
|
|
|
|
|
export async function initAdminSelfCheck() {
|
|
|
|
const elCheckByFrontend = document.querySelector('#self-check-by-frontend');
|
|
|
|
if (!elCheckByFrontend) return;
|
|
|
|
|
|
|
|
const elContent = document.querySelector('.page-content.admin .admin-setting-content');
|
|
|
|
|
|
|
|
// send frontend self-check request
|
2024-10-09 22:56:49 -06:00
|
|
|
const resp = await POST(`${appSubUrl}/-/admin/self_check`, {
|
2024-05-10 06:07:01 -06:00
|
|
|
data: new URLSearchParams({
|
|
|
|
location_origin: window.location.origin,
|
|
|
|
now: Date.now(), // TODO: check time difference between server and client
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
const json = await resp.json();
|
|
|
|
toggleElem(elCheckByFrontend, Boolean(json.problems?.length));
|
|
|
|
for (const problem of json.problems ?? []) {
|
|
|
|
const elProblem = document.createElement('div');
|
|
|
|
elProblem.classList.add('ui', 'warning', 'message');
|
|
|
|
elProblem.textContent = problem;
|
|
|
|
elCheckByFrontend.append(elProblem);
|
|
|
|
}
|
|
|
|
|
|
|
|
// only show the "no problem" if there is no visible "self-check-problem"
|
|
|
|
const hasProblem = Boolean(elContent.querySelectorAll('.self-check-problem:not(.tw-hidden)').length);
|
|
|
|
toggleElem(elContent.querySelector('.self-check-no-problem'), !hasProblem);
|
|
|
|
}
|