@rytass/storages-adapter-gcs 0.2.1 → 0.2.3
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/index.cjs.js +6 -6
- package/package.json +4 -4
- package/storages-adapter-gcs.d.ts +0 -2
- package/storages-adapter-gcs.js +6 -4
package/index.cjs.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var storages = require('@rytass/storages');
|
|
6
4
|
var stream = require('stream');
|
|
7
5
|
var uuid = require('uuid');
|
|
8
6
|
var storage = require('@google-cloud/storage');
|
|
9
7
|
|
|
10
8
|
class StorageGCSService extends storages.Storage {
|
|
9
|
+
storage;
|
|
10
|
+
bucket;
|
|
11
11
|
constructor(options){
|
|
12
12
|
super(options);
|
|
13
13
|
this.storage = new storage.Storage({
|
|
@@ -62,18 +62,18 @@ class StorageGCSService extends storages.Storage {
|
|
|
62
62
|
const uploadStream = new stream.PassThrough();
|
|
63
63
|
const getFilenamePromise = this.getStreamFilename(stream$1);
|
|
64
64
|
const tempFile = this.bucket.file(tempFilename);
|
|
65
|
-
const
|
|
65
|
+
const writeStream = tempFile.createWriteStream({
|
|
66
66
|
gzip: 'auto',
|
|
67
67
|
...options?.contentType ? {
|
|
68
68
|
contentType: options?.contentType
|
|
69
69
|
} : {}
|
|
70
70
|
});
|
|
71
|
-
stream$1.pipe(uploadStream).pipe(
|
|
71
|
+
stream$1.pipe(uploadStream).pipe(writeStream);
|
|
72
72
|
const [[filename, mime]] = await Promise.all([
|
|
73
73
|
getFilenamePromise,
|
|
74
74
|
new Promise((resolve)=>{
|
|
75
|
-
|
|
76
|
-
})
|
|
75
|
+
writeStream.on('finish', resolve);
|
|
76
|
+
})
|
|
77
77
|
]);
|
|
78
78
|
if (!options?.contentType && mime) {
|
|
79
79
|
await tempFile.setMetadata({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rytass/storages-adapter-gcs",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Google Cloud Storage Adapter for @rytass/storages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"gcp",
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
"url": "https://github.com/Rytass/Utils/issues"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@google-cloud/storage": "^
|
|
24
|
+
"@google-cloud/storage": "^7.12.0",
|
|
25
25
|
"@rytass/storages": "^0.2.0",
|
|
26
|
-
"uuid": "^
|
|
26
|
+
"uuid": "^10.0.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@types/uuid": "^
|
|
29
|
+
"@types/uuid": "^10.0.0"
|
|
30
30
|
},
|
|
31
31
|
"main": "./index.cjs.js",
|
|
32
32
|
"module": "./index.js",
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
1
|
import { Storage, ReadBufferFileOptions, ReadStreamFileOptions, InputFile, StorageFile, WriteFileOptions } from '@rytass/storages';
|
|
4
2
|
import { Readable } from 'stream';
|
|
5
3
|
import { GCSOptions } from './typings';
|
package/storages-adapter-gcs.js
CHANGED
|
@@ -4,6 +4,8 @@ import { v4 } from 'uuid';
|
|
|
4
4
|
import { Storage as Storage$1 } from '@google-cloud/storage';
|
|
5
5
|
|
|
6
6
|
class StorageGCSService extends Storage {
|
|
7
|
+
storage;
|
|
8
|
+
bucket;
|
|
7
9
|
constructor(options){
|
|
8
10
|
super(options);
|
|
9
11
|
this.storage = new Storage$1({
|
|
@@ -58,18 +60,18 @@ class StorageGCSService extends Storage {
|
|
|
58
60
|
const uploadStream = new PassThrough();
|
|
59
61
|
const getFilenamePromise = this.getStreamFilename(stream);
|
|
60
62
|
const tempFile = this.bucket.file(tempFilename);
|
|
61
|
-
const
|
|
63
|
+
const writeStream = tempFile.createWriteStream({
|
|
62
64
|
gzip: 'auto',
|
|
63
65
|
...options?.contentType ? {
|
|
64
66
|
contentType: options?.contentType
|
|
65
67
|
} : {}
|
|
66
68
|
});
|
|
67
|
-
stream.pipe(uploadStream).pipe(
|
|
69
|
+
stream.pipe(uploadStream).pipe(writeStream);
|
|
68
70
|
const [[filename, mime]] = await Promise.all([
|
|
69
71
|
getFilenamePromise,
|
|
70
72
|
new Promise((resolve)=>{
|
|
71
|
-
|
|
72
|
-
})
|
|
73
|
+
writeStream.on('finish', resolve);
|
|
74
|
+
})
|
|
73
75
|
]);
|
|
74
76
|
if (!options?.contentType && mime) {
|
|
75
77
|
await tempFile.setMetadata({
|