code.gitea.io/gitea@v1.22.3/web_src/js/features/admin/selfcheck.js (about) 1 import {toggleElem} from '../../utils/dom.js'; 2 import {POST} from '../../modules/fetch.js'; 3 4 const {appSubUrl} = window.config; 5 6 export async function initAdminSelfCheck() { 7 const elCheckByFrontend = document.querySelector('#self-check-by-frontend'); 8 if (!elCheckByFrontend) return; 9 10 const elContent = document.querySelector('.page-content.admin .admin-setting-content'); 11 12 // send frontend self-check request 13 const resp = await POST(`${appSubUrl}/admin/self_check`, { 14 data: new URLSearchParams({ 15 location_origin: window.location.origin, 16 now: Date.now(), // TODO: check time difference between server and client 17 }), 18 }); 19 const json = await resp.json(); 20 toggleElem(elCheckByFrontend, Boolean(json.problems?.length)); 21 for (const problem of json.problems ?? []) { 22 const elProblem = document.createElement('div'); 23 elProblem.classList.add('ui', 'warning', 'message'); 24 elProblem.textContent = problem; 25 elCheckByFrontend.append(elProblem); 26 } 27 28 // only show the "no problem" if there is no visible "self-check-problem" 29 const hasProblem = Boolean(elContent.querySelectorAll('.self-check-problem:not(.tw-hidden)').length); 30 toggleElem(elContent.querySelector('.self-check-no-problem'), !hasProblem); 31 }