2022-01-28 16:00:11 -05:00
|
|
|
import $ from 'jquery';
|
2023-02-18 23:06:14 -05:00
|
|
|
import {hideElem, showElem} from '../utils/dom.js';
|
2023-09-18 20:50:30 -04:00
|
|
|
import {GET, POST} from '../modules/fetch.js';
|
2022-01-28 16:00:11 -05:00
|
|
|
|
2023-09-18 20:50:30 -04:00
|
|
|
const {appSubUrl} = window.config;
|
2021-10-16 13:28:04 -04:00
|
|
|
|
|
|
|
export function initRepoMigrationStatusChecker() {
|
2023-05-11 04:25:46 -04:00
|
|
|
const $repoMigrating = $('#repo_migrating');
|
|
|
|
if (!$repoMigrating.length) return;
|
|
|
|
|
2023-08-03 22:21:32 -04:00
|
|
|
$('#repo_migrating_retry').on('click', doMigrationRetry);
|
|
|
|
|
2023-05-11 04:25:46 -04:00
|
|
|
const task = $repoMigrating.attr('data-migrating-task-id');
|
|
|
|
|
|
|
|
// returns true if the refresh still need to be called after a while
|
|
|
|
const refresh = async () => {
|
2023-09-18 20:50:30 -04:00
|
|
|
const res = await GET(`${appSubUrl}/user/task/${task}`);
|
2023-05-11 04:25:46 -04:00
|
|
|
if (res.status !== 200) return true; // continue to refresh if network error occurs
|
|
|
|
|
|
|
|
const data = await res.json();
|
|
|
|
|
|
|
|
// for all status
|
|
|
|
if (data.message) {
|
|
|
|
$('#repo_migrating_progress_message').text(data.message);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TaskStatusFinished
|
|
|
|
if (data.status === 4) {
|
|
|
|
window.location.reload();
|
|
|
|
return false;
|
2021-10-16 13:28:04 -04:00
|
|
|
}
|
2023-05-11 04:25:46 -04:00
|
|
|
|
|
|
|
// TaskStatusFailed
|
|
|
|
if (data.status === 3) {
|
|
|
|
hideElem('#repo_migrating_progress');
|
|
|
|
hideElem('#repo_migrating');
|
2023-08-03 22:21:32 -04:00
|
|
|
showElem('#repo_migrating_retry');
|
2023-05-11 04:25:46 -04:00
|
|
|
showElem('#repo_migrating_failed');
|
|
|
|
showElem('#repo_migrating_failed_image');
|
|
|
|
$('#repo_migrating_failed_error').text(data.message);
|
|
|
|
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 13:28:04 -04:00
|
|
|
}
|
2023-05-11 04:25:46 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
syncTaskStatus(); // no await
|
2021-10-16 13:28:04 -04:00
|
|
|
}
|
2023-08-03 22:21:32 -04:00
|
|
|
|
|
|
|
async function doMigrationRetry(e) {
|
2023-09-18 20:50:30 -04:00
|
|
|
await POST($(e.target).attr('data-migrating-task-retry-url'));
|
2023-08-03 22:21:32 -04:00
|
|
|
window.location.reload();
|
|
|
|
}
|