mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-13 09:28:14 +08:00
♻️ 全面整理重构
This commit is contained in:
@@ -45,17 +45,10 @@ async function TGHttp<T>(
|
||||
): Promise<T | { data: Promise<T>; resp: Response }> {
|
||||
const httpHeaders = new Headers();
|
||||
if (options.headers) {
|
||||
for (const key in options.headers) {
|
||||
httpHeaders.append(key, options.headers[key]);
|
||||
}
|
||||
}
|
||||
const fetchOptions: RequestInit = {
|
||||
method: options.method,
|
||||
headers: httpHeaders,
|
||||
};
|
||||
if (options.body) {
|
||||
fetchOptions.body = options.body;
|
||||
for (const key in options.headers) httpHeaders.append(key, options.headers[key]);
|
||||
}
|
||||
const fetchOptions: RequestInit = { method: options.method, headers: httpHeaders };
|
||||
if (options.body) fetchOptions.body = options.body;
|
||||
if (options.query) {
|
||||
const query = new URLSearchParams(options.query).toString();
|
||||
url += `?${query}`;
|
||||
@@ -66,9 +59,7 @@ async function TGHttp<T>(
|
||||
.then((res) => {
|
||||
if (res.ok) {
|
||||
const data = options.isBlob ? res.arrayBuffer() : res.json();
|
||||
if (fullResponse) {
|
||||
return { data, resp: res };
|
||||
}
|
||||
if (fullResponse) return { data, resp: res };
|
||||
return data;
|
||||
}
|
||||
throw new Error(`HTTP error! status: ${res.status}`);
|
||||
|
||||
Reference in New Issue
Block a user