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,