forgejo/web_src/js/features/install.js

124 lines
3.5 KiB
JavaScript
Raw Normal View History

import $ from 'jquery';
import {hideElem, showElem} from '../utils/dom.js';
import {GET} from '../modules/fetch.js';
export function initInstall() {
Fix various bugs for "install" page (#23194) ## TLDR * Fix the broken page / broken image problem when click "Install" * Close #20089 * Fix the Password Hash Algorithm display problem for #22942 * Close #23183 * Close #23184 ## Details ### The broken page / broken image problem when click "Install" (Redirect failed after install gitea #23184) Before: when click "install", all new requests will fail, because the server has been restarted. Users just see a broken page with broken images, sometimes the server is not ready but the user would have been redirect to "/user/login" page, then the users see a new broken page (connection refused or something wrong ...) After: only check InstallLock=true for necessary handlers, and sleep for a while before restarting the server, then the browser has enough time to load the "post-install" page. And there is a script to check whether "/user/login" is ready, the user will only be redirected to the login page when the server is ready. ### During new instance setup make 'Gitea Base URL' filled from window.location.origin #20089 If the "app_url" input contains `localhost` (the default value from config), use current window's location href as the `app_url` (aka ROOT_URL) ### Fix the Password Hash Algorithm display problem for "Provide the ability to set password hash algorithm parameters #22942" Before: the UI shows `pbkdf2$50000$50` <details> ![image](https://user-images.githubusercontent.com/2114189/221917143-e1e54798-1698-4fee-a18d-00c48081fc39.png) </details> After: the UI shows `pbkdf2` <details> ![image](https://user-images.githubusercontent.com/2114189/221916999-97a15be8-2ebb-4a01-bf93-dac18e354fcc.png) </details> ### GET data: net::ERR_INVALID_URL #23183 Cause by empty `data:` in `<link rel="manifest" href="data:{{.ManifestData}}">` --------- Co-authored-by: Jason Song <i@wolfogre.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
2023-03-04 02:12:02 +00:00
const $page = $('.page-content.install');
if ($page.length === 0) {
return;
}
Fix various bugs for "install" page (#23194) ## TLDR * Fix the broken page / broken image problem when click "Install" * Close #20089 * Fix the Password Hash Algorithm display problem for #22942 * Close #23183 * Close #23184 ## Details ### The broken page / broken image problem when click "Install" (Redirect failed after install gitea #23184) Before: when click "install", all new requests will fail, because the server has been restarted. Users just see a broken page with broken images, sometimes the server is not ready but the user would have been redirect to "/user/login" page, then the users see a new broken page (connection refused or something wrong ...) After: only check InstallLock=true for necessary handlers, and sleep for a while before restarting the server, then the browser has enough time to load the "post-install" page. And there is a script to check whether "/user/login" is ready, the user will only be redirected to the login page when the server is ready. ### During new instance setup make 'Gitea Base URL' filled from window.location.origin #20089 If the "app_url" input contains `localhost` (the default value from config), use current window's location href as the `app_url` (aka ROOT_URL) ### Fix the Password Hash Algorithm display problem for "Provide the ability to set password hash algorithm parameters #22942" Before: the UI shows `pbkdf2$50000$50` <details> ![image](https://user-images.githubusercontent.com/2114189/221917143-e1e54798-1698-4fee-a18d-00c48081fc39.png) </details> After: the UI shows `pbkdf2` <details> ![image](https://user-images.githubusercontent.com/2114189/221916999-97a15be8-2ebb-4a01-bf93-dac18e354fcc.png) </details> ### GET data: net::ERR_INVALID_URL #23183 Cause by empty `data:` in `<link rel="manifest" href="data:{{.ManifestData}}">` --------- Co-authored-by: Jason Song <i@wolfogre.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
2023-03-04 02:12:02 +00:00
if ($page.is('.post-install')) {
initPostInstall();
} else {
initPreInstall();
}
}
Fix various bugs for "install" page (#23194) ## TLDR * Fix the broken page / broken image problem when click "Install" * Close #20089 * Fix the Password Hash Algorithm display problem for #22942 * Close #23183 * Close #23184 ## Details ### The broken page / broken image problem when click "Install" (Redirect failed after install gitea #23184) Before: when click "install", all new requests will fail, because the server has been restarted. Users just see a broken page with broken images, sometimes the server is not ready but the user would have been redirect to "/user/login" page, then the users see a new broken page (connection refused or something wrong ...) After: only check InstallLock=true for necessary handlers, and sleep for a while before restarting the server, then the browser has enough time to load the "post-install" page. And there is a script to check whether "/user/login" is ready, the user will only be redirected to the login page when the server is ready. ### During new instance setup make 'Gitea Base URL' filled from window.location.origin #20089 If the "app_url" input contains `localhost` (the default value from config), use current window's location href as the `app_url` (aka ROOT_URL) ### Fix the Password Hash Algorithm display problem for "Provide the ability to set password hash algorithm parameters #22942" Before: the UI shows `pbkdf2$50000$50` <details> ![image](https://user-images.githubusercontent.com/2114189/221917143-e1e54798-1698-4fee-a18d-00c48081fc39.png) </details> After: the UI shows `pbkdf2` <details> ![image](https://user-images.githubusercontent.com/2114189/221916999-97a15be8-2ebb-4a01-bf93-dac18e354fcc.png) </details> ### GET data: net::ERR_INVALID_URL #23183 Cause by empty `data:` in `<link rel="manifest" href="data:{{.ManifestData}}">` --------- Co-authored-by: Jason Song <i@wolfogre.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
2023-03-04 02:12:02 +00:00
function initPreInstall() {
[BRANDING] Rebrand default config settings for new installs (#140) Replaces `Gitea` with `Forgejo` in the default config settings for new installs. This will not affect existing installs. Co-authored-by: Caesar Schinas <caesar@caesarschinas.com> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/140 Co-authored-by: Caesar Schinas <caesar@noreply.codeberg.org> Co-committed-by: Caesar Schinas <caesar@noreply.codeberg.org> (cherry picked from commit ca1319aa16128516e50dabdc8e8cadc23eb71d2f) (cherry picked from commit 52a4d238a0b5bbea28b28e55e35f28c51ecbb2de) (cherry picked from commit f63536538cfe4b010ebb5a6323f4b5e5b6ec7232) Conflicts: web_src/js/features/install.js (cherry picked from commit 861cc434e129f3fbd932ee36067c560e754dab9a) (cherry picked from commit 0e6ea60c802d6cfd95dea4aad5df96bb6e4bc7a5) (cherry picked from commit 0cbc0ec15d9d952b0ecfb68a36bf58cbae0c43dd) (cherry picked from commit 3cc19b0ae214ae163f23efa52ab0aa53eb7c935b) (cherry picked from commit 50fcb885fe2f87a27e6ff778cdd0c7cd97bbe9e9) (cherry picked from commit f6039d4df481fc58b8db3e863158665d24cac847) (cherry picked from commit 5ae5c6ba2deefe829f768900f5e1bbcbe9389e15) (cherry picked from commit f0b565e0ed7fe52f0264e92c49736b487b9bff8a) (cherry picked from commit adbd4d2015e8e2c4789849c84cfa4032acd40b7f) (cherry picked from commit d26c540ffdbfb7ec83412635576ab39653d1b531) (cherry picked from commit 6df6781b42ea126d029ba9e85485dbcb9bf6601d) (cherry picked from commit b6fb56e1c407195bedfe09f91ecb6537024d5189) (cherry picked from commit bb4f98a0ca7515aa6c44529df0573195f779a643) (cherry picked from commit 6779229f2732f6791aba3bd1ba51a338a88ca1f3) (cherry picked from commit c216c85aee552aa15e9d6316002ee9e170de64d7) (cherry picked from commit dff780bced1dc78ddd7fa4952766969ee528c538) (cherry picked from commit 4e036aa3b6d1bc5f2041c3b30ec289cb082fe824) (cherry picked from commit 8b3bc3e8a64edaba64cb759ea31248eea7307937) (cherry picked from commit 1e4d8523321efaf6c5febdd77ba5150effe5c1ac) (cherry picked from commit 07a15d18447bb03bb04001f1f65305670d1467ef) (cherry picked from commit fb44b3e10d685dd180f37678a3e2a64ee641f2b2) (cherry picked from commit b212d833190ce59230b3fc288c1aac5106cf33a0) (cherry picked from commit 5754971be5c37e97f3165878af3760117e40af01) (cherry picked from commit 0c43b4e82cab028fae1b709c549251d63a3ffc04) Conflicts: routers/install/install.go https://codeberg.org/forgejo/forgejo/pulls/1351 (cherry picked from commit 2e22a7208a0f149afc3794425c7b5b2b0181a939) (cherry picked from commit 676b0a8a48f99d751b677b9eca5b57238b5003a5) (cherry picked from commit bc4a8bf9bcb75e92b7802c477b1bb14a047344a6) (cherry picked from commit 5e09a4e174cc6d62b08fa718d0309275effadbd8) (cherry picked from commit 712c52a32a3b6ce9aafaefaf9e63729522d1e0c5) (cherry picked from commit ba3d93cc4a5dca5d0daef647fab557e0136925e2) (cherry picked from commit a5a0396abc512834ca7b0b247277e4d753a87659) (cherry picked from commit c1f389f0cb237dcce05db4ade342d48e260ae144) (cherry picked from commit 87d4d2da9faf9cacdd6f0441914c806efe4d1e36) (cherry picked from commit 89d7559054c8d99d1eb4bb151f3514cbb865e82f) (cherry picked from commit 7698cc0c8553d0135d41344ece12f18ad8fc15aa) (cherry picked from commit 69e24c60e131694ea65ba99eef29834f7b0e8365)
2022-12-19 20:01:46 +00:00
const defaultDbUser = 'forgejo';
const defaultDbName = 'forgejo';
const defaultDbHosts = {
mysql: '127.0.0.1:3306',
postgres: '127.0.0.1:5432',
mssql: '127.0.0.1:1433'
};
const $dbHost = $('#db_host');
const $dbUser = $('#db_user');
const $dbName = $('#db_name');
// Database type change detection.
$('#db_type').on('change', function () {
const dbType = $(this).val();
hideElem($('div[data-db-setting-for]'));
showElem($(`div[data-db-setting-for=${dbType}]`));
if (dbType !== 'sqlite3') {
// for most remote database servers
showElem($(`div[data-db-setting-for=common-host]`));
const lastDbHost = $dbHost.val();
const isDbHostDefault = !lastDbHost || Object.values(defaultDbHosts).includes(lastDbHost);
if (isDbHostDefault) {
$dbHost.val(defaultDbHosts[dbType] ?? '');
}
if (!$dbUser.val() && !$dbName.val()) {
$dbUser.val(defaultDbUser);
$dbName.val(defaultDbName);
}
} // else: for SQLite3, the default path is always prepared by backend code (setting)
}).trigger('change');
Fix various bugs for "install" page (#23194) ## TLDR * Fix the broken page / broken image problem when click "Install" * Close #20089 * Fix the Password Hash Algorithm display problem for #22942 * Close #23183 * Close #23184 ## Details ### The broken page / broken image problem when click "Install" (Redirect failed after install gitea #23184) Before: when click "install", all new requests will fail, because the server has been restarted. Users just see a broken page with broken images, sometimes the server is not ready but the user would have been redirect to "/user/login" page, then the users see a new broken page (connection refused or something wrong ...) After: only check InstallLock=true for necessary handlers, and sleep for a while before restarting the server, then the browser has enough time to load the "post-install" page. And there is a script to check whether "/user/login" is ready, the user will only be redirected to the login page when the server is ready. ### During new instance setup make 'Gitea Base URL' filled from window.location.origin #20089 If the "app_url" input contains `localhost` (the default value from config), use current window's location href as the `app_url` (aka ROOT_URL) ### Fix the Password Hash Algorithm display problem for "Provide the ability to set password hash algorithm parameters #22942" Before: the UI shows `pbkdf2$50000$50` <details> ![image](https://user-images.githubusercontent.com/2114189/221917143-e1e54798-1698-4fee-a18d-00c48081fc39.png) </details> After: the UI shows `pbkdf2` <details> ![image](https://user-images.githubusercontent.com/2114189/221916999-97a15be8-2ebb-4a01-bf93-dac18e354fcc.png) </details> ### GET data: net::ERR_INVALID_URL #23183 Cause by empty `data:` in `<link rel="manifest" href="data:{{.ManifestData}}">` --------- Co-authored-by: Jason Song <i@wolfogre.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
2023-03-04 02:12:02 +00:00
const $appUrl = $('#app_url');
const configAppUrl = $appUrl.val();
if (configAppUrl.includes('://localhost')) {
$appUrl.val(window.location.href);
}
const $domain = $('#domain');
const configDomain = $domain.val().trim();
if (configDomain === 'localhost') {
$domain.val(window.location.hostname);
}
// TODO: better handling of exclusive relations.
$('#offline-mode input').on('change', function () {
if ($(this).is(':checked')) {
$('#disable-gravatar').checkbox('check');
$('#federated-avatar-lookup').checkbox('uncheck');
}
});
$('#disable-gravatar input').on('change', function () {
if ($(this).is(':checked')) {
$('#federated-avatar-lookup').checkbox('uncheck');
} else {
$('#offline-mode').checkbox('uncheck');
}
});
$('#federated-avatar-lookup input').on('change', function () {
if ($(this).is(':checked')) {
$('#disable-gravatar').checkbox('uncheck');
$('#offline-mode').checkbox('uncheck');
}
});
$('#enable-openid-signin input').on('change', function () {
if ($(this).is(':checked')) {
if (!$('#disable-registration input').is(':checked')) {
$('#enable-openid-signup').checkbox('check');
}
} else {
$('#enable-openid-signup').checkbox('uncheck');
}
});
$('#disable-registration input').on('change', function () {
if ($(this).is(':checked')) {
$('#enable-captcha').checkbox('uncheck');
$('#enable-openid-signup').checkbox('uncheck');
} else {
$('#enable-openid-signup').checkbox('check');
}
});
$('#enable-captcha input').on('change', function () {
if ($(this).is(':checked')) {
$('#disable-registration').checkbox('uncheck');
}
});
}
Fix various bugs for "install" page (#23194) ## TLDR * Fix the broken page / broken image problem when click "Install" * Close #20089 * Fix the Password Hash Algorithm display problem for #22942 * Close #23183 * Close #23184 ## Details ### The broken page / broken image problem when click "Install" (Redirect failed after install gitea #23184) Before: when click "install", all new requests will fail, because the server has been restarted. Users just see a broken page with broken images, sometimes the server is not ready but the user would have been redirect to "/user/login" page, then the users see a new broken page (connection refused or something wrong ...) After: only check InstallLock=true for necessary handlers, and sleep for a while before restarting the server, then the browser has enough time to load the "post-install" page. And there is a script to check whether "/user/login" is ready, the user will only be redirected to the login page when the server is ready. ### During new instance setup make 'Gitea Base URL' filled from window.location.origin #20089 If the "app_url" input contains `localhost` (the default value from config), use current window's location href as the `app_url` (aka ROOT_URL) ### Fix the Password Hash Algorithm display problem for "Provide the ability to set password hash algorithm parameters #22942" Before: the UI shows `pbkdf2$50000$50` <details> ![image](https://user-images.githubusercontent.com/2114189/221917143-e1e54798-1698-4fee-a18d-00c48081fc39.png) </details> After: the UI shows `pbkdf2` <details> ![image](https://user-images.githubusercontent.com/2114189/221916999-97a15be8-2ebb-4a01-bf93-dac18e354fcc.png) </details> ### GET data: net::ERR_INVALID_URL #23183 Cause by empty `data:` in `<link rel="manifest" href="data:{{.ManifestData}}">` --------- Co-authored-by: Jason Song <i@wolfogre.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
2023-03-04 02:12:02 +00:00
function initPostInstall() {
const el = document.getElementById('goto-user-login');
if (!el) return;
const targetUrl = el.getAttribute('href');
let tid = setInterval(async () => {
try {
const resp = await GET(targetUrl);
Fix various bugs for "install" page (#23194) ## TLDR * Fix the broken page / broken image problem when click "Install" * Close #20089 * Fix the Password Hash Algorithm display problem for #22942 * Close #23183 * Close #23184 ## Details ### The broken page / broken image problem when click "Install" (Redirect failed after install gitea #23184) Before: when click "install", all new requests will fail, because the server has been restarted. Users just see a broken page with broken images, sometimes the server is not ready but the user would have been redirect to "/user/login" page, then the users see a new broken page (connection refused or something wrong ...) After: only check InstallLock=true for necessary handlers, and sleep for a while before restarting the server, then the browser has enough time to load the "post-install" page. And there is a script to check whether "/user/login" is ready, the user will only be redirected to the login page when the server is ready. ### During new instance setup make 'Gitea Base URL' filled from window.location.origin #20089 If the "app_url" input contains `localhost` (the default value from config), use current window's location href as the `app_url` (aka ROOT_URL) ### Fix the Password Hash Algorithm display problem for "Provide the ability to set password hash algorithm parameters #22942" Before: the UI shows `pbkdf2$50000$50` <details> ![image](https://user-images.githubusercontent.com/2114189/221917143-e1e54798-1698-4fee-a18d-00c48081fc39.png) </details> After: the UI shows `pbkdf2` <details> ![image](https://user-images.githubusercontent.com/2114189/221916999-97a15be8-2ebb-4a01-bf93-dac18e354fcc.png) </details> ### GET data: net::ERR_INVALID_URL #23183 Cause by empty `data:` in `<link rel="manifest" href="data:{{.ManifestData}}">` --------- Co-authored-by: Jason Song <i@wolfogre.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
2023-03-04 02:12:02 +00:00
if (tid && resp.status === 200) {
clearInterval(tid);
tid = null;
window.location.href = targetUrl;
}
} catch {}
}, 1000);
}