@quatrain/storage-supabase 1.1.13 → 1.1.14
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.
|
@@ -11,6 +11,7 @@ export declare class SupabaseStorageAdapter extends AbstractStorageAdapter {
|
|
|
11
11
|
getMetaData(file: FileType): Promise<FileType>;
|
|
12
12
|
test(): Promise<boolean>;
|
|
13
13
|
streamToBuffer(stream: Stream): Promise<Buffer>;
|
|
14
|
+
toArrayBuffer(buffer: Buffer): ArrayBuffer;
|
|
14
15
|
create(file: FileType, stream: Readable | string): Promise<FileType>;
|
|
15
16
|
copy(file: FileType, destFile: FileType): Promise<void>;
|
|
16
17
|
move(file: FileType, destFile: FileType): Promise<FileType>;
|
|
@@ -22,5 +23,13 @@ export declare class SupabaseStorageAdapter extends AbstractStorageAdapter {
|
|
|
22
23
|
getReadable(file: FileType): Promise<Readable>;
|
|
23
24
|
stream(file: FileType, res: any): Promise<any>;
|
|
24
25
|
download(file: FileType, meta: DownloadFileMetaType): Promise<string | Blob>;
|
|
26
|
+
/**
|
|
27
|
+
* Get signed upload url for file
|
|
28
|
+
* Careful, on docker the time to live for JWT signature is defaulted to 60 sec
|
|
29
|
+
* Add SIGNED_UPLOAD_URL_EXPIRATION_TIME env variable to fix TTL
|
|
30
|
+
* @param file FileType
|
|
31
|
+
* @param _expiresIn actually ignored
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
25
34
|
getUploadUrl(file: FileType, _expiresIn?: number): Promise<FileResponseLinkType>;
|
|
26
35
|
}
|
|
@@ -61,12 +61,19 @@ class SupabaseStorageAdapter extends storage_1.AbstractStorageAdapter {
|
|
|
61
61
|
});
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
|
+
toArrayBuffer(buffer) {
|
|
65
|
+
const arrayBuffer = new ArrayBuffer(buffer.length);
|
|
66
|
+
const view = new Uint8Array(arrayBuffer);
|
|
67
|
+
for (let i = 0; i < buffer.length; ++i) {
|
|
68
|
+
view[i] = buffer[i];
|
|
69
|
+
}
|
|
70
|
+
return arrayBuffer;
|
|
71
|
+
}
|
|
64
72
|
create(file, stream) {
|
|
65
73
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
-
|
|
67
|
-
storage_1.Storage.info(`Uploading ${file.ref} to ${file.bucket}`);
|
|
74
|
+
storage_1.Storage.info(`[SSA] Uploading ${file.ref} to ${file.bucket}`);
|
|
68
75
|
if (typeof stream === 'string') {
|
|
69
|
-
const {
|
|
76
|
+
const { error } = yield this._client
|
|
70
77
|
.from(file.bucket)
|
|
71
78
|
.upload(file.ref, new Blob([node_fs_1.default.readFileSync(stream)]), {
|
|
72
79
|
// cacheControl: '3600',
|
|
@@ -74,6 +81,24 @@ class SupabaseStorageAdapter extends storage_1.AbstractStorageAdapter {
|
|
|
74
81
|
contentType: file.contentType,
|
|
75
82
|
});
|
|
76
83
|
if (error !== null) {
|
|
84
|
+
console.log(error);
|
|
85
|
+
storage_1.Storage.error(`Unable to upload ${file.ref} to ${file.bucket}`);
|
|
86
|
+
throw new Error(`Unable to upload ${file.ref} to ${file.bucket}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
const content = new Blob([
|
|
91
|
+
this.toArrayBuffer(yield this.streamToBuffer(stream)),
|
|
92
|
+
]);
|
|
93
|
+
const { error } = yield this._client
|
|
94
|
+
.from(file.bucket)
|
|
95
|
+
.upload(file.ref, content, {
|
|
96
|
+
// cacheControl: '3600',
|
|
97
|
+
upsert: false,
|
|
98
|
+
contentType: file.contentType,
|
|
99
|
+
});
|
|
100
|
+
if (error !== null) {
|
|
101
|
+
console.log(error);
|
|
77
102
|
storage_1.Storage.error(`Unable to upload ${file.ref} to ${file.bucket}`);
|
|
78
103
|
throw new Error(`Unable to upload ${file.ref} to ${file.bucket}`);
|
|
79
104
|
}
|
|
@@ -172,6 +197,14 @@ class SupabaseStorageAdapter extends storage_1.AbstractStorageAdapter {
|
|
|
172
197
|
return meta.path;
|
|
173
198
|
});
|
|
174
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* Get signed upload url for file
|
|
202
|
+
* Careful, on docker the time to live for JWT signature is defaulted to 60 sec
|
|
203
|
+
* Add SIGNED_UPLOAD_URL_EXPIRATION_TIME env variable to fix TTL
|
|
204
|
+
* @param file FileType
|
|
205
|
+
* @param _expiresIn actually ignored
|
|
206
|
+
* @returns
|
|
207
|
+
*/
|
|
175
208
|
getUploadUrl(file, _expiresIn = 7200) {
|
|
176
209
|
return __awaiter(this, void 0, void 0, function* () {
|
|
177
210
|
const { data, error } = yield this._client
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quatrain/storage-supabase",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.14",
|
|
4
4
|
"description": "Storage adapter for Supabase Storage",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@quatrain/core": "^1.1.19",
|
|
26
|
-
"@quatrain/storage": "^1.1.
|
|
26
|
+
"@quatrain/storage": "^1.1.17",
|
|
27
27
|
"@supabase/storage-js": "^2.7.2",
|
|
28
28
|
"@supabase/supabase-js": "^2.45.1"
|
|
29
29
|
},
|