@tweedegolf/sab-adapter-backblaze-b2 1.0.7 → 3.0.0

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/README.md CHANGED
@@ -11,10 +11,10 @@ It is also possible to access all the specific functionality of the cloud servic
11
11
  If you are new to the Storage Abstraction library you may want to read [this](https://github.com/tweedegolf/storage-abstraction/blob/master/README.md#how-it-works) first.
12
12
 
13
13
  ```typescript
14
- import { Storage, StorageType } from "@tweedegolf/storage-abstraction";
14
+ import { Storage, Provider } from "@tweedegolf/storage-abstraction";
15
15
 
16
16
  const configuration = {
17
- type: StorageType.B2,
17
+ type: Provider.B2,
18
18
  applicationKey: "key",
19
19
  applicationKeyId: "keyId",
20
20
  };
@@ -28,13 +28,13 @@ console.log(result);
28
28
 
29
29
  The Storage class is cloud service agnostic and doesn't know anything about the adapter it uses and adapters are completely interchangeable. It only expects the adapter to have implemented all methods of the `IAdapter` interface, see the [API](https://github.com/tweedegolf/storage-abstraction/blob/master/README.md#adapter-api).
30
30
 
31
- When you create a Storage instance it checks the mandatory `type` key in the configuration object and then loads the appropriate adapter module automatically from your node_modules folder using `require()`. For more information please read [this](https://github.com/tweedegolf/storage-abstraction/blob/master/README.md#register-your-adapter).
31
+ When you create a Storage instance it checks the mandatory `provider` key in the configuration object and then loads the appropriate adapter module automatically from your node_modules folder using `require()`. For more information please read [this](https://github.com/tweedegolf/storage-abstraction/blob/master/README.md#register-your-adapter).
32
32
 
33
33
  ## Configuration
34
34
 
35
35
  The configuration object that you pass to the Storage constructor is forwarded to the constructor of the adapter.
36
36
 
37
- The Storage constructor is only interested in the `type` key of the configuration object, all other keys are necessary for configuring the adapter.
37
+ The Storage constructor is only interested in the `provider` key of the configuration object, all other keys are necessary for configuring the adapter.
38
38
 
39
39
  The Storage constructor expects the configuration to be of type `StorageAdapterConfig`.
40
40
 
@@ -66,13 +66,13 @@ Examples with configuration object:
66
66
 
67
67
  ```typescript
68
68
  const s = new Storage({
69
- type: StorageType.B2,
69
+ type: Provider.B2,
70
70
  applicationKeyId: "your-key-id",
71
71
  applicationKey: "your-key",
72
72
  });
73
73
 
74
74
  const s = new Storage({
75
- type: StorageType.B2,
75
+ type: Provider.B2,
76
76
  applicationKeyId: "your-key-id",
77
77
  applicationKey: "your-key",
78
78
  bucketName: "the-buck",
package/changelog.md CHANGED
@@ -1,3 +1,12 @@
1
+ # 3.0.0
2
+ - version bump to match the version of Storage and the API
3
+ - removed support for versioning (wasn't implemented consistently anyway)
4
+ - removed `getFileAsURL`
5
+ - removed option `{allVersions: boolean}` for `removeFile`
6
+ - `removeFile` does not fail if the file doesn't exist
7
+ - `deleteBucket` does not fail if the bucket doesn't exist
8
+ - see also the [migration guide](https://github.com/tweedegolf/storage-abstraction/blob/master/migration_to_api3.0.md)
9
+
1
10
  # 1.0.7
2
11
  - include @deprecated functions
3
12
 
@@ -1,15 +1,15 @@
1
- import { AdapterConfig, IAdapter, Options, StreamOptions } from "./types/general";
1
+ import { AdapterConfig, IAdapter, Options, Provider, StreamOptions } from "./types/general";
2
2
  import { FileBufferParams, FilePathParams, FileStreamParams } from "./types/add_file_params";
3
- import { ResultObject, ResultObjectBoolean, ResultObjectBuckets, ResultObjectFiles, ResultObjectNumber, ResultObjectStream } from "./types/result";
3
+ import { ResultObject, ResultObjectBoolean, ResultObjectBuckets, ResultObjectFiles, ResultObjectNumber, ResultObjectObject, ResultObjectStream } from "./types/result";
4
4
  export declare abstract class AbstractAdapter implements IAdapter {
5
- protected _type: string;
5
+ protected _provider: Provider;
6
6
  protected _config: AdapterConfig | null;
7
7
  protected _configError: string | null;
8
8
  protected _bucketName: string;
9
9
  protected _client: any;
10
10
  constructor(config: string | AdapterConfig);
11
- get type(): string;
12
- getType(): string;
11
+ get provider(): Provider;
12
+ getProvider(): Provider;
13
13
  get config(): AdapterConfig;
14
14
  getConfig(): AdapterConfig;
15
15
  get configError(): string;
@@ -22,24 +22,9 @@ export declare abstract class AbstractAdapter implements IAdapter {
22
22
  get selectedBucket(): string | null;
23
23
  set bucketName(bucketName: string | null);
24
24
  get bucketName(): string | null;
25
- addFileFromPath(params: FilePathParams): Promise<ResultObject>;
26
- addFileFromBuffer(params: FileBufferParams): Promise<ResultObject>;
27
- addFileFromStream(params: FileStreamParams): Promise<ResultObject>;
28
- protected _getFileAndBucketAndOptions(...args: [
29
- bucketName: string,
30
- fileName: string,
31
- options?: boolean | Options | StreamOptions
32
- ] | [
33
- fileName: string,
34
- options?: boolean | Options | StreamOptions
35
- ] | [
36
- options: boolean | Options | StreamOptions
37
- ]): {
38
- bucketName: string;
39
- fileName: string;
40
- options: object | boolean;
41
- error: string;
42
- };
25
+ private getFileAndBucketAndOptions;
26
+ private checkBucket;
27
+ private checkFile;
43
28
  protected abstract _listBuckets(): Promise<ResultObjectBuckets>;
44
29
  protected abstract _createBucket(name: string, options: Options): Promise<ResultObject>;
45
30
  protected abstract _clearBucket(name: string): Promise<ResultObject>;
@@ -51,10 +36,10 @@ export declare abstract class AbstractAdapter implements IAdapter {
51
36
  protected abstract _addFile(params: FilePathParams | FileBufferParams | FileStreamParams): Promise<ResultObject>;
52
37
  protected abstract _fileExists(bucketName: string, fileName: string): Promise<ResultObjectBoolean>;
53
38
  protected abstract _getFileAsStream(bucketName: string, fileName: string, options: StreamOptions): Promise<ResultObjectStream>;
54
- protected abstract _getFileAsURL(bucketName: string, fileName: string, options: Options): Promise<ResultObject>;
55
39
  protected abstract _getPublicURL(bucketName: string, fileName: string, options: Options): Promise<ResultObject>;
56
40
  protected abstract _getSignedURL(bucketName: string, fileName: string, options: Options): Promise<ResultObject>;
57
- protected abstract _removeFile(bucketName: string, fileName: string, allVersions: boolean): Promise<ResultObject>;
41
+ protected abstract _removeFile(bucketName: string, fileName: string): Promise<ResultObject>;
42
+ protected abstract _getPresignedUploadURL(bucketName: string, fileName: string, options: Options): Promise<ResultObjectObject>;
58
43
  listBuckets(): Promise<ResultObjectBuckets>;
59
44
  createBucket(...args: [
60
45
  bucketName?: string,
@@ -74,6 +59,9 @@ export declare abstract class AbstractAdapter implements IAdapter {
74
59
  ] | [
75
60
  bucketName?: string
76
61
  ]): Promise<ResultObjectFiles>;
62
+ addFileFromPath(params: FilePathParams): Promise<ResultObject>;
63
+ addFileFromBuffer(params: FileBufferParams): Promise<ResultObject>;
64
+ addFileFromStream(params: FileStreamParams): Promise<ResultObject>;
77
65
  addFile(params: FilePathParams | FileBufferParams | FileStreamParams): Promise<ResultObject>;
78
66
  getFileAsStream(...args: [
79
67
  bucketName: string,
@@ -83,17 +71,6 @@ export declare abstract class AbstractAdapter implements IAdapter {
83
71
  fileName: string,
84
72
  options?: StreamOptions
85
73
  ]): Promise<ResultObjectStream>;
86
- /**
87
- * @deprecated: please use getPublicURL or getSignedURL
88
- */
89
- getFileAsURL(...args: [
90
- bucketName: string,
91
- fileName: string,
92
- options?: Options
93
- ] | [
94
- fileName: string,
95
- options?: Options
96
- ]): Promise<ResultObject>;
97
74
  getPublicURL(...args: [
98
75
  bucketName: string,
99
76
  fileName: string,
@@ -123,11 +100,17 @@ export declare abstract class AbstractAdapter implements IAdapter {
123
100
  fileName: string
124
101
  ]): Promise<ResultObjectBoolean>;
125
102
  removeFile(...args: [
103
+ bucketName: string,
104
+ fileName: string
105
+ ] | [
106
+ fileName: string
107
+ ]): Promise<ResultObject>;
108
+ getPresignedUploadURL(...args: [
126
109
  bucketName: string,
127
110
  fileName: string,
128
- allVersions?: boolean
111
+ options?: Options
129
112
  ] | [
130
113
  fileName: string,
131
- allVersions?: boolean
132
- ]): Promise<ResultObject>;
114
+ options?: Options
115
+ ]): Promise<ResultObjectObject>;
133
116
  }
@@ -1,19 +1,24 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.AbstractAdapter = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const general_1 = require("./types/general");
4
9
  const util_1 = require("./util");
5
10
  class AbstractAdapter {
6
11
  constructor(config) {
7
- this._type = "abstract-adapter";
12
+ this._provider = general_1.Provider.NONE;
8
13
  this._configError = null;
9
14
  this._bucketName = null;
10
15
  this._client = null; // eslint-disable-line
11
16
  }
12
- get type() {
13
- return this._type;
17
+ get provider() {
18
+ return this._provider;
14
19
  }
15
- getType() {
16
- return this.type;
20
+ getProvider() {
21
+ return this.provider;
17
22
  }
18
23
  get config() {
19
24
  return this._config;
@@ -53,18 +58,9 @@ class AbstractAdapter {
53
58
  get bucketName() {
54
59
  return this._bucketName;
55
60
  }
56
- async addFileFromPath(params) {
57
- return await this.addFile(params);
58
- }
59
- async addFileFromBuffer(params) {
60
- return await this.addFile(params);
61
- }
62
- async addFileFromStream(params) {
63
- return await this.addFile(params);
64
- }
65
- _getFileAndBucketAndOptions(...args) {
61
+ getFileAndBucketAndOptions(...args) {
66
62
  const [arg1, arg2, arg3] = args;
67
- // console.log("_getFileAndBucketAndOptions", arg1, arg2, arg3);
63
+ // console.log("getFileAndBucketAndOptions", arg1, arg2, arg3);
68
64
  let bucketName = null;
69
65
  let fileName = null;
70
66
  let options = {};
@@ -109,6 +105,40 @@ class AbstractAdapter {
109
105
  return { bucketName, fileName, options, error: "Please provide a filename" };
110
106
  }
111
107
  }
108
+ async checkBucket(name, checkIfExists = true) {
109
+ if (this._configError !== null) {
110
+ return { value: null, error: this.configError };
111
+ }
112
+ if (typeof name === "undefined") {
113
+ if (this._bucketName === null) {
114
+ return {
115
+ value: null,
116
+ error: "No bucket selected.",
117
+ };
118
+ }
119
+ name = this._bucketName;
120
+ }
121
+ if (checkIfExists === true) {
122
+ const { value, error } = await this._bucketExists(name);
123
+ if (error !== null) {
124
+ return { value: null, error };
125
+ }
126
+ else if (value === false) {
127
+ return { value: null, error: `No bucket '${name}' found.` };
128
+ }
129
+ }
130
+ return { value: name, error: null };
131
+ }
132
+ async checkFile(bucketName, fileName) {
133
+ const r = await this._fileExists(bucketName, fileName);
134
+ if (r.error) {
135
+ return { value: null, error: r.error };
136
+ }
137
+ if (r.value === false) {
138
+ return { value: null, error: `No file '${fileName}' found in bucket '${bucketName}'` };
139
+ }
140
+ return { value: null, error: null };
141
+ }
112
142
  // public
113
143
  async listBuckets() {
114
144
  if (this._configError !== null) {
@@ -121,94 +151,77 @@ class AbstractAdapter {
121
151
  return { value: null, error: this.configError };
122
152
  }
123
153
  const [arg1, arg2] = args;
124
- let bucketName;
154
+ let name;
125
155
  if (typeof arg1 !== "string") {
126
156
  if (this._bucketName === null) {
127
157
  return {
128
158
  value: null,
129
- error: "no bucket selected",
159
+ error: "No bucket selected.",
130
160
  };
131
161
  }
132
- bucketName = this._bucketName;
162
+ name = this._bucketName;
133
163
  }
134
164
  else {
135
- bucketName = arg1;
136
- const error = (0, util_1.validateName)(bucketName);
165
+ name = arg1;
166
+ const error = (0, util_1.validateName)(name, this.provider);
137
167
  if (error !== null) {
138
168
  return { value: null, error };
139
169
  }
140
170
  }
141
- return this._createBucket(bucketName, arg2 || {});
171
+ const { value, error } = await this.bucketExists(name);
172
+ if (error !== null) {
173
+ return { value: null, error };
174
+ }
175
+ else if (value === true) {
176
+ return { value: null, error: `Bucket '${name}' already exists.` };
177
+ }
178
+ return this._createBucket(name, arg2 || {});
142
179
  }
143
180
  async clearBucket(name) {
144
- if (this._configError !== null) {
145
- return { value: null, error: this.configError };
146
- }
147
- if (typeof name === "undefined") {
148
- if (this._bucketName === null) {
149
- return {
150
- value: null,
151
- error: "no bucket selected",
152
- };
153
- }
154
- name = this._bucketName;
181
+ const r = await this.checkBucket(name, true);
182
+ if (r.error !== null) {
183
+ return { value: null, error: r.error };
155
184
  }
185
+ name = r.value;
156
186
  return this._clearBucket(name);
157
187
  }
158
188
  async deleteBucket(name) {
159
- if (this._configError !== null) {
160
- return { value: null, error: this.configError };
161
- }
162
- if (typeof name === "undefined") {
163
- if (this._bucketName === null) {
164
- return {
165
- value: null,
166
- error: "no bucket selected",
167
- };
189
+ const r = await this.checkBucket(name, true);
190
+ if (r.error !== null) {
191
+ if (r.error === `No bucket '${name}' found.`) {
192
+ return { value: r.error, error: null };
193
+ }
194
+ else {
195
+ return r;
168
196
  }
169
- name = this._bucketName;
170
197
  }
198
+ name = r.value;
171
199
  if (this.selectedBucket === name) {
172
200
  this.selectedBucket = null;
173
201
  }
174
202
  return this._deleteBucket(name);
175
203
  }
176
204
  async bucketExists(name) {
177
- if (this._configError !== null) {
178
- return { value: null, error: this.configError };
179
- }
180
- if (typeof name === "undefined") {
181
- if (this._bucketName === null) {
182
- return { value: null, error: "no bucket selected" };
183
- }
184
- name = this._bucketName;
205
+ const r = await this.checkBucket(name, false);
206
+ if (r.error !== null) {
207
+ return { value: null, error: r.error };
185
208
  }
209
+ name = r.value;
186
210
  return this._bucketExists(name);
187
211
  }
188
212
  async bucketIsPublic(name) {
189
- if (this._configError !== null) {
190
- return { value: null, error: this.configError };
191
- }
192
- if (typeof name === "undefined") {
193
- if (this._bucketName === null) {
194
- return { value: null, error: "no bucket selected" };
195
- }
196
- name = this._bucketName;
213
+ const r = await this.checkBucket(name, true);
214
+ if (r.error !== null) {
215
+ return { value: null, error: r.error };
197
216
  }
217
+ name = r.value;
198
218
  return this._bucketIsPublic(name);
199
219
  }
200
220
  async listFiles(...args) {
201
- if (this._configError !== null) {
202
- return { value: null, error: this.configError };
203
- }
204
221
  const [arg1, arg2] = args;
205
222
  let bucketName;
206
223
  let numFiles = 10000;
207
224
  if (typeof arg1 === "number") {
208
- if (this._bucketName === null) {
209
- return { value: null, error: "no bucket selected" };
210
- }
211
- bucketName = this._bucketName;
212
225
  numFiles = arg1;
213
226
  }
214
227
  else if (typeof arg1 === "string") {
@@ -217,115 +230,158 @@ class AbstractAdapter {
217
230
  numFiles = arg2;
218
231
  }
219
232
  }
220
- else {
221
- if (this._bucketName === null) {
222
- return { value: null, error: "no bucket selected" };
223
- }
224
- bucketName = this._bucketName;
233
+ const r = await this.checkBucket(bucketName, true);
234
+ if (r.error) {
235
+ return { value: null, error: r.error };
225
236
  }
226
- return this._listFiles(bucketName, numFiles);
237
+ // console.log(bucketName, numFiles)
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);
227
248
  }
228
249
  async addFile(params) {
229
- if (this._configError !== null) {
230
- return { value: null, error: this.configError };
231
- }
232
- const { bucketName, fileName: _fn, options, error } = this._getFileAndBucketAndOptions(params.bucketName, params.targetPath, params.options);
250
+ const { bucketName, fileName: _fn, options, error } = this.getFileAndBucketAndOptions(params.bucketName, params.targetPath, params.options);
233
251
  if (error !== null) {
234
252
  return { value: null, error };
235
253
  }
236
- params.bucketName = bucketName;
237
- params.options = options === null ? {} : options;
238
- return this._addFile(params);
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;
239
280
  }
240
281
  async getFileAsStream(...args) {
241
- if (this.configError !== null) {
242
- return { error: this.configError, value: null };
243
- }
244
- const { bucketName, fileName, options, error } = this._getFileAndBucketAndOptions(...args);
282
+ const { bucketName, fileName, options, error } = this.getFileAndBucketAndOptions(...args);
245
283
  // console.log(bucketName, fileName, options, error);
246
284
  if (error !== null) {
247
285
  return { error, value: null };
248
286
  }
249
- return this._getFileAsStream(bucketName, fileName, options === null ? {} : options);
250
- }
251
- /**
252
- * @deprecated: please use getPublicURL or getSignedURL
253
- */
254
- async getFileAsURL(...args) {
255
- if (this._configError !== null) {
256
- return { value: null, error: this.configError };
287
+ const r = await this.checkBucket(bucketName);
288
+ if (r.error !== null) {
289
+ return { value: null, error: r.error };
257
290
  }
258
- const { bucketName, fileName, options, error } = this._getFileAndBucketAndOptions(...args);
259
- if (error !== null) {
260
- return { error, value: null };
291
+ const r2 = await this.checkFile(r.value, fileName);
292
+ if (r2.error !== null) {
293
+ return { value: null, error: r2.error };
261
294
  }
262
- return this._getFileAsURL(bucketName, fileName, options === null ? {} : options);
295
+ return this._getFileAsStream(r.value, fileName, options === null ? {} : options);
263
296
  }
264
297
  async getPublicURL(...args) {
265
- const { bucketName, fileName, options: opt, error } = this._getFileAndBucketAndOptions(...args);
298
+ const { bucketName, fileName, options: opt, error } = this.getFileAndBucketAndOptions(...args);
266
299
  if (error !== null) {
267
300
  return { error, value: null };
268
301
  }
302
+ const r = await this.checkBucket(bucketName);
303
+ if (r.error !== null) {
304
+ return { value: null, error: r.error };
305
+ }
306
+ const r2 = await this.checkFile(r.value, fileName);
307
+ if (r2.error !== null) {
308
+ return { value: null, error: r2.error };
309
+ }
269
310
  const options = opt === null ? {} : opt;
270
- return this._getPublicURL(bucketName, fileName, options);
311
+ return this._getPublicURL(r.value, fileName, options);
271
312
  }
272
313
  async getSignedURL(...args) {
273
- const { bucketName, fileName, options, error } = this._getFileAndBucketAndOptions(...args);
314
+ const { bucketName, fileName, options, error } = this.getFileAndBucketAndOptions(...args);
274
315
  if (error !== null) {
275
316
  return { error, value: null };
276
317
  }
277
- return this._getSignedURL(bucketName, fileName, options === null ? {} : options);
318
+ const r = await this.checkBucket(bucketName);
319
+ if (r.error !== null) {
320
+ return { value: null, error: r.error };
321
+ }
322
+ const r2 = await this.checkFile(r.value, fileName);
323
+ if (r2.error !== null) {
324
+ return { value: null, error: r2.error };
325
+ }
326
+ return this._getSignedURL(r.value, fileName, options === null ? {} : options);
278
327
  }
279
328
  async sizeOf(...args) {
280
- if (this.configError !== null) {
281
- return { value: null, error: this.configError };
282
- }
283
- const { bucketName, fileName, options: _o, error } = this._getFileAndBucketAndOptions(...args);
329
+ const { bucketName, fileName, options: _o, error } = this.getFileAndBucketAndOptions(...args);
284
330
  if (error !== null) {
285
331
  return { value: null, error };
286
332
  }
287
- return this._sizeOf(bucketName, fileName);
333
+ const r = await this.checkBucket(bucketName);
334
+ if (r.error !== null) {
335
+ return { value: null, error: r.error };
336
+ }
337
+ const r2 = await this.checkFile(r.value, fileName);
338
+ if (r2.error !== null) {
339
+ return { value: null, error: r2.error };
340
+ }
341
+ return this._sizeOf(r.value, fileName);
288
342
  }
289
343
  async fileExists(...args) {
290
- if (this.configError !== null) {
291
- return { value: null, error: this.configError };
292
- }
293
- const { bucketName, fileName, options: _o, error } = this._getFileAndBucketAndOptions(...args);
344
+ const { bucketName, fileName, options: _o, error } = this.getFileAndBucketAndOptions(...args);
294
345
  if (error !== null) {
295
346
  return { value: null, error };
296
347
  }
297
- return this._fileExists(bucketName, fileName);
348
+ const r = await this.checkBucket(bucketName);
349
+ if (r.error !== null) {
350
+ return { value: null, error: r.error };
351
+ }
352
+ return this._fileExists(r.value, fileName);
298
353
  }
299
354
  async removeFile(...args) {
300
- if (this.configError !== null) {
301
- return { value: null, error: this.configError };
302
- }
303
- if (this.configError !== null) {
304
- return { value: null, error: this.configError };
305
- }
306
- const { bucketName, fileName, options: allVersions, error } = this._getFileAndBucketAndOptions(...args);
355
+ const { bucketName, fileName, options: _allVersions, error } = this.getFileAndBucketAndOptions(...args);
307
356
  if (error !== null) {
308
357
  return { error, value: null };
309
358
  }
310
- /*
311
- let r = await this.bucketExists(bucketName);
312
- if (r.error) {
313
- return { value: null, error: r.error }
314
- }
315
- if (r.value === false) {
316
- return { value: null, error: `No bucket '${bucketName}' found` }
317
- }
318
-
319
- // check if file exists, this is especially necessary for Backblaze B2 with S3 adapter!
320
- r = await this.fileExists(bucketName, fileName);
321
- if (r.error) {
322
- return { value: null, error: r.error }
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 };
323
368
  }
324
- if (r.value === false) {
325
- return { value: null, error: `No file '${fileName}' found in bucket '${bucketName}'` }
369
+ else {
370
+ return { value: null, error: r2.error };
326
371
  }
327
- */
328
- return this._removeFile(bucketName, fileName, allVersions === null ? false : allVersions);
372
+ }
373
+ return this._removeFile(bucketName, fileName);
374
+ }
375
+ async getPresignedUploadURL(...args) {
376
+ const { bucketName, fileName, options, error } = this.getFileAndBucketAndOptions(...args);
377
+ if (error !== null) {
378
+ return { value: null, error };
379
+ }
380
+ const r = await this.checkBucket(bucketName);
381
+ if (r.error !== null) {
382
+ return { value: null, error: r.error };
383
+ }
384
+ return this._getPresignedUploadURL(r.value, fileName, options);
329
385
  }
330
386
  }
331
387
  exports.AbstractAdapter = AbstractAdapter;