@tweedegolf/sab-adapter-backblaze-b2 3.0.0 → 3.0.2
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/changelog.md +13 -0
- package/dist/AbstractAdapter.d.ts +20 -75
- package/dist/AbstractAdapter.js +337 -259
- package/dist/AbstractAdapter.js.map +1 -1
- package/dist/AdapterBackblazeB2.d.ts +2 -2
- package/dist/AdapterBackblazeB2.js +461 -406
- package/dist/AdapterBackblazeB2.js.map +1 -1
- package/dist/types/backblaze-b2.d.ts +182 -0
- package/dist/types/general.d.ts +23 -78
- package/dist/types/result.d.ts +9 -9
- package/dist/util.d.ts +2 -1
- package/dist/util.js +28 -22
- package/dist/util.js.map +1 -1
- package/package.json +1 -1
package/dist/AbstractAdapter.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
@@ -12,7 +21,6 @@ class AbstractAdapter {
|
|
|
12
21
|
this._provider = general_1.Provider.NONE;
|
|
13
22
|
this._configError = null;
|
|
14
23
|
this._bucketName = null;
|
|
15
|
-
this._client = null; // eslint-disable-line
|
|
16
24
|
}
|
|
17
25
|
get provider() {
|
|
18
26
|
return this._provider;
|
|
@@ -61,8 +69,8 @@ class AbstractAdapter {
|
|
|
61
69
|
getFileAndBucketAndOptions(...args) {
|
|
62
70
|
const [arg1, arg2, arg3] = args;
|
|
63
71
|
// console.log("getFileAndBucketAndOptions", arg1, arg2, arg3);
|
|
64
|
-
let bucketName =
|
|
65
|
-
let fileName =
|
|
72
|
+
let bucketName = undefined;
|
|
73
|
+
let fileName = undefined;
|
|
66
74
|
let options = {};
|
|
67
75
|
let error = null;
|
|
68
76
|
if (typeof arg1 !== "string" && typeof arg2 !== "string") {
|
|
@@ -77,7 +85,7 @@ class AbstractAdapter {
|
|
|
77
85
|
return { bucketName, fileName, options, error };
|
|
78
86
|
}
|
|
79
87
|
if (typeof arg1 !== "string" && typeof arg2 === "string") {
|
|
80
|
-
bucketName = this._bucketName;
|
|
88
|
+
bucketName = this._bucketName === null ? undefined : this._bucketName;
|
|
81
89
|
if (bucketName === null) {
|
|
82
90
|
return { bucketName, fileName, options, error: "Please provide or select a bucket" };
|
|
83
91
|
}
|
|
@@ -88,7 +96,7 @@ class AbstractAdapter {
|
|
|
88
96
|
return { bucketName, fileName, options, error };
|
|
89
97
|
}
|
|
90
98
|
if (typeof arg1 === "string" && typeof arg2 !== "string") {
|
|
91
|
-
bucketName = this._bucketName;
|
|
99
|
+
bucketName = this._bucketName === null ? undefined : this._bucketName;
|
|
92
100
|
if (bucketName === null) {
|
|
93
101
|
return { bucketName, fileName, options, error: "Please provide or select a bucket" };
|
|
94
102
|
}
|
|
@@ -104,284 +112,354 @@ class AbstractAdapter {
|
|
|
104
112
|
if (fileName === null) {
|
|
105
113
|
return { bucketName, fileName, options, error: "Please provide a filename" };
|
|
106
114
|
}
|
|
115
|
+
return { bucketName, fileName, options, error };
|
|
107
116
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (typeof name === "undefined") {
|
|
113
|
-
if (this._bucketName === null) {
|
|
114
|
-
return {
|
|
115
|
-
value: null,
|
|
116
|
-
error: "No bucket selected.",
|
|
117
|
-
};
|
|
117
|
+
checkBucket(name_1) {
|
|
118
|
+
return __awaiter(this, arguments, void 0, function* (name, checkIfExists = true) {
|
|
119
|
+
if (this._configError !== null) {
|
|
120
|
+
return { value: null, error: this.configError };
|
|
118
121
|
}
|
|
119
|
-
name
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
if (typeof name === "undefined") {
|
|
123
|
+
if (this._bucketName === null) {
|
|
124
|
+
return {
|
|
125
|
+
value: null,
|
|
126
|
+
error: "No bucket selected.",
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
name = this._bucketName;
|
|
125
130
|
}
|
|
126
|
-
|
|
127
|
-
|
|
131
|
+
if (checkIfExists === true) {
|
|
132
|
+
const { value, error } = yield this._bucketExists(name);
|
|
133
|
+
if (error !== null) {
|
|
134
|
+
return { value: null, error };
|
|
135
|
+
}
|
|
136
|
+
else if (value === false) {
|
|
137
|
+
return { value: null, error: `No bucket '${name}' found.` };
|
|
138
|
+
}
|
|
128
139
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
140
|
+
return { value: name, error: null };
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
checkFile(bucketName, fileName) {
|
|
144
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
+
const r = yield this._fileExists(bucketName, fileName);
|
|
146
|
+
if (r.error) {
|
|
147
|
+
return { value: null, error: r.error };
|
|
148
|
+
}
|
|
149
|
+
if (r.value === false) {
|
|
150
|
+
return { value: null, error: `No file '${fileName}' found in bucket '${bucketName}'` };
|
|
151
|
+
}
|
|
152
|
+
return { value: null, error: null };
|
|
153
|
+
});
|
|
141
154
|
}
|
|
142
155
|
// public
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
156
|
+
listBuckets() {
|
|
157
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
158
|
+
if (this._configError !== null) {
|
|
159
|
+
return { value: null, error: this.configError };
|
|
160
|
+
}
|
|
161
|
+
return this._listBuckets();
|
|
162
|
+
});
|
|
148
163
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const [arg1, arg2] = args;
|
|
154
|
-
let name;
|
|
155
|
-
if (typeof arg1 !== "string") {
|
|
156
|
-
if (this._bucketName === null) {
|
|
157
|
-
return {
|
|
158
|
-
value: null,
|
|
159
|
-
error: "No bucket selected.",
|
|
160
|
-
};
|
|
164
|
+
createBucket(...args) {
|
|
165
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
166
|
+
if (this._configError !== null) {
|
|
167
|
+
return { value: null, error: this.configError };
|
|
161
168
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
169
|
+
const [arg1, arg2] = args;
|
|
170
|
+
let name;
|
|
171
|
+
if (typeof arg1 !== "string") {
|
|
172
|
+
if (this._bucketName === null) {
|
|
173
|
+
return {
|
|
174
|
+
value: null,
|
|
175
|
+
error: "No bucket selected.",
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
name = this._bucketName;
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
name = arg1;
|
|
182
|
+
const error = (0, util_1.validateName)(name, this.provider);
|
|
183
|
+
if (error !== null) {
|
|
184
|
+
return { value: null, error };
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
const { value, error } = yield this.bucketExists(name);
|
|
167
188
|
if (error !== null) {
|
|
168
189
|
return { value: null, error };
|
|
169
190
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
return
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
return
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
191
|
+
else if (value === true) {
|
|
192
|
+
return { value: null, error: `Bucket '${name}' already exists.` };
|
|
193
|
+
}
|
|
194
|
+
return this._createBucket(name, arg2 || {});
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
clearBucket(name) {
|
|
198
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
199
|
+
const r = yield this.checkBucket(name, true);
|
|
200
|
+
if (r.error !== null) {
|
|
201
|
+
return { value: null, error: r.error };
|
|
202
|
+
}
|
|
203
|
+
name = r.value;
|
|
204
|
+
return this._clearBucket(name);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
deleteBucket(name) {
|
|
208
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
209
|
+
const r = yield this.checkBucket(name, true);
|
|
210
|
+
if (r.error !== null) {
|
|
211
|
+
if (r.error === `No bucket '${name}' found.`) {
|
|
212
|
+
return { value: r.error, error: null };
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
return r;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
name = r.value;
|
|
219
|
+
const data = yield this._clearBucket(name);
|
|
220
|
+
if (data.error !== null) {
|
|
221
|
+
return { value: null, error: data.error };
|
|
222
|
+
}
|
|
223
|
+
const r2 = yield this._deleteBucket(name);
|
|
224
|
+
if (r2.error === null) {
|
|
225
|
+
if (this.selectedBucket === name) {
|
|
226
|
+
this.selectedBucket = null;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return r2;
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
bucketExists(name) {
|
|
233
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
234
|
+
const r = yield this.checkBucket(name, false);
|
|
235
|
+
if (r.error !== null) {
|
|
236
|
+
return { value: null, error: r.error };
|
|
237
|
+
}
|
|
238
|
+
name = r.value;
|
|
239
|
+
return this._bucketExists(name);
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
bucketIsPublic(name) {
|
|
243
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
244
|
+
const r = yield this.checkBucket(name, true);
|
|
245
|
+
if (r.error !== null) {
|
|
246
|
+
return { value: null, error: r.error };
|
|
247
|
+
}
|
|
248
|
+
name = r.value;
|
|
249
|
+
return this._bucketIsPublic(name);
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
listFiles(...args) {
|
|
253
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
254
|
+
const [arg1, arg2] = args;
|
|
255
|
+
let bucketName = undefined;
|
|
256
|
+
let numFiles = 10000;
|
|
257
|
+
if (typeof arg1 === "number") {
|
|
258
|
+
numFiles = arg1;
|
|
259
|
+
}
|
|
260
|
+
else if (typeof arg1 === "string") {
|
|
261
|
+
bucketName = arg1;
|
|
262
|
+
if (typeof arg2 === "number") {
|
|
263
|
+
numFiles = arg2;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const r = yield this.checkBucket(bucketName, true);
|
|
267
|
+
if (r.error) {
|
|
268
|
+
return { value: null, error: r.error };
|
|
269
|
+
}
|
|
270
|
+
// console.log(bucketName, numFiles)
|
|
271
|
+
return this._listFiles(r.value, numFiles);
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
addFileFromPath(params) {
|
|
275
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
276
|
+
return yield this.addFile(params);
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
addFileFromBuffer(params) {
|
|
280
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
281
|
+
return yield this.addFile(params);
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
addFileFromStream(params) {
|
|
285
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
286
|
+
return yield this.addFile(params);
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
addFile(params) {
|
|
290
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
291
|
+
const { bucketName, fileName: _fn, options, error, } = this.getFileAndBucketAndOptions(params.bucketName, params.targetPath, params.options);
|
|
292
|
+
if (error !== null) {
|
|
293
|
+
return { value: null, error: error };
|
|
294
|
+
}
|
|
295
|
+
let checkIfBucketExists = true;
|
|
296
|
+
// console.log(bucketName, _fn, options, error);
|
|
297
|
+
if (typeof options.checkIfBucketExists === "boolean") {
|
|
298
|
+
checkIfBucketExists = options.checkIfBucketExists;
|
|
299
|
+
}
|
|
300
|
+
const r = yield this.checkBucket(bucketName, checkIfBucketExists);
|
|
301
|
+
if (r.error !== null) {
|
|
302
|
+
return { value: null, error: r.error };
|
|
193
303
|
}
|
|
194
304
|
else {
|
|
195
|
-
|
|
305
|
+
params.bucketName = r.value;
|
|
306
|
+
params.options = options === null ? {} : options;
|
|
196
307
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
const r = await this.checkBucket(name, true);
|
|
214
|
-
if (r.error !== null) {
|
|
215
|
-
return { value: null, error: r.error };
|
|
216
|
-
}
|
|
217
|
-
name = r.value;
|
|
218
|
-
return this._bucketIsPublic(name);
|
|
219
|
-
}
|
|
220
|
-
async listFiles(...args) {
|
|
221
|
-
const [arg1, arg2] = args;
|
|
222
|
-
let bucketName;
|
|
223
|
-
let numFiles = 10000;
|
|
224
|
-
if (typeof arg1 === "number") {
|
|
225
|
-
numFiles = arg1;
|
|
226
|
-
}
|
|
227
|
-
else if (typeof arg1 === "string") {
|
|
228
|
-
bucketName = arg1;
|
|
229
|
-
if (typeof arg2 === "number") {
|
|
230
|
-
numFiles = arg2;
|
|
308
|
+
let fh = null;
|
|
309
|
+
if (typeof params.origPath === "string") {
|
|
310
|
+
const f = params.origPath;
|
|
311
|
+
try {
|
|
312
|
+
fh = yield fs_1.default.promises.open(f);
|
|
313
|
+
}
|
|
314
|
+
catch (e) {
|
|
315
|
+
return { value: null, error: (0, util_1.getErrorMessage)(e) };
|
|
316
|
+
}
|
|
317
|
+
const readStream = fs_1.default.createReadStream(f);
|
|
318
|
+
params = {
|
|
319
|
+
bucketName: params.bucketName,
|
|
320
|
+
options: params.options,
|
|
321
|
+
stream: readStream,
|
|
322
|
+
targetPath: params.targetPath,
|
|
323
|
+
};
|
|
231
324
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
return this._listFiles(r.value, numFiles);
|
|
239
|
-
}
|
|
240
|
-
async addFileFromPath(params) {
|
|
241
|
-
return await this.addFile(params);
|
|
242
|
-
}
|
|
243
|
-
async addFileFromBuffer(params) {
|
|
244
|
-
return await this.addFile(params);
|
|
245
|
-
}
|
|
246
|
-
async addFileFromStream(params) {
|
|
247
|
-
return await this.addFile(params);
|
|
248
|
-
}
|
|
249
|
-
async addFile(params) {
|
|
250
|
-
const { bucketName, fileName: _fn, options, error } = this.getFileAndBucketAndOptions(params.bucketName, params.targetPath, params.options);
|
|
251
|
-
if (error !== null) {
|
|
252
|
-
return { value: null, error };
|
|
253
|
-
}
|
|
254
|
-
const r = await this.checkBucket(bucketName);
|
|
255
|
-
if (r.error !== null) {
|
|
256
|
-
return { value: null, error: r.error };
|
|
257
|
-
}
|
|
258
|
-
else {
|
|
259
|
-
params.bucketName = r.value;
|
|
260
|
-
params.options = options === null ? {} : options;
|
|
261
|
-
}
|
|
262
|
-
let fh = null;
|
|
263
|
-
if (typeof params.origPath === "string") {
|
|
264
|
-
const f = params.origPath;
|
|
265
|
-
try {
|
|
266
|
-
fh = await fs_1.default.promises.open(f);
|
|
267
|
-
}
|
|
268
|
-
catch (e) {
|
|
269
|
-
return { value: null, error: e.message };
|
|
270
|
-
}
|
|
271
|
-
const readStream = fs_1.default.createReadStream(f);
|
|
272
|
-
delete params.origPath;
|
|
273
|
-
params.stream = readStream;
|
|
274
|
-
}
|
|
275
|
-
const r2 = await this._addFile(params);
|
|
276
|
-
if (fh !== null) {
|
|
277
|
-
fh.close();
|
|
278
|
-
}
|
|
279
|
-
return r2;
|
|
325
|
+
const r2 = yield this._addFile(params);
|
|
326
|
+
if (fh !== null) {
|
|
327
|
+
fh.close();
|
|
328
|
+
}
|
|
329
|
+
return r2;
|
|
330
|
+
});
|
|
280
331
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
332
|
+
getFileAsStream(...args) {
|
|
333
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
334
|
+
const { bucketName, fileName, options, error } = this.getFileAndBucketAndOptions(...args);
|
|
335
|
+
// console.log(bucketName, fileName, options, error);
|
|
336
|
+
if (error !== null) {
|
|
337
|
+
return { value: null, error: error };
|
|
338
|
+
}
|
|
339
|
+
let checkIfBucketExists = true;
|
|
340
|
+
if (typeof options.checkIfBucketExists === "boolean") {
|
|
341
|
+
checkIfBucketExists = options.checkIfBucketExists;
|
|
342
|
+
}
|
|
343
|
+
const r = yield this.checkBucket(bucketName, checkIfBucketExists);
|
|
344
|
+
if (r.error !== null) {
|
|
345
|
+
return { value: null, error: r.error };
|
|
346
|
+
}
|
|
347
|
+
const r2 = yield this.checkFile(r.value, fileName);
|
|
348
|
+
if (r2.error !== null) {
|
|
349
|
+
return { value: null, error: r2.error };
|
|
350
|
+
}
|
|
351
|
+
return this._getFileAsStream(r.value, fileName, options === null ? {} : options);
|
|
352
|
+
});
|
|
296
353
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
354
|
+
getPublicURL(...args) {
|
|
355
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
356
|
+
const { bucketName, fileName, options: opt, error } = this.getFileAndBucketAndOptions(...args);
|
|
357
|
+
if (error !== null) {
|
|
358
|
+
return { value: null, error: error };
|
|
359
|
+
}
|
|
360
|
+
const r = yield this.checkBucket(bucketName);
|
|
361
|
+
if (r.error !== null) {
|
|
362
|
+
return { value: null, error: r.error };
|
|
363
|
+
}
|
|
364
|
+
const r2 = yield this.checkFile(r.value, fileName);
|
|
365
|
+
if (r2.error !== null) {
|
|
366
|
+
return { value: null, error: r2.error };
|
|
367
|
+
}
|
|
368
|
+
const options = opt === null ? {} : opt;
|
|
369
|
+
if (options.noCheck !== true && this.provider !== general_1.Provider.CUBBIT /*ouch!*/ && this.provider !== general_1.Provider.CLOUDFLARE /*ugly!*/) {
|
|
370
|
+
const result = yield this._bucketIsPublic(bucketName);
|
|
371
|
+
if (result.error !== null) {
|
|
372
|
+
return { value: null, error: result.error };
|
|
373
|
+
}
|
|
374
|
+
if (result.value === false) {
|
|
375
|
+
return { value: null, error: `Bucket "${bucketName}" is not public!` };
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return this._getPublicURL(r.value, fileName, options);
|
|
379
|
+
});
|
|
312
380
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
381
|
+
getSignedURL(...args) {
|
|
382
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
383
|
+
const { bucketName, fileName, options, error } = this.getFileAndBucketAndOptions(...args);
|
|
384
|
+
if (error !== null) {
|
|
385
|
+
return { value: null, error: error };
|
|
386
|
+
}
|
|
387
|
+
const r = yield this.checkBucket(bucketName);
|
|
388
|
+
if (r.error !== null) {
|
|
389
|
+
return { value: null, error: r.error };
|
|
390
|
+
}
|
|
391
|
+
const r2 = yield this.checkFile(r.value, fileName);
|
|
392
|
+
if (r2.error !== null) {
|
|
393
|
+
return { value: null, error: r2.error };
|
|
394
|
+
}
|
|
395
|
+
return this._getSignedURL(r.value, fileName, options === null ? {} : options);
|
|
396
|
+
});
|
|
327
397
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
398
|
+
sizeOf(...args) {
|
|
399
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
400
|
+
const { bucketName, fileName, options: _o, error } = this.getFileAndBucketAndOptions(...args);
|
|
401
|
+
if (error !== null) {
|
|
402
|
+
return { value: null, error: error };
|
|
403
|
+
}
|
|
404
|
+
const r = yield this.checkBucket(bucketName);
|
|
405
|
+
if (r.error !== null) {
|
|
406
|
+
return { value: null, error: r.error };
|
|
407
|
+
}
|
|
408
|
+
const r2 = yield this.checkFile(r.value, fileName);
|
|
409
|
+
if (r2.error !== null) {
|
|
410
|
+
return { value: null, error: r2.error };
|
|
411
|
+
}
|
|
412
|
+
return this._sizeOf(r.value, fileName);
|
|
413
|
+
});
|
|
342
414
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
415
|
+
fileExists(...args) {
|
|
416
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
417
|
+
const { bucketName, fileName, options: _o, error } = this.getFileAndBucketAndOptions(...args);
|
|
418
|
+
if (error !== null) {
|
|
419
|
+
return { value: null, error: error };
|
|
420
|
+
}
|
|
421
|
+
const r = yield this.checkBucket(bucketName);
|
|
422
|
+
if (r.error !== null) {
|
|
423
|
+
return { value: null, error: r.error };
|
|
424
|
+
}
|
|
425
|
+
return this._fileExists(r.value, fileName);
|
|
426
|
+
});
|
|
353
427
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
const r = await this.checkBucket(bucketName);
|
|
360
|
-
if (r.error !== null) {
|
|
361
|
-
return { value: null, error: r.error };
|
|
362
|
-
}
|
|
363
|
-
// check if file exists, this is especially necessary for Backblaze B2 with S3 adapter!
|
|
364
|
-
const r2 = await this.checkFile(r.value, fileName);
|
|
365
|
-
if (r2.error !== null) {
|
|
366
|
-
if (r2.error.startsWith(`No file '${fileName}' found in bucket`)) {
|
|
367
|
-
return { value: r2.error, error: null };
|
|
428
|
+
removeFile(...args) {
|
|
429
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
430
|
+
const { bucketName, fileName, options: _allVersions, error, } = this.getFileAndBucketAndOptions(...args);
|
|
431
|
+
if (error !== null) {
|
|
432
|
+
return { value: null, error: error };
|
|
368
433
|
}
|
|
369
|
-
|
|
370
|
-
|
|
434
|
+
const r = yield this.checkBucket(bucketName);
|
|
435
|
+
if (r.error !== null) {
|
|
436
|
+
return { value: null, error: r.error };
|
|
371
437
|
}
|
|
372
|
-
|
|
373
|
-
|
|
438
|
+
// check if file exists, this is especially necessary for Backblaze B2 with S3 adapter!
|
|
439
|
+
const r2 = yield this.checkFile(r.value, fileName);
|
|
440
|
+
if (r2.error !== null) {
|
|
441
|
+
if (r2.error.startsWith(`No file '${fileName}' found in bucket`)) {
|
|
442
|
+
return { value: r2.error, error: null };
|
|
443
|
+
}
|
|
444
|
+
else {
|
|
445
|
+
return { value: null, error: r2.error };
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
return this._removeFile(bucketName, fileName);
|
|
449
|
+
});
|
|
374
450
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
451
|
+
getPresignedUploadURL(...args) {
|
|
452
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
453
|
+
const { bucketName, fileName, options, error } = this.getFileAndBucketAndOptions(...args);
|
|
454
|
+
if (error !== null) {
|
|
455
|
+
return { value: null, error: error };
|
|
456
|
+
}
|
|
457
|
+
const r = yield this.checkBucket(bucketName);
|
|
458
|
+
if (r.error !== null) {
|
|
459
|
+
return { value: null, error: r.error };
|
|
460
|
+
}
|
|
461
|
+
return this._getPresignedUploadURL(r.value, fileName, options);
|
|
462
|
+
});
|
|
385
463
|
}
|
|
386
464
|
}
|
|
387
465
|
exports.AbstractAdapter = AbstractAdapter;
|