mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-26 12:27:06 +00:00 
			
		
		
		
	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.
This commit is contained in:
		| @@ -11,6 +11,7 @@ import {htmlEscape} from 'escape-goat'; | ||||
| import {showTemporaryTooltip} from '../modules/tippy.js'; | ||||
| import {confirmModal} from './comp/ConfirmModal.js'; | ||||
| import {showErrorToast} from '../modules/toast.js'; | ||||
| import {request} from '../modules/fetch.js'; | ||||
|  | ||||
| const {appUrl, appSubUrl, csrfToken, i18n} = window.config; | ||||
|  | ||||
| @@ -81,7 +82,7 @@ function fetchActionDoRedirect(redirect) { | ||||
|  | ||||
| async function fetchActionDoRequest(actionElem, url, opt) { | ||||
|   try { | ||||
|     const resp = await fetch(url, opt); | ||||
|     const resp = await request(url, opt); | ||||
|     if (resp.status === 200) { | ||||
|       let {redirect} = await resp.json(); | ||||
|       redirect = redirect || actionElem.getAttribute('data-redirect'); | ||||
| @@ -127,7 +128,7 @@ async function formFetchAction(e) { | ||||
|   } | ||||
|  | ||||
|   let reqUrl = formActionUrl; | ||||
|   const reqOpt = {method: formMethod.toUpperCase(), headers: {'X-Csrf-Token': csrfToken}}; | ||||
|   const reqOpt = {method: formMethod.toUpperCase()}; | ||||
|   if (formMethod.toLowerCase() === 'get') { | ||||
|     const params = new URLSearchParams(); | ||||
|     for (const [key, value] of formData) { | ||||
| @@ -264,7 +265,7 @@ async function linkAction(e) { | ||||
|   const url = el.getAttribute('data-url'); | ||||
|   const doRequest = async () => { | ||||
|     el.disabled = true; | ||||
|     await fetchActionDoRequest(el, url, {method: 'POST', headers: {'X-Csrf-Token': csrfToken}}); | ||||
|     await fetchActionDoRequest(el, url, {method: 'POST'}); | ||||
|     el.disabled = false; | ||||
|   }; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 silverwind
					silverwind