From 2a2c01ff7371b492f5aafe1da39535f3ea899dde Mon Sep 17 00:00:00 2001 From: abearxiong Date: Thu, 12 Mar 2026 01:36:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E8=87=B3=200.0.64=EF=BC=8C=E6=B7=BB=E5=8A=A0=20getUrl=20?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E4=BB=A5=E7=AE=80=E5=8C=96=20URL=20=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- query/query-resources/index.ts | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index c2484a1..26a4d83 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/api", - "version": "0.0.63", + "version": "0.0.64", "description": "", "main": "mod.ts", "scripts": { diff --git a/query/query-resources/index.ts b/query/query-resources/index.ts index b62f220..64ff59a 100644 --- a/query/query-resources/index.ts +++ b/query/query-resources/index.ts @@ -59,19 +59,25 @@ export class QueryResources { headers: this.header(opts?.headers), }); } + getUrl(prefix: string): string { + if (prefix.startsWith('http')) { + return prefix; + } + return `${this.prefix}${prefix}`; + } async getList(prefix: string, data?: { recursive?: boolean }, opts?: DataOpts): Promise> { return this.get(data, { - url: `${this.prefix}${prefix}`, + url: this.getUrl(prefix), body: data, ...opts, }); } async fetchFile(filepath: string, opts?: DataOpts): Promise> { - const url = `${this.prefix}${filepath}`; + const url = this.getUrl(filepath); return this.get({}, { url, method: 'GET', ...opts, headers: this.header(opts?.headers, false), isText: true }); } async uploadFile(filepath: string, content: string | Blob, opts?: DataOpts & { chunkSize?: number, maxSize?: number }): Promise> { - const pathname = `${this.prefix}${filepath}`; + const pathname = this.getUrl(filepath); const filename = path.basename(pathname); const type = getContentType(filename); const url = new URL(pathname, window.location.origin); @@ -114,12 +120,12 @@ export class QueryResources { return res; } async uploadChunkedFile(filepath: string, file: Blob, hash: string, opts?: DataOpts & { chunkSize?: number }): Promise> { - const pathname = `${this.prefix}${filepath}`; + const pathname = this.getUrl(filepath); const filename = path.basename(pathname); const url = new URL(pathname, window.location.origin); url.searchParams.set('hash', hash); url.searchParams.set('chunk', '1'); - console.log(`url,`, url, hash); + // console.log(`url,`, url, hash); // 预留 eventSource 支持(暂不处理) // const createEventSource = opts?.createEventSource; const { chunkSize: _chunkSize, ...restOpts } = opts || {}; @@ -183,7 +189,7 @@ export class QueryResources { } async getStat(filepath: string, opts?: DataOpts): Promise> { - const url = `${this.prefix}${filepath}`; + const url = this.getUrl(filepath); return adapter({ url, params: { @@ -207,8 +213,8 @@ export class QueryResources { return this.uploadFile(filepath, '文件夹占位,其他文件不存在,文件夹不存在,如果有其他文件夹,删除当前文件夹占位文件即可', opts); } async rename(oldpath: string, newpath: string, opts?: DataOpts): Promise> { - const pathname = `${this.prefix}${oldpath}`; - const newName = `${this.prefix}${newpath}`; + const pathname = this.getUrl(oldpath); + const newName = this.getUrl(newpath); const params = { newName: newName, }; @@ -221,7 +227,7 @@ export class QueryResources { }); } async deleteFile(filepath: string, opts?: DataOpts): Promise> { - const url = `${this.prefix}${filepath}`; + const url = this.getUrl(filepath); return adapter({ url, method: 'DELETE' as any,