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