You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

install.js 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import {hideElem, showElem} from '../utils/dom.js';
  2. import {GET} from '../modules/fetch.js';
  3. export function initInstall() {
  4. const page = document.querySelector('.page-content.install');
  5. if (!page) {
  6. return;
  7. }
  8. if (page.classList.contains('post-install')) {
  9. initPostInstall();
  10. } else {
  11. initPreInstall();
  12. }
  13. }
  14. function initPreInstall() {
  15. const defaultDbUser = 'gitea';
  16. const defaultDbName = 'gitea';
  17. const defaultDbHosts = {
  18. mysql: '127.0.0.1:3306',
  19. postgres: '127.0.0.1:5432',
  20. mssql: '127.0.0.1:1433',
  21. };
  22. const dbHost = document.getElementById('db_host');
  23. const dbUser = document.getElementById('db_user');
  24. const dbName = document.getElementById('db_name');
  25. // Database type change detection.
  26. document.getElementById('db_type').addEventListener('change', function () {
  27. const dbType = this.value;
  28. hideElem('div[data-db-setting-for]');
  29. showElem(`div[data-db-setting-for=${dbType}]`);
  30. if (dbType !== 'sqlite3') {
  31. // for most remote database servers
  32. showElem('div[data-db-setting-for=common-host]');
  33. const lastDbHost = dbHost.value;
  34. const isDbHostDefault = !lastDbHost || Object.values(defaultDbHosts).includes(lastDbHost);
  35. if (isDbHostDefault) {
  36. dbHost.value = defaultDbHosts[dbType] ?? '';
  37. }
  38. if (!dbUser.value && !dbName.value) {
  39. dbUser.value = defaultDbUser;
  40. dbName.value = defaultDbName;
  41. }
  42. } // else: for SQLite3, the default path is always prepared by backend code (setting)
  43. });
  44. document.getElementById('db_type').dispatchEvent(new Event('change'));
  45. const appUrl = document.getElementById('app_url');
  46. if (appUrl.value.includes('://localhost')) {
  47. appUrl.value = window.location.href;
  48. }
  49. const domain = document.getElementById('domain');
  50. if (domain.value.trim() === 'localhost') {
  51. domain.value = window.location.hostname;
  52. }
  53. // TODO: better handling of exclusive relations.
  54. document.querySelector('#offline-mode input').addEventListener('change', function () {
  55. if (this.checked) {
  56. document.querySelector('#disable-gravatar input').checked = true;
  57. document.querySelector('#federated-avatar-lookup input').checked = false;
  58. }
  59. });
  60. document.querySelector('#disable-gravatar input').addEventListener('change', function () {
  61. if (this.checked) {
  62. document.querySelector('#federated-avatar-lookup input').checked = false;
  63. } else {
  64. document.querySelector('#offline-mode input').checked = false;
  65. }
  66. });
  67. document.querySelector('#federated-avatar-lookup input').addEventListener('change', function () {
  68. if (this.checked) {
  69. document.querySelector('#disable-gravatar input').checked = false;
  70. document.querySelector('#offline-mode input').checked = false;
  71. }
  72. });
  73. document.querySelector('#enable-openid-signin input').addEventListener('change', function () {
  74. if (this.checked) {
  75. if (!document.querySelector('#disable-registration input').checked) {
  76. document.querySelector('#enable-openid-signup input').checked = true;
  77. }
  78. } else {
  79. document.querySelector('#enable-openid-signup input').checked = false;
  80. }
  81. });
  82. document.querySelector('#disable-registration input').addEventListener('change', function () {
  83. if (this.checked) {
  84. document.querySelector('#enable-captcha input').checked = false;
  85. document.querySelector('#enable-openid-signup input').checked = false;
  86. } else {
  87. document.querySelector('#enable-openid-signup input').checked = true;
  88. }
  89. });
  90. document.querySelector('#enable-captcha input').addEventListener('change', function () {
  91. if (this.checked) {
  92. document.querySelector('#disable-registration input').checked = false;
  93. }
  94. });
  95. }
  96. function initPostInstall() {
  97. const el = document.getElementById('goto-user-login');
  98. if (!el) return;
  99. const targetUrl = el.getAttribute('href');
  100. let tid = setInterval(async () => {
  101. try {
  102. const resp = await GET(targetUrl);
  103. if (tid && resp.status === 200) {
  104. clearInterval(tid);
  105. tid = null;
  106. window.location.href = targetUrl;
  107. }
  108. } catch {}
  109. }, 1000);
  110. }