diff options
author | silverwind <me@silverwind.io> | 2023-09-19 02:50:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-19 00:50:30 +0000 |
commit | ae8e8f055e9edfe258e641df8752a070ffdd6823 (patch) | |
tree | 1181f5dec6a7e9cfff020aa08d073582cfcc5e43 /web_src/js/features/comp | |
parent | 8099238618f6573f1eb5cfeeb0902b641e7121ab (diff) | |
download | gitea-ae8e8f055e9edfe258e641df8752a070ffdd6823.tar.gz gitea-ae8e8f055e9edfe258e641df8752a070ffdd6823.zip |
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.
Diffstat (limited to 'web_src/js/features/comp')
-rw-r--r-- | web_src/js/features/comp/ImagePaste.js | 9 | ||||
-rw-r--r-- | web_src/js/features/comp/ReactionSelector.js | 14 |
2 files changed, 5 insertions, 18 deletions
diff --git a/web_src/js/features/comp/ImagePaste.js b/web_src/js/features/comp/ImagePaste.js index dc335495a3..cae42f3d5f 100644 --- a/web_src/js/features/comp/ImagePaste.js +++ b/web_src/js/features/comp/ImagePaste.js @@ -1,16 +1,11 @@ import $ from 'jquery'; - -const {csrfToken} = window.config; +import {POST} from '../../modules/fetch.js'; async function uploadFile(file, uploadUrl) { const formData = new FormData(); formData.append('file', file, file.name); - const res = await fetch(uploadUrl, { - method: 'POST', - headers: {'X-Csrf-Token': csrfToken}, - body: formData, - }); + const res = await POST(uploadUrl, {data: formData}); return await res.json(); } diff --git a/web_src/js/features/comp/ReactionSelector.js b/web_src/js/features/comp/ReactionSelector.js index 336634a582..76834f8844 100644 --- a/web_src/js/features/comp/ReactionSelector.js +++ b/web_src/js/features/comp/ReactionSelector.js @@ -1,6 +1,5 @@ import $ from 'jquery'; - -const {csrfToken} = window.config; +import {POST} from '../../modules/fetch.js'; export function initCompReactionSelector($parent) { $parent.find(`.select-reaction .item.reaction, .comment-reaction-button`).on('click', async function (e) { @@ -12,15 +11,8 @@ export function initCompReactionSelector($parent) { const reactionContent = $(this).attr('data-reaction-content'); const hasReacted = $(this).closest('.ui.segment.reactions').find(`a[data-reaction-content="${reactionContent}"]`).attr('data-has-reacted') === 'true'; - const res = await fetch(`${actionUrl}/${hasReacted ? 'unreact' : 'react'}`, { - method: 'POST', - headers: { - 'content-type': 'application/x-www-form-urlencoded', - }, - body: new URLSearchParams({ - _csrf: csrfToken, - content: reactionContent, - }), + const res = await POST(`${actionUrl}/${hasReacted ? 'unreact' : 'react'}`, { + data: new URLSearchParams({content: reactionContent}), }); const data = await res.json(); |