mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08: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:
		@@ -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();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user