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