From 452f821d0675235b3c8c2c3cbb43146b7a934978 Mon Sep 17 00:00:00 2001 From: xion Date: Tue, 3 Jun 2025 21:12:33 +0800 Subject: [PATCH] fix: fix adapter --- package.json | 2 +- readme.md | 22 +++++++++++++++++++--- src/adapter.ts | 8 ++++---- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index ac34e97..76d6132 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/query", - "version": "0.0.24", + "version": "0.0.25", "main": "dist/index.js", "module": "dist/index.js", "types": "dist/index.d.ts", diff --git a/readme.md b/readme.md index ca28a15..6db34aa 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ # query -对应的 fetch 内容的一部分功能的封装。 +对 fetch 功能的的一部分功能的封装。主要处理header的token的提交和response中的处理json。 主要目的:请求路径默认`/api/router`,使用`post`,`post`的数据分流使用`path`和`key`. @@ -8,7 +8,6 @@ ## query - ```ts const query = new Query(); const res = await query.post({ @@ -35,4 +34,21 @@ type Data = { type DataOpts = Partial & { beforeRequest?: Fn; }; -``` \ No newline at end of file +``` + +## 适配的@kevisual/router的代码 + +```ts +import { App } from '@kevisual/router'; +const app = new App(); + +app + .route({ + path: 'demo', + key: '1', + }) + .define(async (ctx) => { + ctx.body = 234; + }) + .addTo(app); +``` diff --git a/src/adapter.ts b/src/adapter.ts index 063ec22..1ae44ab 100644 --- a/src/adapter.ts +++ b/src/adapter.ts @@ -50,21 +50,21 @@ export const adapter = async (opts: AdapterOpts, overloadOpts?: RequestInit) => ...overloadOpts, body: isGet ? undefined : JSON.stringify(opts.body), }) - .then((response) => { + .then(async (response) => { // 获取 Content-Type 头部信息 const contentType = response.headers.get('Content-Type'); if (isBlob) { - return response.blob(); // 直接返回 Blob 对象 + return await response.blob(); // 直接返回 Blob 对象 } const isJson = contentType && contentType.includes('application/json'); // 判断返回的数据类型 if (isJson) { - return response.json(); // 解析为 JSON + return await response.json(); // 解析为 JSON } else if (isTextForContentType(contentType)) { return { code: 200, status: response.status, - data: response.text(), // 直接返回文本内容 + data: await response.text(), // 直接返回文本内容 }; } else { return response;