From 903662a2248dd41d280469492fb0b8fff5921248 Mon Sep 17 00:00:00 2001 From: BTMuli Date: Wed, 15 Apr 2026 19:36:31 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20=E5=88=A0=E9=99=A4=E6=97=A0?= =?UTF-8?q?=E7=94=A8=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/TGHttp.ts | 89 --------------------------------------------- 1 file changed, 89 deletions(-) delete mode 100644 src/utils/TGHttp.ts diff --git a/src/utils/TGHttp.ts b/src/utils/TGHttp.ts deleted file mode 100644 index 37328884..00000000 --- a/src/utils/TGHttp.ts +++ /dev/null @@ -1,89 +0,0 @@ -/** - * 封装HTTP请求 - * @since Beta v0.10.0 - * @deprecated 请使用 TGHttps - */ - -import { type ClientOptions, fetch } from "@tauri-apps/plugin-http"; - -import TGLogger from "./TGLogger.js"; - -/** - * 请求参数 - * @since Beta v0.10.0 - * @deprecated 请使用 TGHttpsConfig 类型 - */ -type TGHttpParams = { - /** 请求方法 */ - method: "GET" | "POST"; - /** 请求头 */ - headers?: Record; - /** 请求参数 */ - query?: Record; - /** 请求体 */ - body?: string; - /** 是否是Blob */ - isBlob?: boolean; -}; - -/** - * 发送请求 - * @since Beta v0.10.0 - * @deprecated 请使用 TGHttps.get() 或 TGHttps.post() 替代 - * @param url - 请求地址 - * @param options - 请求参数 - * @returns 请求结果 - */ -async function TGHttp(url: string, options: TGHttpParams): Promise; -async function TGHttp( - url: string, - options: TGHttpParams, - fullResponse: true, -): Promise<{ data: Promise; resp: Response }>; -async function TGHttp( - url: string, - options: TGHttpParams, - fullResponse?: true, -): Promise; resp: Response }> { - const httpHeaders = new Headers(); - if (options.headers) { - for (const key in options.headers) httpHeaders.append(key, options.headers[key]); - } - const fetchOptions: RequestInit & ClientOptions = { - method: options.method, - headers: httpHeaders, - }; - if (options.body) fetchOptions.body = options.body; - if (options.query) { - const query = new URLSearchParams(options.query).toString(); - url += `?${query}`; - } - if (options.isBlob) { - console.debug(`Fetch Blob: ${url}`); - } else { - console.debug(`Fetch URL: ${url}`); - console.debug(options); - } - return await fetch(url, fetchOptions) - .then(async (res) => { - if (res.ok) { - const data = options.isBlob ? await res.arrayBuffer() : await res.json(); - if (fullResponse) return { data, resp: res }; - return data; - } - await TGLogger.Error(`Fetch URL: ${url} ERROR: ${res.status} ${res.statusText}`); - throw new Error(await res.text(), { cause: `${res.status} ${res.statusText}` }); - }) - .catch(async (err) => { - if (err instanceof Error) { - console.error(err.message); - } else if (typeof err === "object") { - await TGLogger.Error(`Error: ${JSON.stringify(err)}`); - } else { - await TGLogger.Error(`Error: ${err}`); - } - return err; - }); -} - -export default TGHttp;