@kevisual/api 0.0.63 → 0.0.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,6 +21,7 @@ declare class QueryResources {
21
21
  setPrefix(prefix: string): void;
22
22
  header(headers?: Record<string, string>, json?: boolean): Record<string, string>;
23
23
  get(data: any, opts: DataOpts): Promise<any>;
24
+ getUrl(prefix: string): string;
24
25
  getList(prefix: string, data?: {
25
26
  recursive?: boolean;
26
27
  }, opts?: DataOpts): Promise<Result<any[]>>;
@@ -1061,19 +1061,25 @@ class QueryResources {
1061
1061
  headers: this.header(opts?.headers)
1062
1062
  });
1063
1063
  }
1064
+ getUrl(prefix) {
1065
+ if (prefix.startsWith("http")) {
1066
+ return prefix;
1067
+ }
1068
+ return `${this.prefix}${prefix}`;
1069
+ }
1064
1070
  async getList(prefix, data, opts) {
1065
1071
  return this.get(data, {
1066
- url: `${this.prefix}${prefix}`,
1072
+ url: this.getUrl(prefix),
1067
1073
  body: data,
1068
1074
  ...opts
1069
1075
  });
1070
1076
  }
1071
1077
  async fetchFile(filepath, opts) {
1072
- const url = `${this.prefix}${filepath}`;
1078
+ const url = this.getUrl(filepath);
1073
1079
  return this.get({}, { url, method: "GET", ...opts, headers: this.header(opts?.headers, false), isText: true });
1074
1080
  }
1075
1081
  async uploadFile(filepath, content, opts) {
1076
- const pathname = `${this.prefix}${filepath}`;
1082
+ const pathname = this.getUrl(filepath);
1077
1083
  const filename = posix.basename(pathname);
1078
1084
  const type = getContentType(filename);
1079
1085
  const url = new URL(pathname, window.location.origin);
@@ -1111,12 +1117,11 @@ class QueryResources {
1111
1117
  return res;
1112
1118
  }
1113
1119
  async uploadChunkedFile(filepath, file, hash, opts) {
1114
- const pathname = `${this.prefix}${filepath}`;
1120
+ const pathname = this.getUrl(filepath);
1115
1121
  const filename = posix.basename(pathname);
1116
1122
  const url = new URL(pathname, window.location.origin);
1117
1123
  url.searchParams.set("hash", hash);
1118
1124
  url.searchParams.set("chunk", "1");
1119
- console.log(`url,`, url, hash);
1120
1125
  const { chunkSize: _chunkSize, ...restOpts } = opts || {};
1121
1126
  const chunkSize = _chunkSize ?? 5 * 1024 * 1024;
1122
1127
  const totalChunks = Math.ceil(file.size / chunkSize);
@@ -1169,7 +1174,7 @@ class QueryResources {
1169
1174
  return filepath;
1170
1175
  }
1171
1176
  async getStat(filepath, opts) {
1172
- const url = `${this.prefix}${filepath}`;
1177
+ const url = this.getUrl(filepath);
1173
1178
  return adapter({
1174
1179
  url,
1175
1180
  params: {
@@ -1187,8 +1192,8 @@ class QueryResources {
1187
1192
  return this.uploadFile(filepath, "文件夹占位,其他文件不存在,文件夹不存在,如果有其他文件夹,删除当前文件夹占位文件即可", opts);
1188
1193
  }
1189
1194
  async rename(oldpath, newpath, opts) {
1190
- const pathname = `${this.prefix}${oldpath}`;
1191
- const newName = `${this.prefix}${newpath}`;
1195
+ const pathname = this.getUrl(oldpath);
1196
+ const newName = this.getUrl(newpath);
1192
1197
  const params = {
1193
1198
  newName
1194
1199
  };
@@ -1201,7 +1206,7 @@ class QueryResources {
1201
1206
  });
1202
1207
  }
1203
1208
  async deleteFile(filepath, opts) {
1204
- const url = `${this.prefix}${filepath}`;
1209
+ const url = this.getUrl(filepath);
1205
1210
  return adapter({
1206
1211
  url,
1207
1212
  method: "DELETE",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kevisual/api",
3
- "version": "0.0.63",
3
+ "version": "0.0.64",
4
4
  "description": "",
5
5
  "main": "mod.ts",
6
6
  "scripts": {
@@ -59,19 +59,25 @@ export class QueryResources {
59
59
  headers: this.header(opts?.headers),
60
60
  });
61
61
  }
62
+ getUrl(prefix: string): string {
63
+ if (prefix.startsWith('http')) {
64
+ return prefix;
65
+ }
66
+ return `${this.prefix}${prefix}`;
67
+ }
62
68
  async getList(prefix: string, data?: { recursive?: boolean }, opts?: DataOpts): Promise<Result<any[]>> {
63
69
  return this.get(data, {
64
- url: `${this.prefix}${prefix}`,
70
+ url: this.getUrl(prefix),
65
71
  body: data,
66
72
  ...opts,
67
73
  });
68
74
  }
69
75
  async fetchFile(filepath: string, opts?: DataOpts): Promise<Result<any>> {
70
- const url = `${this.prefix}${filepath}`;
76
+ const url = this.getUrl(filepath);
71
77
  return this.get({}, { url, method: 'GET', ...opts, headers: this.header(opts?.headers, false), isText: true });
72
78
  }
73
79
  async uploadFile(filepath: string, content: string | Blob, opts?: DataOpts & { chunkSize?: number, maxSize?: number }): Promise<Result<any>> {
74
- const pathname = `${this.prefix}${filepath}`;
80
+ const pathname = this.getUrl(filepath);
75
81
  const filename = path.basename(pathname);
76
82
  const type = getContentType(filename);
77
83
  const url = new URL(pathname, window.location.origin);
@@ -114,12 +120,12 @@ export class QueryResources {
114
120
  return res;
115
121
  }
116
122
  async uploadChunkedFile(filepath: string, file: Blob, hash: string, opts?: DataOpts & { chunkSize?: number }): Promise<Result<any>> {
117
- const pathname = `${this.prefix}${filepath}`;
123
+ const pathname = this.getUrl(filepath);
118
124
  const filename = path.basename(pathname);
119
125
  const url = new URL(pathname, window.location.origin);
120
126
  url.searchParams.set('hash', hash);
121
127
  url.searchParams.set('chunk', '1');
122
- console.log(`url,`, url, hash);
128
+ // console.log(`url,`, url, hash);
123
129
  // 预留 eventSource 支持(暂不处理)
124
130
  // const createEventSource = opts?.createEventSource;
125
131
  const { chunkSize: _chunkSize, ...restOpts } = opts || {};
@@ -183,7 +189,7 @@ export class QueryResources {
183
189
  }
184
190
 
185
191
  async getStat(filepath: string, opts?: DataOpts): Promise<Result<Stat>> {
186
- const url = `${this.prefix}${filepath}`;
192
+ const url = this.getUrl(filepath);
187
193
  return adapter({
188
194
  url,
189
195
  params: {
@@ -207,8 +213,8 @@ export class QueryResources {
207
213
  return this.uploadFile(filepath, '文件夹占位,其他文件不存在,文件夹不存在,如果有其他文件夹,删除当前文件夹占位文件即可', opts);
208
214
  }
209
215
  async rename(oldpath: string, newpath: string, opts?: DataOpts): Promise<Result<any>> {
210
- const pathname = `${this.prefix}${oldpath}`;
211
- const newName = `${this.prefix}${newpath}`;
216
+ const pathname = this.getUrl(oldpath);
217
+ const newName = this.getUrl(newpath);
212
218
  const params = {
213
219
  newName: newName,
214
220
  };
@@ -221,7 +227,7 @@ export class QueryResources {
221
227
  });
222
228
  }
223
229
  async deleteFile(filepath: string, opts?: DataOpts): Promise<Result<any>> {
224
- const url = `${this.prefix}${filepath}`;
230
+ const url = this.getUrl(filepath);
225
231
  return adapter({
226
232
  url,
227
233
  method: 'DELETE' as any,