@data-loom/storage-js 0.2.1-alpha.1
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.
- package/LICENSE +201 -0
- package/README.md +163 -0
- package/dist/main/StorageClient.d.ts +18 -0
- package/dist/main/StorageClient.d.ts.map +1 -0
- package/dist/main/StorageClient.js +23 -0
- package/dist/main/StorageClient.js.map +1 -0
- package/dist/main/index.d.ts +4 -0
- package/dist/main/index.d.ts.map +1 -0
- package/dist/main/index.js +22 -0
- package/dist/main/index.js.map +1 -0
- package/dist/main/lib/constants.d.ts +4 -0
- package/dist/main/lib/constants.d.ts.map +1 -0
- package/dist/main/lib/constants.js +6 -0
- package/dist/main/lib/constants.js.map +1 -0
- package/dist/main/lib/errors.d.ts +22 -0
- package/dist/main/lib/errors.d.ts.map +1 -0
- package/dist/main/lib/errors.js +45 -0
- package/dist/main/lib/errors.js.map +1 -0
- package/dist/main/lib/fetch.d.ts +16 -0
- package/dist/main/lib/fetch.d.ts.map +1 -0
- package/dist/main/lib/fetch.js +78 -0
- package/dist/main/lib/fetch.js.map +1 -0
- package/dist/main/lib/helpers.d.ts +14 -0
- package/dist/main/lib/helpers.d.ts.map +1 -0
- package/dist/main/lib/helpers.js +104 -0
- package/dist/main/lib/helpers.js.map +1 -0
- package/dist/main/lib/index.d.ts +5 -0
- package/dist/main/lib/index.d.ts.map +1 -0
- package/dist/main/lib/index.js +21 -0
- package/dist/main/lib/index.js.map +1 -0
- package/dist/main/lib/types.d.ts +139 -0
- package/dist/main/lib/types.d.ts.map +1 -0
- package/dist/main/lib/types.js +3 -0
- package/dist/main/lib/types.js.map +1 -0
- package/dist/main/lib/version.d.ts +2 -0
- package/dist/main/lib/version.d.ts.map +1 -0
- package/dist/main/lib/version.js +6 -0
- package/dist/main/lib/version.js.map +1 -0
- package/dist/main/packages/StorageBucketApi.d.ts +118 -0
- package/dist/main/packages/StorageBucketApi.d.ts.map +1 -0
- package/dist/main/packages/StorageBucketApi.js +149 -0
- package/dist/main/packages/StorageBucketApi.js.map +1 -0
- package/dist/main/packages/StorageFileApi.d.ts +243 -0
- package/dist/main/packages/StorageFileApi.d.ts.map +1 -0
- package/dist/main/packages/StorageFileApi.js +456 -0
- package/dist/main/packages/StorageFileApi.js.map +1 -0
- package/dist/module/StorageClient.d.ts +18 -0
- package/dist/module/StorageClient.d.ts.map +1 -0
- package/dist/module/StorageClient.js +16 -0
- package/dist/module/StorageClient.js.map +1 -0
- package/dist/module/index.d.ts +4 -0
- package/dist/module/index.d.ts.map +1 -0
- package/dist/module/index.js +4 -0
- package/dist/module/index.js.map +1 -0
- package/dist/module/lib/constants.d.ts +4 -0
- package/dist/module/lib/constants.d.ts.map +1 -0
- package/dist/module/lib/constants.js +3 -0
- package/dist/module/lib/constants.js.map +1 -0
- package/dist/module/lib/errors.d.ts +22 -0
- package/dist/module/lib/errors.d.ts.map +1 -0
- package/dist/module/lib/errors.js +37 -0
- package/dist/module/lib/errors.js.map +1 -0
- package/dist/module/lib/fetch.d.ts +16 -0
- package/dist/module/lib/fetch.d.ts.map +1 -0
- package/dist/module/lib/fetch.js +70 -0
- package/dist/module/lib/fetch.js.map +1 -0
- package/dist/module/lib/helpers.d.ts +14 -0
- package/dist/module/lib/helpers.d.ts.map +1 -0
- package/dist/module/lib/helpers.js +72 -0
- package/dist/module/lib/helpers.js.map +1 -0
- package/dist/module/lib/index.d.ts +5 -0
- package/dist/module/lib/index.d.ts.map +1 -0
- package/dist/module/lib/index.js +5 -0
- package/dist/module/lib/index.js.map +1 -0
- package/dist/module/lib/types.d.ts +139 -0
- package/dist/module/lib/types.d.ts.map +1 -0
- package/dist/module/lib/types.js +2 -0
- package/dist/module/lib/types.js.map +1 -0
- package/dist/module/lib/version.d.ts +2 -0
- package/dist/module/lib/version.d.ts.map +1 -0
- package/dist/module/lib/version.js +3 -0
- package/dist/module/lib/version.js.map +1 -0
- package/dist/module/packages/StorageBucketApi.d.ts +118 -0
- package/dist/module/packages/StorageBucketApi.d.ts.map +1 -0
- package/dist/module/packages/StorageBucketApi.js +146 -0
- package/dist/module/packages/StorageBucketApi.js.map +1 -0
- package/dist/module/packages/StorageFileApi.d.ts +243 -0
- package/dist/module/packages/StorageFileApi.d.ts.map +1 -0
- package/dist/module/packages/StorageFileApi.js +453 -0
- package/dist/module/packages/StorageFileApi.js.map +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
import { isStorageError, StorageError, StorageUnknownError, isErrorReturned } from '../lib/errors';
|
|
2
|
+
import { get, head, post, put, remove } from '../lib/fetch';
|
|
3
|
+
import { recursiveToCamel, resolveFetch, getUpdateFileSize } from '../lib/helpers';
|
|
4
|
+
const DEFAULT_SEARCH_OPTIONS = {
|
|
5
|
+
limit: 100,
|
|
6
|
+
offset: 0,
|
|
7
|
+
sortBy: {
|
|
8
|
+
column: 'name',
|
|
9
|
+
order: 'asc',
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
const DEFAULT_FILE_OPTIONS = {
|
|
13
|
+
// cacheControl: '3600',
|
|
14
|
+
// contentType: 'text/plain;charset=UTF-8',
|
|
15
|
+
upsert: false,
|
|
16
|
+
};
|
|
17
|
+
export default class StorageFileApi {
|
|
18
|
+
constructor(url, headers = {}, bucketId, fetch) {
|
|
19
|
+
this.url = url;
|
|
20
|
+
this.headers = headers;
|
|
21
|
+
this.bucketId = bucketId;
|
|
22
|
+
this.fetch = resolveFetch(fetch);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Uploads a file to an existing bucket or replaces an existing file at the specified path with a new one.
|
|
26
|
+
*
|
|
27
|
+
* @param method HTTP method.
|
|
28
|
+
* @param path The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.
|
|
29
|
+
* @param fileBody The body of the file to be stored in the bucket.
|
|
30
|
+
*/
|
|
31
|
+
async uploadOrUpdate(path, fileBody, fileOptions) {
|
|
32
|
+
var _a, _b, _c, _d;
|
|
33
|
+
try {
|
|
34
|
+
const options = Object.assign(Object.assign({}, DEFAULT_FILE_OPTIONS), fileOptions);
|
|
35
|
+
const headers = Object.assign({}, this.headers);
|
|
36
|
+
// pre-upload
|
|
37
|
+
const preUploadBody = {
|
|
38
|
+
file_size: getUpdateFileSize(fileBody),
|
|
39
|
+
upsert: (_a = options.upsert) !== null && _a !== void 0 ? _a : false,
|
|
40
|
+
};
|
|
41
|
+
const cleanPath = this._removeEmptyFolders(path);
|
|
42
|
+
const _path = this._getFinalPath(cleanPath);
|
|
43
|
+
const res = await post(this.fetch, `${this.url}/object/${this.bucketId}/${_path}`, preUploadBody, headers);
|
|
44
|
+
const { upload_id, upload_url } = (_b = res === null || res === void 0 ? void 0 : res.data) !== null && _b !== void 0 ? _b : {};
|
|
45
|
+
if (upload_url && upload_id) {
|
|
46
|
+
const tosHeaders = {};
|
|
47
|
+
if (options.cacheControl) {
|
|
48
|
+
tosHeaders['cache-control'] = `max-age=${options.cacheControl}`;
|
|
49
|
+
}
|
|
50
|
+
if (options.contentType) {
|
|
51
|
+
tosHeaders['content-type'] = options.contentType;
|
|
52
|
+
}
|
|
53
|
+
const tosRes = await put(this.fetch, upload_url, fileBody, {
|
|
54
|
+
noResolveJson: true,
|
|
55
|
+
}, tosHeaders);
|
|
56
|
+
const etag = (_d = (_c = tosRes === null || tosRes === void 0 ? void 0 : tosRes.headers) === null || _c === void 0 ? void 0 : _c.get('Etag')) !== null && _d !== void 0 ? _d : '';
|
|
57
|
+
const callbackRes = await post(this.fetch, `${this.url}/object/callback`, {
|
|
58
|
+
upload_id,
|
|
59
|
+
etag,
|
|
60
|
+
});
|
|
61
|
+
if (isErrorReturned(callbackRes)) {
|
|
62
|
+
return {
|
|
63
|
+
data: null,
|
|
64
|
+
error: callbackRes,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
data: callbackRes.data,
|
|
69
|
+
error: null,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
return {
|
|
74
|
+
data: null,
|
|
75
|
+
error: new StorageError('upload_url or upload_id is empty'),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
if (isStorageError(error)) {
|
|
81
|
+
return { data: null, error };
|
|
82
|
+
}
|
|
83
|
+
return { data: null, error: new StorageUnknownError('upload file error', error) };
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Uploads a file to an existing bucket.
|
|
88
|
+
*
|
|
89
|
+
* @param path The file path, including the file name. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.
|
|
90
|
+
* @param fileBody The body of the file to be stored in the bucket.
|
|
91
|
+
*/
|
|
92
|
+
async upload(path, fileBody, fileOptions) {
|
|
93
|
+
return this.uploadOrUpdate(path, fileBody, fileOptions);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Upload a file with a token generated from `createSignedUploadUrl`.
|
|
97
|
+
* @param path The file path, including the file name. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.
|
|
98
|
+
* @param token The token generated from `createSignedUploadUrl`
|
|
99
|
+
* @param fileBody The body of the file to be stored in the bucket.
|
|
100
|
+
*/
|
|
101
|
+
async uploadToSignedUrl(path, token, fileBody, fileOptions) {
|
|
102
|
+
const cleanPath = this._removeEmptyFolders(path);
|
|
103
|
+
const _path = this._getFinalPath(cleanPath);
|
|
104
|
+
const url = new URL(this.url + `/object/upload/sign/${_path}`);
|
|
105
|
+
url.searchParams.set('token', token);
|
|
106
|
+
try {
|
|
107
|
+
let body;
|
|
108
|
+
const options = Object.assign({ upsert: DEFAULT_FILE_OPTIONS.upsert }, fileOptions);
|
|
109
|
+
const headers = Object.assign({}, this.headers);
|
|
110
|
+
if (typeof Blob !== 'undefined' && fileBody instanceof Blob) {
|
|
111
|
+
body = new FormData();
|
|
112
|
+
body.append('cacheControl', options.cacheControl);
|
|
113
|
+
body.append('', fileBody);
|
|
114
|
+
}
|
|
115
|
+
else if (typeof FormData !== 'undefined' && fileBody instanceof FormData) {
|
|
116
|
+
body = fileBody;
|
|
117
|
+
body.append('cacheControl', options.cacheControl);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
body = fileBody;
|
|
121
|
+
headers['cache-control'] = `max-age=${options.cacheControl}`;
|
|
122
|
+
headers['content-type'] = options.contentType;
|
|
123
|
+
}
|
|
124
|
+
const data = await put(this.fetch, url.toString(), body, { headers });
|
|
125
|
+
return {
|
|
126
|
+
data: { path: cleanPath, fullPath: data.Key },
|
|
127
|
+
error: null,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
if (isStorageError(error)) {
|
|
132
|
+
return { data: null, error };
|
|
133
|
+
}
|
|
134
|
+
return { data: null, error: new StorageUnknownError('upload file error', error) };
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Creates a signed upload URL.
|
|
139
|
+
* Signed upload URLs can be used to upload files to the bucket without further authentication.
|
|
140
|
+
* They are valid for 2 hours.
|
|
141
|
+
* @param path The file path, including the current file name. For example `folder/image.png`.
|
|
142
|
+
* @param options.upsert If set to true, allows the file to be overwritten if it already exists.
|
|
143
|
+
*/
|
|
144
|
+
async createSignedUploadUrl(path, options) {
|
|
145
|
+
try {
|
|
146
|
+
let _path = this._getFinalPath(path);
|
|
147
|
+
const headers = Object.assign({}, this.headers);
|
|
148
|
+
// if (options?.upsert) {
|
|
149
|
+
// headers['x-upsert'] = 'true';
|
|
150
|
+
// }
|
|
151
|
+
const data = await post(this.fetch, `${this.url}/object/upload/sign/${_path}`, {}, { headers });
|
|
152
|
+
const url = new URL(this.url + data.url);
|
|
153
|
+
const token = url.searchParams.get('token');
|
|
154
|
+
if (!token) {
|
|
155
|
+
throw new StorageError('No token returned by API');
|
|
156
|
+
}
|
|
157
|
+
return { data: { signedUrl: url.toString(), path, token }, error: null };
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
if (isStorageError(error)) {
|
|
161
|
+
return { data: null, error };
|
|
162
|
+
}
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Replaces an existing file at the specified path with a new one.
|
|
168
|
+
*
|
|
169
|
+
* @param path The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to update.
|
|
170
|
+
* @param fileBody The body of the file to be stored in the bucket.
|
|
171
|
+
*/
|
|
172
|
+
async update(path, fileBody, fileOptions) {
|
|
173
|
+
return this.uploadOrUpdate(path, fileBody, fileOptions);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Moves an existing file to a new path in the same bucket.
|
|
177
|
+
*
|
|
178
|
+
* @param fromPath The original file path, including the current file name. For example `folder/image.png`.
|
|
179
|
+
* @param toPath The new file path, including the new file name. For example `folder/image-new.png`.
|
|
180
|
+
* @param options The destination options.
|
|
181
|
+
*/
|
|
182
|
+
async move(fromPath, toPath, options) {
|
|
183
|
+
try {
|
|
184
|
+
const data = await post(this.fetch, `${this.url}/object/move`, {
|
|
185
|
+
bucketId: this.bucketId,
|
|
186
|
+
sourceKey: fromPath,
|
|
187
|
+
destinationKey: toPath,
|
|
188
|
+
destinationBucket: options === null || options === void 0 ? void 0 : options.destinationBucket,
|
|
189
|
+
}, { headers: this.headers });
|
|
190
|
+
return { data, error: null };
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
if (isStorageError(error)) {
|
|
194
|
+
return { data: null, error };
|
|
195
|
+
}
|
|
196
|
+
throw error;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Copies an existing file to a new path in the same bucket.
|
|
201
|
+
*
|
|
202
|
+
* @param fromPath The original file path, including the current file name. For example `folder/image.png`.
|
|
203
|
+
* @param toPath The new file path, including the new file name. For example `folder/image-copy.png`.
|
|
204
|
+
* @param options The destination options.
|
|
205
|
+
*/
|
|
206
|
+
async copy(fromPath, toPath, options) {
|
|
207
|
+
try {
|
|
208
|
+
const data = await post(this.fetch, `${this.url}/object/copy`, {
|
|
209
|
+
bucketId: this.bucketId,
|
|
210
|
+
sourceKey: fromPath,
|
|
211
|
+
destinationKey: toPath,
|
|
212
|
+
destinationBucket: options === null || options === void 0 ? void 0 : options.destinationBucket,
|
|
213
|
+
}, { headers: this.headers });
|
|
214
|
+
return { data: { path: data.Key }, error: null };
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
if (isStorageError(error)) {
|
|
218
|
+
return { data: null, error };
|
|
219
|
+
}
|
|
220
|
+
throw error;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Creates a signed URL. Use a signed URL to share a file for a fixed amount of time.
|
|
225
|
+
*
|
|
226
|
+
* @param path The file path, including the current file name. For example `folder/image.png`.
|
|
227
|
+
* @param expiresIn The number of seconds until the signed URL expires. For example, `60` for a URL which is valid for one minute.
|
|
228
|
+
* @param options.download triggers the file as a download if set to true. Set this parameter as the name of the file if you want to trigger the download with a different filename.
|
|
229
|
+
* @param options.transform Transform the asset before serving it to the client.
|
|
230
|
+
*/
|
|
231
|
+
async createSignedUrl(path, expiresIn) {
|
|
232
|
+
try {
|
|
233
|
+
let _path = this._getFinalPath(path);
|
|
234
|
+
const res = await post(this.fetch, `${this.url}/object/sign/${_path}`, { expires_in: expiresIn }, { headers: this.headers });
|
|
235
|
+
if (isErrorReturned(res)) {
|
|
236
|
+
return {
|
|
237
|
+
data: null,
|
|
238
|
+
error: res,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
return { data: res.data, error: null };
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
if (isStorageError(error)) {
|
|
245
|
+
return { data: null, error };
|
|
246
|
+
}
|
|
247
|
+
throw error;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Creates multiple signed URLs. Use a signed URL to share a file for a fixed amount of time.
|
|
252
|
+
*
|
|
253
|
+
* @param paths The file paths to be downloaded, including the current file names. For example `['folder/image.png', 'folder2/image2.png']`.
|
|
254
|
+
* @param expiresIn The number of seconds until the signed URLs expire. For example, `60` for URLs which are valid for one minute.
|
|
255
|
+
* @param options.download triggers the file as a download if set to true. Set this parameter as the name of the file if you want to trigger the download with a different filename.
|
|
256
|
+
*/
|
|
257
|
+
async createSignedUrls(paths, expiresIn) {
|
|
258
|
+
try {
|
|
259
|
+
const res = await post(this.fetch, `${this.url}/object/sign/${this.bucketId}`, { expires_in: expiresIn, paths }, { headers: this.headers });
|
|
260
|
+
if (isErrorReturned(res)) {
|
|
261
|
+
return {
|
|
262
|
+
data: null,
|
|
263
|
+
error: res,
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
data: res.data,
|
|
268
|
+
error: null,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
catch (error) {
|
|
272
|
+
if (isStorageError(error)) {
|
|
273
|
+
return { data: null, error };
|
|
274
|
+
}
|
|
275
|
+
throw error;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Downloads a file from a private bucket. For public buckets, make a request to the URL returned from `getPublicUrl` instead.
|
|
280
|
+
*
|
|
281
|
+
* @param path The full path and file name of the file to be downloaded. For example `folder/image.png`.
|
|
282
|
+
* @param options.transform Transform the asset before serving it to the client.
|
|
283
|
+
*/
|
|
284
|
+
async download(path) {
|
|
285
|
+
try {
|
|
286
|
+
const _path = this._getFinalPath(path);
|
|
287
|
+
const res = await get(this.fetch, `${this.url}/object/${_path}`, {
|
|
288
|
+
headers: this.headers,
|
|
289
|
+
noResolveJson: true,
|
|
290
|
+
});
|
|
291
|
+
let resBody;
|
|
292
|
+
// only parse blob when response is from TOS, server returns 200 with errors if it can't redirect to TOS.
|
|
293
|
+
if (res.redirected && res.headers.get('server') === 'TosServer') {
|
|
294
|
+
resBody = await res.blob();
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
resBody = await res.json();
|
|
298
|
+
return { data: null, error: resBody };
|
|
299
|
+
}
|
|
300
|
+
return { data: resBody, error: null };
|
|
301
|
+
}
|
|
302
|
+
catch (error) {
|
|
303
|
+
if (isStorageError(error)) {
|
|
304
|
+
return { data: null, error };
|
|
305
|
+
}
|
|
306
|
+
return { data: null, error: new StorageUnknownError('download file error', error) };
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Retrieves the details of an existing file.
|
|
311
|
+
* @param path
|
|
312
|
+
*/
|
|
313
|
+
async info(path) {
|
|
314
|
+
const _path = this._getFinalPath(path);
|
|
315
|
+
try {
|
|
316
|
+
const data = await get(this.fetch, `${this.url}/object/info/${_path}`, {
|
|
317
|
+
headers: this.headers,
|
|
318
|
+
});
|
|
319
|
+
return { data: recursiveToCamel(data), error: null };
|
|
320
|
+
}
|
|
321
|
+
catch (error) {
|
|
322
|
+
if (isStorageError(error)) {
|
|
323
|
+
return { data: null, error };
|
|
324
|
+
}
|
|
325
|
+
throw error;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Checks the existence of a file.
|
|
330
|
+
* @param path
|
|
331
|
+
*/
|
|
332
|
+
async exists(path) {
|
|
333
|
+
const _path = this._getFinalPath(path);
|
|
334
|
+
try {
|
|
335
|
+
await head(this.fetch, `${this.url}/object/${_path}`, {
|
|
336
|
+
headers: this.headers,
|
|
337
|
+
});
|
|
338
|
+
return { data: true, error: null };
|
|
339
|
+
}
|
|
340
|
+
catch (error) {
|
|
341
|
+
if (isStorageError(error) && error instanceof StorageUnknownError) {
|
|
342
|
+
const originalError = error.originalError;
|
|
343
|
+
if ([400, 404].includes(originalError === null || originalError === void 0 ? void 0 : originalError.status)) {
|
|
344
|
+
return { data: false, error };
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
throw error;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* A simple convenience function to get the URL for an asset in a public bucket. If you do not want to use this function, you can construct the public URL by concatenating the bucket URL with the path to the asset.
|
|
352
|
+
* This function does not verify if the bucket is public. If a public URL is created for a bucket which is not public, you will not be able to download the asset.
|
|
353
|
+
*
|
|
354
|
+
* @param path The path and name of the file to generate the public URL for. For example `folder/image.png`.
|
|
355
|
+
* @param options.download Triggers the file as a download if set to true. Set this parameter as the name of the file if you want to trigger the download with a different filename.
|
|
356
|
+
* @param options.transform Transform the asset before serving it to the client.
|
|
357
|
+
*/
|
|
358
|
+
getPublicUrl(path, options) {
|
|
359
|
+
const _path = this._getFinalPath(path);
|
|
360
|
+
const _queryString = [];
|
|
361
|
+
const downloadQueryParam = (options === null || options === void 0 ? void 0 : options.download)
|
|
362
|
+
? `download=${options.download === true ? '' : options.download}`
|
|
363
|
+
: '';
|
|
364
|
+
if (downloadQueryParam !== '') {
|
|
365
|
+
_queryString.push(downloadQueryParam);
|
|
366
|
+
}
|
|
367
|
+
const wantsTransformation = typeof (options === null || options === void 0 ? void 0 : options.transform) !== 'undefined';
|
|
368
|
+
const renderPath = wantsTransformation ? 'render/image' : 'object';
|
|
369
|
+
const transformationQuery = this.transformOptsToQueryString((options === null || options === void 0 ? void 0 : options.transform) || {});
|
|
370
|
+
if (transformationQuery !== '') {
|
|
371
|
+
_queryString.push(transformationQuery);
|
|
372
|
+
}
|
|
373
|
+
let queryString = _queryString.join('&');
|
|
374
|
+
if (queryString !== '') {
|
|
375
|
+
queryString = `?${queryString}`;
|
|
376
|
+
}
|
|
377
|
+
return {
|
|
378
|
+
data: { publicUrl: encodeURI(`${this.url}/${renderPath}/public/${_path}${queryString}`) },
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Deletes files within the same bucket
|
|
383
|
+
*
|
|
384
|
+
* @param paths An array of files to delete, including the path and file name. For example [`'folder/image.png'`].
|
|
385
|
+
*/
|
|
386
|
+
async remove(paths) {
|
|
387
|
+
try {
|
|
388
|
+
const res = await remove(this.fetch, `${this.url}/object/${this.bucketId}`, { prefixes: paths }, { headers: this.headers });
|
|
389
|
+
return { data: res.data, error: null };
|
|
390
|
+
}
|
|
391
|
+
catch (error) {
|
|
392
|
+
if (isStorageError(error)) {
|
|
393
|
+
return { data: null, error };
|
|
394
|
+
}
|
|
395
|
+
return { data: null, error: new StorageUnknownError('remove file error', error) };
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Lists all the files within a bucket.
|
|
400
|
+
* @param path The folder path.
|
|
401
|
+
* @param options Search options including limit (defaults to 100), offset, sortBy, and search
|
|
402
|
+
*/
|
|
403
|
+
async list(path, options) {
|
|
404
|
+
try {
|
|
405
|
+
const body = Object.assign(Object.assign(Object.assign({}, DEFAULT_SEARCH_OPTIONS), options), { prefix: path || '' });
|
|
406
|
+
const res = await post(this.fetch, `${this.url}/object/list/${this.bucketId}`, body, {
|
|
407
|
+
headers: this.headers,
|
|
408
|
+
});
|
|
409
|
+
return { data: res.data, error: null };
|
|
410
|
+
}
|
|
411
|
+
catch (error) {
|
|
412
|
+
if (isStorageError(error)) {
|
|
413
|
+
return { data: null, error };
|
|
414
|
+
}
|
|
415
|
+
throw error;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
encodeMetadata(metadata) {
|
|
419
|
+
return JSON.stringify(metadata);
|
|
420
|
+
}
|
|
421
|
+
toBase64(data) {
|
|
422
|
+
if (typeof Buffer !== 'undefined') {
|
|
423
|
+
return Buffer.from(data).toString('base64');
|
|
424
|
+
}
|
|
425
|
+
return btoa(data);
|
|
426
|
+
}
|
|
427
|
+
_getFinalPath(path) {
|
|
428
|
+
return `${this.bucketId}/${path.replace(/^\/+/, '')}`;
|
|
429
|
+
}
|
|
430
|
+
_removeEmptyFolders(path) {
|
|
431
|
+
return path.replace(/^\/|\/$/g, '').replace(/\/+/g, '/');
|
|
432
|
+
}
|
|
433
|
+
transformOptsToQueryString(transform) {
|
|
434
|
+
const params = [];
|
|
435
|
+
if (transform.width) {
|
|
436
|
+
params.push(`width=${transform.width}`);
|
|
437
|
+
}
|
|
438
|
+
if (transform.height) {
|
|
439
|
+
params.push(`height=${transform.height}`);
|
|
440
|
+
}
|
|
441
|
+
if (transform.resize) {
|
|
442
|
+
params.push(`resize=${transform.resize}`);
|
|
443
|
+
}
|
|
444
|
+
if (transform.format) {
|
|
445
|
+
params.push(`format=${transform.format}`);
|
|
446
|
+
}
|
|
447
|
+
if (transform.quality) {
|
|
448
|
+
params.push(`quality=${transform.quality}`);
|
|
449
|
+
}
|
|
450
|
+
return params.join('&');
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
//# sourceMappingURL=StorageFileApi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StorageFileApi.js","sourceRoot":"","sources":["../../../src/packages/StorageFileApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACnG,OAAO,EAAS,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAanF,MAAM,sBAAsB,GAAG;IAC7B,KAAK,EAAE,GAAG;IACV,MAAM,EAAE,CAAC;IACT,MAAM,EAAE;QACN,MAAM,EAAE,MAAM;QACd,KAAK,EAAE,KAAK;KACb;CACF,CAAC;AAEF,MAAM,oBAAoB,GAAgB;IACxC,wBAAwB;IACxB,2CAA2C;IAC3C,MAAM,EAAE,KAAK;CACd,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,cAAc;IAMjC,YACE,GAAW,EACX,UAAqC,EAAE,EACvC,QAAiB,EACjB,KAAa;QAEb,IAAI,CAAC,GAAG,GAAG,GAA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,SAAS,CAAC,KAAK,EAAE;YACnB,MAAM,CAAC,IAAI,CAAC,SAAS,SAAS,CAAC,KAAK,EAAE,CAAC,CAAC;SACzC;QAED,IAAI,SAAS,CAAC,MAAM,EAAE;YACpB,MAAM,CAAC,IAAI,CAAC,UAAU,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;SAC3C;QAED,IAAI,SAAS,CAAC,MAAM,EAAE;YACpB,MAAM,CAAC,IAAI,CAAC,UAAU,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;SAC3C;QAED,IAAI,SAAS,CAAC,MAAM,EAAE;YACpB,MAAM,CAAC,IAAI,CAAC,UAAU,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;SAC3C;QAED,IAAI,SAAS,CAAC,OAAO,EAAE;YACrB,MAAM,CAAC,IAAI,CAAC,WAAW,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC;SAC7C;QAED,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@data-loom/storage-js",
|
|
3
|
+
"version": "0.2.1-alpha.1",
|
|
4
|
+
"description": "Dataloom service",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"service",
|
|
7
|
+
"dataloom"
|
|
8
|
+
],
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"author": "Dataloom",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"main": "dist/main/index.js",
|
|
15
|
+
"module": "dist/module/index.js",
|
|
16
|
+
"types": "dist/module/index.d.ts",
|
|
17
|
+
"scripts": {
|
|
18
|
+
"clean": "rimraf dist docs/v2",
|
|
19
|
+
"format": "prettier --write \"{src,test}/**/**/*.ts\"",
|
|
20
|
+
"format:check": "prettier --check \"{src,test}/**/**/*.ts\"",
|
|
21
|
+
"build": "run-s clean format build:*",
|
|
22
|
+
"build:main": "npx tsc -p tsconfig.json",
|
|
23
|
+
"build:module": "npx tsc -p tsconfig.module.json",
|
|
24
|
+
"test": "run-s test:types test:run",
|
|
25
|
+
"test:run": "jest --runInBand",
|
|
26
|
+
"test:coverage": "jest --runInBand --coverage",
|
|
27
|
+
"test:db": "cd infra/db && docker-compose down && docker-compose up -d && sleep 5",
|
|
28
|
+
"test:watch": "jest --watch --verbose false --silent false",
|
|
29
|
+
"test:clean": "cd infra/db && docker-compose down",
|
|
30
|
+
"test:types": "run-s build:module && tsd --files test/*.test-d.ts",
|
|
31
|
+
"test:cov": "exit 0",
|
|
32
|
+
"lint": "exit 0",
|
|
33
|
+
"test:types:watch": "run-s build && tsd --files 'test/**/*.test-d.ts' --watch"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@data-loom/node-fetch": "0.2.1-alpha.1"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/jest": "^26.0.13",
|
|
40
|
+
"@types/node": "^18.16.19",
|
|
41
|
+
"form-data": "^4.0.0",
|
|
42
|
+
"genversion": "^3.0.1",
|
|
43
|
+
"husky": "^4.3.0",
|
|
44
|
+
"jest": "^29.0.0",
|
|
45
|
+
"jest-environment-jsdom": "^29.5.0",
|
|
46
|
+
"npm-run-all": "^4.1.5",
|
|
47
|
+
"prettier": "^2.1.2",
|
|
48
|
+
"pretty-quick": "^3.1.0",
|
|
49
|
+
"rimraf": "^3.0.2",
|
|
50
|
+
"semantic-release-plugin-update-version-in-files": "^1.1.0",
|
|
51
|
+
"ts-jest": "^29.0.0",
|
|
52
|
+
"ts-loader": "^9.4.2",
|
|
53
|
+
"typedoc": "^0.22.16",
|
|
54
|
+
"typescript": "^4.6.3",
|
|
55
|
+
"webpack": "^5.75.0",
|
|
56
|
+
"webpack-cli": "^5.0.1"
|
|
57
|
+
}
|
|
58
|
+
}
|