2024-07-07 09:32:30 -06:00
|
|
|
import {hideElem, showElem} from '../utils/dom.ts';
|
|
|
|
import {GET} from '../modules/fetch.ts';
|
2022-01-28 14:00:11 -07:00
|
|
|
|
2021-10-16 11:28:04 -06:00
|
|
|
export function initInstall() {
|
2024-02-21 01:13:48 -07:00
|
|
|
const page = document.querySelector('.page-content.install');
|
|
|
|
if (!page) {
|
2021-10-16 11:28:04 -06:00
|
|
|
return;
|
|
|
|
}
|
2024-02-21 01:13:48 -07:00
|
|
|
if (page.classList.contains('post-install')) {
|
2023-03-03 19:12:02 -07:00
|
|
|
initPostInstall();
|
|
|
|
} else {
|
|
|
|
initPreInstall();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function initPreInstall() {
|
2021-12-06 22:44:08 -07:00
|
|
|
const defaultDbUser = 'gitea';
|
|
|
|
const defaultDbName = 'gitea';
|
|
|
|
|
|
|
|
const defaultDbHosts = {
|
|
|
|
mysql: '127.0.0.1:3306',
|
|
|
|
postgres: '127.0.0.1:5432',
|
2024-03-22 08:06:53 -06:00
|
|
|
mssql: '127.0.0.1:1433',
|
2021-12-06 22:44:08 -07:00
|
|
|
};
|
|
|
|
|
2024-06-10 14:49:33 -06:00
|
|
|
const dbHost = document.querySelector('#db_host');
|
|
|
|
const dbUser = document.querySelector('#db_user');
|
|
|
|
const dbName = document.querySelector('#db_name');
|
2021-10-16 11:28:04 -06:00
|
|
|
|
|
|
|
// Database type change detection.
|
2024-06-10 14:49:33 -06:00
|
|
|
document.querySelector('#db_type').addEventListener('change', function () {
|
2024-02-21 01:13:48 -07:00
|
|
|
const dbType = this.value;
|
|
|
|
hideElem('div[data-db-setting-for]');
|
|
|
|
showElem(`div[data-db-setting-for=${dbType}]`);
|
2021-12-06 22:44:08 -07:00
|
|
|
|
|
|
|
if (dbType !== 'sqlite3') {
|
|
|
|
// for most remote database servers
|
2024-02-21 01:13:48 -07:00
|
|
|
showElem('div[data-db-setting-for=common-host]');
|
|
|
|
const lastDbHost = dbHost.value;
|
2021-12-06 22:44:08 -07:00
|
|
|
const isDbHostDefault = !lastDbHost || Object.values(defaultDbHosts).includes(lastDbHost);
|
|
|
|
if (isDbHostDefault) {
|
2024-02-21 01:13:48 -07:00
|
|
|
dbHost.value = defaultDbHosts[dbType] ?? '';
|
2021-10-16 11:28:04 -06:00
|
|
|
}
|
2024-02-21 01:13:48 -07:00
|
|
|
if (!dbUser.value && !dbName.value) {
|
|
|
|
dbUser.value = defaultDbUser;
|
|
|
|
dbName.value = defaultDbName;
|
2021-10-16 11:28:04 -06:00
|
|
|
}
|
2021-12-06 22:44:08 -07:00
|
|
|
} // else: for SQLite3, the default path is always prepared by backend code (setting)
|
2024-02-21 01:13:48 -07:00
|
|
|
});
|
2024-06-10 14:49:33 -06:00
|
|
|
document.querySelector('#db_type').dispatchEvent(new Event('change'));
|
2021-10-16 11:28:04 -06:00
|
|
|
|
2024-06-10 14:49:33 -06:00
|
|
|
const appUrl = document.querySelector('#app_url');
|
2024-02-21 01:13:48 -07:00
|
|
|
if (appUrl.value.includes('://localhost')) {
|
|
|
|
appUrl.value = window.location.href;
|
2023-03-03 19:12:02 -07:00
|
|
|
}
|
|
|
|
|
2024-06-10 14:49:33 -06:00
|
|
|
const domain = document.querySelector('#domain');
|
2024-02-21 01:13:48 -07:00
|
|
|
if (domain.value.trim() === 'localhost') {
|
|
|
|
domain.value = window.location.hostname;
|
2023-03-03 19:12:02 -07:00
|
|
|
}
|
|
|
|
|
2021-10-16 11:28:04 -06:00
|
|
|
// TODO: better handling of exclusive relations.
|
2024-02-21 01:13:48 -07:00
|
|
|
document.querySelector('#offline-mode input').addEventListener('change', function () {
|
|
|
|
if (this.checked) {
|
|
|
|
document.querySelector('#disable-gravatar input').checked = true;
|
|
|
|
document.querySelector('#federated-avatar-lookup input').checked = false;
|
2021-10-16 11:28:04 -06:00
|
|
|
}
|
|
|
|
});
|
2024-02-21 01:13:48 -07:00
|
|
|
document.querySelector('#disable-gravatar input').addEventListener('change', function () {
|
|
|
|
if (this.checked) {
|
|
|
|
document.querySelector('#federated-avatar-lookup input').checked = false;
|
2021-10-16 11:28:04 -06:00
|
|
|
} else {
|
2024-02-21 01:13:48 -07:00
|
|
|
document.querySelector('#offline-mode input').checked = false;
|
2021-10-16 11:28:04 -06:00
|
|
|
}
|
|
|
|
});
|
2024-02-21 01:13:48 -07:00
|
|
|
document.querySelector('#federated-avatar-lookup input').addEventListener('change', function () {
|
|
|
|
if (this.checked) {
|
|
|
|
document.querySelector('#disable-gravatar input').checked = false;
|
|
|
|
document.querySelector('#offline-mode input').checked = false;
|
2021-10-16 11:28:04 -06:00
|
|
|
}
|
|
|
|
});
|
2024-02-21 01:13:48 -07:00
|
|
|
document.querySelector('#enable-openid-signin input').addEventListener('change', function () {
|
|
|
|
if (this.checked) {
|
|
|
|
if (!document.querySelector('#disable-registration input').checked) {
|
|
|
|
document.querySelector('#enable-openid-signup input').checked = true;
|
2021-10-16 11:28:04 -06:00
|
|
|
}
|
|
|
|
} else {
|
2024-02-21 01:13:48 -07:00
|
|
|
document.querySelector('#enable-openid-signup input').checked = false;
|
2021-10-16 11:28:04 -06:00
|
|
|
}
|
|
|
|
});
|
2024-02-21 01:13:48 -07:00
|
|
|
document.querySelector('#disable-registration input').addEventListener('change', function () {
|
|
|
|
if (this.checked) {
|
|
|
|
document.querySelector('#enable-captcha input').checked = false;
|
|
|
|
document.querySelector('#enable-openid-signup input').checked = false;
|
2021-10-16 11:28:04 -06:00
|
|
|
} else {
|
2024-02-21 01:13:48 -07:00
|
|
|
document.querySelector('#enable-openid-signup input').checked = true;
|
2021-10-16 11:28:04 -06:00
|
|
|
}
|
|
|
|
});
|
2024-02-21 01:13:48 -07:00
|
|
|
document.querySelector('#enable-captcha input').addEventListener('change', function () {
|
|
|
|
if (this.checked) {
|
|
|
|
document.querySelector('#disable-registration input').checked = false;
|
2021-10-16 11:28:04 -06:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2023-03-03 19:12:02 -07:00
|
|
|
|
|
|
|
function initPostInstall() {
|
2024-06-10 14:49:33 -06:00
|
|
|
const el = document.querySelector('#goto-user-login');
|
2023-03-03 19:12:02 -07:00
|
|
|
if (!el) return;
|
|
|
|
|
|
|
|
const targetUrl = el.getAttribute('href');
|
|
|
|
let tid = setInterval(async () => {
|
|
|
|
try {
|
2023-09-18 18:50:30 -06:00
|
|
|
const resp = await GET(targetUrl);
|
2023-03-03 19:12:02 -07:00
|
|
|
if (tid && resp.status === 200) {
|
|
|
|
clearInterval(tid);
|
|
|
|
tid = null;
|
|
|
|
window.location.href = targetUrl;
|
|
|
|
}
|
|
|
|
} catch {}
|
|
|
|
}, 1000);
|
|
|
|
}
|