code.gitea.io/gitea@v1.21.7/web_src/js/features/repo-migrate.js (about) 1 import $ from 'jquery'; 2 import {hideElem, showElem} from '../utils/dom.js'; 3 import {GET, POST} from '../modules/fetch.js'; 4 5 const {appSubUrl} = window.config; 6 7 export function initRepoMigrationStatusChecker() { 8 const $repoMigrating = $('#repo_migrating'); 9 if (!$repoMigrating.length) return; 10 11 $('#repo_migrating_retry').on('click', doMigrationRetry); 12 13 const task = $repoMigrating.attr('data-migrating-task-id'); 14 15 // returns true if the refresh still need to be called after a while 16 const refresh = async () => { 17 const res = await GET(`${appSubUrl}/user/task/${task}`); 18 if (res.status !== 200) return true; // continue to refresh if network error occurs 19 20 const data = await res.json(); 21 22 // for all status 23 if (data.message) { 24 $('#repo_migrating_progress_message').text(data.message); 25 } 26 27 // TaskStatusFinished 28 if (data.status === 4) { 29 window.location.reload(); 30 return false; 31 } 32 33 // TaskStatusFailed 34 if (data.status === 3) { 35 hideElem('#repo_migrating_progress'); 36 hideElem('#repo_migrating'); 37 showElem('#repo_migrating_retry'); 38 showElem('#repo_migrating_failed'); 39 showElem('#repo_migrating_failed_image'); 40 $('#repo_migrating_failed_error').text(data.message); 41 return false; 42 } 43 44 return true; // continue to refresh 45 }; 46 47 const syncTaskStatus = async () => { 48 let doNextRefresh = true; 49 try { 50 doNextRefresh = await refresh(); 51 } finally { 52 if (doNextRefresh) { 53 setTimeout(syncTaskStatus, 2000); 54 } 55 } 56 }; 57 58 syncTaskStatus(); // no await 59 } 60 61 async function doMigrationRetry(e) { 62 await POST($(e.target).attr('data-migrating-task-retry-url')); 63 window.location.reload(); 64 }