diff options
author | Daniel Baumann <daniel@debian.org> | 2024-10-18 20:33:49 +0200 |
---|---|---|
committer | Daniel Baumann <daniel@debian.org> | 2024-12-12 23:57:56 +0100 |
commit | e68b9d00a6e05b3a941f63ffb696f91e554ac5ec (patch) | |
tree | 97775d6c13b0f416af55314eb6a89ef792474615 /web_src/js/features/repo-migrate.js | |
parent | Initial commit. (diff) | |
download | forgejo-e68b9d00a6e05b3a941f63ffb696f91e554ac5ec.tar.xz forgejo-e68b9d00a6e05b3a941f63ffb696f91e554ac5ec.zip |
Adding upstream version 9.0.3.
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to 'web_src/js/features/repo-migrate.js')
-rw-r--r-- | web_src/js/features/repo-migrate.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/web_src/js/features/repo-migrate.js b/web_src/js/features/repo-migrate.js new file mode 100644 index 0000000..fc42ce8 --- /dev/null +++ b/web_src/js/features/repo-migrate.js @@ -0,0 +1,64 @@ +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.url.endsWith('/login')) return false; // stop refreshing if redirected to login + 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(); +} |