mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-08 14:34:49 +09:00
Refactor htmx and fetch-action related code (#37186)
This is the first step (the hardest part): * repo file list last commit message lazy load * admin server status monitor * watch/unwatch (normal page, watchers page) * star/unstar (normal page, watchers page) * project view, delete column * workflow dispatch, switch the branch * commit page: load branches and tags referencing this commit The legacy "data-redirect" attribute is removed, it only makes the page reload (sometimes using an incorrect link). Also did cleanup for some devtest pages.
This commit is contained in:
@@ -2,7 +2,7 @@ import {isObject} from '../utils.ts';
|
||||
import type {RequestOpts} from '../types.ts';
|
||||
|
||||
// fetch wrapper, use below method name functions and the `data` option to pass in data
|
||||
// which will automatically set an appropriate headers. For json content, only object
|
||||
// which will automatically set an appropriate headers. For JSON content, only object
|
||||
// and array types are currently supported.
|
||||
export function request(url: string, {method = 'GET', data, headers = {}, ...other}: RequestOpts = {}): Promise<Response> {
|
||||
let body: string | FormData | URLSearchParams | undefined;
|
||||
@@ -14,17 +14,13 @@ export function request(url: string, {method = 'GET', data, headers = {}, ...oth
|
||||
body = JSON.stringify(data);
|
||||
}
|
||||
|
||||
const headersMerged = new Headers({
|
||||
...(contentType && {'content-type': contentType}),
|
||||
});
|
||||
|
||||
for (const [name, value] of Object.entries(headers)) {
|
||||
headersMerged.set(name, value);
|
||||
headers = new Headers(headers);
|
||||
if (!headers.has('content-type') && contentType) {
|
||||
headers.set('content-type', contentType);
|
||||
}
|
||||
|
||||
return fetch(url, { // eslint-disable-line no-restricted-globals
|
||||
method,
|
||||
headers: headersMerged,
|
||||
headers,
|
||||
...other,
|
||||
...(body && {body}),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user