2023-02-19 09:36:14 +05:30
|
|
|
import {hideElem, showElem} from '../utils/dom.js';
|
2023-09-19 06:20:30 +05:30
|
|
|
import {GET, POST} from '../modules/fetch.js';
|
2022-01-29 02:30:11 +05:30
|
|
|
|
2023-09-19 06:20:30 +05:30
|
|
|
const {appSubUrl} = window.config;
|
2021-10-16 22:58:04 +05:30
|
|
|
|
|
|
|
export function initRepoMigrationStatusChecker() {
|
2024-02-18 01:37:47 +05:30
|
|
|
const repoMigrating = document.getElementById('repo_migrating');
|
|
|
|
if (!repoMigrating) return;
|
2023-05-11 13:55:46 +05:30
|
|
|
|
2024-02-18 01:37:47 +05:30
|
|
|
document.getElementById('repo_migrating_retry').addEventListener('click', doMigrationRetry);
|
2023-08-04 07:51:32 +05:30
|
|
|
|
2024-02-18 01:37:47 +05:30
|
|
|
const task = repoMigrating.getAttribute('data-migrating-task-id');
|
2023-05-11 13:55:46 +05:30
|
|
|
|
2024-02-18 01:37:47 +05:30
|
|
|
// returns true if the refresh still needs to be called after a while
|
2023-05-11 13:55:46 +05:30
|
|
|
const refresh = async () => {
|
2023-09-19 06:20:30 +05:30
|
|
|
const res = await GET(`${appSubUrl}/user/task/${task}`);
|
2023-05-11 13:55:46 +05:30
|
|
|
if (res.status !== 200) return true; // continue to refresh if network error occurs
|
|
|
|
|
|
|
|
const data = await res.json();
|
|
|
|
|
|
|
|
// for all status
|
|
|
|
if (data.message) {
|
2024-02-18 01:37:47 +05:30
|
|
|
document.getElementById('repo_migrating_progress_message').textContent = data.message;
|
2023-05-11 13:55:46 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
// TaskStatusFinished
|
|
|
|
if (data.status === 4) {
|
|
|
|
window.location.reload();
|
|
|
|
return false;
|
2021-10-16 22:58:04 +05:30
|
|
|
}
|
2023-05-11 13:55:46 +05:30
|
|
|
|
|
|
|
// TaskStatusFailed
|
|
|
|
if (data.status === 3) {
|
|
|
|
hideElem('#repo_migrating_progress');
|
|
|
|
hideElem('#repo_migrating');
|
2023-08-04 07:51:32 +05:30
|
|
|
showElem('#repo_migrating_retry');
|
2023-05-11 13:55:46 +05:30
|
|
|
showElem('#repo_migrating_failed');
|
|
|
|
showElem('#repo_migrating_failed_image');
|
2024-02-18 01:37:47 +05:30
|
|
|
document.getElementById('repo_migrating_failed_error').textContent = data.message;
|
2023-05-11 13:55:46 +05:30
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true; // continue to refresh
|
|
|
|
};
|
|
|
|
|
|
|
|
const syncTaskStatus = async () => {
|
|
|
|
let doNextRefresh = true;
|
|
|
|
try {
|
|
|
|
doNextRefresh = await refresh();
|
|
|
|
} finally {
|
|
|
|
if (doNextRefresh) {
|
|
|
|
setTimeout(syncTaskStatus, 2000);
|
2021-10-16 22:58:04 +05:30
|
|
|
}
|
2023-05-11 13:55:46 +05:30
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
syncTaskStatus(); // no await
|
2021-10-16 22:58:04 +05:30
|
|
|
}
|
2023-08-04 07:51:32 +05:30
|
|
|
|
|
|
|
async function doMigrationRetry(e) {
|
2024-02-18 01:37:47 +05:30
|
|
|
await POST(e.target.getAttribute('data-migrating-task-retry-url'));
|
2023-08-04 07:51:32 +05:30
|
|
|
window.location.reload();
|
|
|
|
}
|