mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-30 05:06:21 +01:00
f6e029e6c7
Replace #12917 Close #24601 Close #12845 ![image](https://github.com/go-gitea/gitea/assets/2114189/39378118-064d-40fb-8396-4579ebf33917) ![image](https://github.com/go-gitea/gitea/assets/2114189/faf37418-191c-46a6-90a8-353141e00e2d) ![image](https://github.com/go-gitea/gitea/assets/2114189/fdc8ee4d-125f-4737-9990-89bcdf9eb388) ![image](https://github.com/go-gitea/gitea/assets/2114189/9a3bd2c2-fe20-4011-81f0-990ed869d139) --------- Co-authored-by: Yarden Shoham <git@yardenshoham.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Giteabot <teabot@gitea.io>
55 lines
1.4 KiB
JavaScript
55 lines
1.4 KiB
JavaScript
import $ from 'jquery';
|
|
import {hideElem, showElem} from '../utils/dom.js';
|
|
|
|
const {appSubUrl} = window.config;
|
|
|
|
export function initRepoMigrationStatusChecker() {
|
|
const $repoMigrating = $('#repo_migrating');
|
|
if (!$repoMigrating.length) return;
|
|
|
|
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_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
|
|
}
|