mirror of
https://github.com/go-gitea/gitea
synced 2024-11-30 12:17:56 +01:00
5e1bf3efe2
- Switched to plain JavaScript - Tested the repo migrate functionality and it works as before # Demo using JavaScript without jQuery ![action](https://github.com/go-gitea/gitea/assets/20454870/44ad134b-832e-44b8-8e77-7cc8603d95fe) --------- Signed-off-by: Yarden Shoham <git@yardenshoham.com> Co-authored-by: silverwind <me@silverwind.io>
63 lines
1.8 KiB
JavaScript
63 lines
1.8 KiB
JavaScript
import {hideElem, showElem} from '../utils/dom.js';
|
|
import {GET, POST} from '../modules/fetch.js';
|
|
|
|
const {appSubUrl} = window.config;
|
|
|
|
export function initRepoMigrationStatusChecker() {
|
|
const repoMigrating = document.getElementById('repo_migrating');
|
|
if (!repoMigrating) return;
|
|
|
|
document.getElementById('repo_migrating_retry').addEventListener('click', doMigrationRetry);
|
|
|
|
const task = repoMigrating.getAttribute('data-migrating-task-id');
|
|
|
|
// returns true if the refresh still needs to be called after a while
|
|
const refresh = async () => {
|
|
const res = await GET(`${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) {
|
|
document.getElementById('repo_migrating_progress_message').textContent = 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');
|
|
document.getElementById('repo_migrating_failed_error').textContent = 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 POST(e.target.getAttribute('data-migrating-task-retry-url'));
|
|
window.location.reload();
|
|
}
|