Files
firefly-iii/public/v1/js/ff/install/index.js

207 lines
6.6 KiB
JavaScript
Raw Normal View History

2018-03-10 07:17:05 +01:00
/*
* index.js
2020-02-16 13:59:41 +01:00
* Copyright (c) 2019 james@firefly-iii.org
2018-03-10 07:17:05 +01:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
2018-03-10 07:17:05 +01:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
2018-03-10 07:17:05 +01:00
*
* This program is distributed in the hope that it will be useful,
2018-03-10 07:17:05 +01:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
2018-03-10 07:17:05 +01:00
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2018-03-10 07:17:05 +01:00
*/
2024-03-31 19:31:52 +02:00
document.addEventListener("DOMContentLoaded", (event) => {
2023-04-15 10:14:14 +02:00
console.log('Starting...');
startRunningCommands(0);
2018-03-10 07:17:05 +01:00
});
2023-04-15 10:14:14 +02:00
function startRunningCommands(index) {
console.log('Now in startRunningCommands with index' + index);
2019-03-30 11:03:39 +01:00
if (0 === index) {
2024-03-31 19:31:52 +02:00
document.querySelector('#status-box').innerHTML = '<span class="fa fa-spin fa-spinner"></span> Running first command...';
2019-03-30 11:03:39 +01:00
}
runCommand(index);
}
function runCommand(index) {
2023-04-15 10:14:14 +02:00
console.log('Now in runCommand(' + index + '): ' + runCommandUrl);
2024-03-31 19:31:52 +02:00
fetch(runCommandUrl, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({_token: token, index: parseInt(index)}),
})
.then(response => response.json())
.then(response => {
if (response.error === false) {
index++;
if (response.hasNextCommand) {
// inform user
document.querySelector('#status-box').innerHTML = '<span class="fa fa-spin fa-spinner"></span> Just executed ' + response.previous + '...';
console.log('Will call next command.');
runCommand(index);
} else {
completeDone();
console.log('Finished!');
}
2019-03-30 11:03:39 +01:00
} else {
2024-03-31 19:31:52 +02:00
displaySoftFail(response.errorMessage);
console.error(response);
2019-03-30 11:03:39 +01:00
}
2024-03-31 19:31:52 +02:00
})
2019-03-30 11:03:39 +01:00
}
2018-03-10 07:17:05 +01:00
function startMigration() {
2023-04-15 10:14:14 +02:00
console.log('Now in startMigration');
2024-03-31 19:31:52 +02:00
fetch(migrateUrl, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({_token: token}),
})
.then(response => response.json())
.then(response => {
if (response.error === false) {
2019-02-04 20:35:46 +01:00
// move to decrypt routine.
startDecryption();
} else {
2024-03-31 19:31:52 +02:00
displaySoftFail(response.message);
2019-02-04 20:35:46 +01:00
}
}).fail(function () {
2024-03-31 19:31:52 +02:00
document.querySelector('#status-box').innerHTML = '<span class="fa fa-warning"></span> Migration failed! See log files :(';
2019-02-04 20:35:46 +01:00
});
}
function startDecryption() {
2023-04-15 10:14:14 +02:00
console.log('Now in startDecryption');
2024-03-31 19:31:52 +02:00
document.querySelector('#status-box').innerHTML = '<span class="fa fa-spin fa-spinner"></span> Setting up DB #2...';
fetch(decryptUrl, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({_token: token}),
})
.then(response => response.json())
.then(response => {
if (response.error === false) {
2019-02-04 20:35:46 +01:00
// move to decrypt routine.
2018-04-06 13:36:36 +02:00
startPassport();
} else {
displaySoftFail(data.message);
}
2018-03-10 07:17:05 +01:00
}).fail(function () {
2024-03-31 19:31:52 +02:00
document.querySelector('#status-box').innerHTML = '<span class="fa fa-warning"></span> Migration failed! See log files :(';
2018-03-10 07:17:05 +01:00
});
}
/**
*
*/
function startPassport() {
2024-03-31 19:31:52 +02:00
document.querySelector('#status-box').innerHTML = '<span class="fa fa-spin fa-spinner"></span> Setting up OAuth2...';
fetch(keysUrl, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({_token: token}),
})
.then(response => response.json())
.then(response => {
if (response.error === false) {
2018-04-06 13:36:36 +02:00
startUpgrade();
} else {
displaySoftFail(data.message);
}
2018-03-10 07:17:05 +01:00
}).fail(function () {
2024-03-31 19:31:52 +02:00
document.querySelector('#status-box').innerHTML = '<span class="fa fa-warning"></span> OAuth2 failed! See log files :(';
2018-03-10 07:17:05 +01:00
});
}
/**
*
*/
function startUpgrade() {
2024-03-31 19:31:52 +02:00
document.querySelector('#status-box').innerHTML = '<span class="fa fa-spin fa-spinner"></span> Upgrading database...';
fetch(upgradeUrl, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({_token: token}),
})
.then(response => response.json())
.then(response => {
if (response.error === false) {
2018-04-06 13:36:36 +02:00
startVerify();
} else {
displaySoftFail(data.message);
}
2018-03-10 07:17:05 +01:00
}).fail(function () {
2024-03-31 19:31:52 +02:00
document.querySelector('#status-box').innerHTML = '<span class="fa fa-warning"></span> Upgrade failed! See log files :(';
2018-03-10 07:17:05 +01:00
});
}
2018-03-11 18:46:18 +01:00
/**
*
*/
function startVerify() {
2024-03-31 19:31:52 +02:00
document.querySelector('#status-box').innerHTML = '<span class="fa fa-spin fa-spinner"></span> Verify database integrity...';
fetch(veifyUrl, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({_token: token}),
})
.then(response => response.json())
.then(response => {
if (response.error === false) {
2018-04-06 13:36:36 +02:00
completeDone();
} else {
displaySoftFail(data.message);
}
2018-03-11 18:46:18 +01:00
}).fail(function () {
2024-03-31 19:31:52 +02:00
document.querySelector('#status-box').innerHTML = '<span class="fa fa-warning"></span> Verification failed! See log files :(';
2018-03-11 18:46:18 +01:00
});
}
2018-03-10 07:17:05 +01:00
/**
*
*/
function completeDone() {
2024-03-31 19:31:52 +02:00
document.querySelector('#status-box').innerHTML = '<span class="fa fa-thumbs-up"></span> Installation + upgrade complete! Wait to be redirected...';
2018-03-10 07:17:05 +01:00
setTimeout(function () {
2022-04-12 18:19:30 +02:00
window.location = homeUrl;
2018-03-10 07:17:05 +01:00
}, 3000);
2018-04-06 13:36:36 +02:00
}
function displaySoftFail(message) {
2024-03-31 19:31:52 +02:00
document.querySelector('#status-box').innerHTML = '<span class="fa fa-warning"></span> ' + message + '<br /><br />Please read the ' +
'<a href="https://docs.firefly-iii.org/">' +
'documentation</a> about this, and upgrade by hand.';
2023-04-15 10:14:14 +02:00
}