mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-26 20:27:03 +01:00
865d2221c0
fixed #26156 * Added a retry button in the frontend (only displayed when the status is abnormal) * After clicking Retry, the backend adds the task back to the task queue ![7UJDNM671RI})EA8~~XPL39](https://github.com/go-gitea/gitea/assets/3371163/e088fd63-5dcc-4bc6-8849-7db3086511b7) ![T83F1WL9)VGHR@MB956$VT9](https://github.com/go-gitea/gitea/assets/3371163/744425bb-dde1-4315-be2e-5c99ac3a44d4) --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
69 lines
1.8 KiB
JavaScript
69 lines
1.8 KiB
JavaScript
import $ from 'jquery';
|
|
import {hideElem, showElem} from '../utils/dom.js';
|
|
|
|
const {appSubUrl, csrfToken} = window.config;
|
|
|
|
export function initRepoMigrationStatusChecker() {
|
|
const $repoMigrating = $('#repo_migrating');
|
|
if (!$repoMigrating.length) return;
|
|
|
|
$('#repo_migrating_retry').on('click', doMigrationRetry);
|
|
|
|
const task = $repoMigrating.attr('data-migrating-task-id');
|
|
|
|
// returns true if the refresh still need to be called after a while
|
|
const refresh = async () => {
|
|
const res = await fetch(`${appSubUrl}/user/task/${task}`);
|
|
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;
|
|
}
|
|
|
|
// TaskStatusFailed
|
|
if (data.status === 3) {
|
|
hideElem('#repo_migrating_progress');
|
|
hideElem('#repo_migrating');
|
|
showElem('#repo_migrating_retry');
|
|
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);
|
|
}
|
|
}
|
|
};
|
|
|
|
syncTaskStatus(); // no await
|
|
}
|
|
|
|
async function doMigrationRetry(e) {
|
|
await fetch($(e.target).attr('data-migrating-task-retry-url'), {
|
|
method: 'post',
|
|
headers: {
|
|
'X-Csrf-Token': csrfToken,
|
|
'Content-Type': 'application/json',
|
|
},
|
|
});
|
|
window.location.reload();
|
|
}
|