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;
|
|
|
|
|
2024-11-11 04:13:57 -07:00
|
|
|
const elContent = document.querySelector<HTMLDivElement>('.page-content.admin .admin-setting-content');
|
2024-05-10 06:07:01 -06:00
|
|
|
|
|
|
|
// 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,
|
2024-11-11 04:13:57 -07:00
|
|
|
now: String(Date.now()), // TODO: check time difference between server and client
|
2024-05-10 06:07:01 -06:00
|
|
|
}),
|
|
|
|
});
|
2024-11-11 04:13:57 -07:00
|
|
|
const json: Record<string, any> = await resp.json();
|
2024-05-10 06:07:01 -06:00
|
|
|
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);
|
|
|
|
}
|