gitea源码

selfcheck.ts 1.3KB

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