From ae8e8f055e9edfe258e641df8752a070ffdd6823 Mon Sep 17 00:00:00 2001 From: silverwind Date: Tue, 19 Sep 2023 02:50:30 +0200 Subject: Use fetch helpers instead of fetch (#27026) WIP because: - [x] Some calls set a `content-type` but send no body, can likely remove the header - [x] Need to check whether `charset=utf-8` has any significance on the webauthn calls, I assume not as it is the default for json content. - [x] Maybe `no-restricted-globals` is better for eslint, but will require a lot of duplication in the yaml or moving eslint config to a `.js` extension. - [x] Maybe export `request` as `fetch`, shadowing the global. --- web_src/js/features/repo-migrate.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'web_src/js/features/repo-migrate.js') diff --git a/web_src/js/features/repo-migrate.js b/web_src/js/features/repo-migrate.js index de9f7b023c..cae28fdd1b 100644 --- a/web_src/js/features/repo-migrate.js +++ b/web_src/js/features/repo-migrate.js @@ -1,7 +1,8 @@ import $ from 'jquery'; import {hideElem, showElem} from '../utils/dom.js'; +import {GET, POST} from '../modules/fetch.js'; -const {appSubUrl, csrfToken} = window.config; +const {appSubUrl} = window.config; export function initRepoMigrationStatusChecker() { const $repoMigrating = $('#repo_migrating'); @@ -13,7 +14,7 @@ export function initRepoMigrationStatusChecker() { // returns true if the refresh still need to be called after a while const refresh = async () => { - const res = await fetch(`${appSubUrl}/user/task/${task}`); + 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(); @@ -58,12 +59,6 @@ export function initRepoMigrationStatusChecker() { } 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', - }, - }); + await POST($(e.target).attr('data-migrating-task-retry-url')); window.location.reload(); } -- cgit v1.2.3