@rytass/storages-adapter-gcs 0.1.4 → 0.2.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/index.cjs.js +11 -2
- package/package.json +5 -5
- package/storages-adapter-gcs.js +11 -2
package/index.cjs.js
CHANGED
|
@@ -69,22 +69,31 @@ class StorageGCSService extends storages.Storage {
|
|
|
69
69
|
} : {}
|
|
70
70
|
});
|
|
71
71
|
stream$1.pipe(uploadStream).pipe(writeStream1);
|
|
72
|
-
const [filename] = await Promise.all([
|
|
72
|
+
const [[filename, mime]] = await Promise.all([
|
|
73
73
|
getFilenamePromise,
|
|
74
74
|
new Promise((resolve)=>{
|
|
75
75
|
writeStream1.on('finish', resolve);
|
|
76
76
|
}),
|
|
77
77
|
]);
|
|
78
|
+
if (!options?.contentType && mime) {
|
|
79
|
+
await tempFile.setMetadata({
|
|
80
|
+
contentType: mime
|
|
81
|
+
});
|
|
82
|
+
}
|
|
78
83
|
await tempFile.move(filename);
|
|
79
84
|
return {
|
|
80
85
|
key: filename
|
|
81
86
|
};
|
|
82
87
|
}
|
|
83
88
|
async writeBufferFile(buffer, options) {
|
|
84
|
-
const
|
|
89
|
+
const fileInfo = options?.filename || await this.getBufferFilename(buffer);
|
|
90
|
+
const filename = Array.isArray(fileInfo) ? fileInfo[0] : fileInfo;
|
|
85
91
|
const file = this.bucket.file(filename);
|
|
86
92
|
await file.save(buffer, {
|
|
87
93
|
gzip: 'auto',
|
|
94
|
+
...Array.isArray(fileInfo) && fileInfo[1] ? {
|
|
95
|
+
ContentType: fileInfo[1]
|
|
96
|
+
} : {},
|
|
88
97
|
...options?.contentType ? {
|
|
89
98
|
contentType: options?.contentType
|
|
90
99
|
} : {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rytass/storages-adapter-gcs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
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": "^6.
|
|
25
|
-
"@rytass/storages": "^0.
|
|
26
|
-
"uuid": "^
|
|
24
|
+
"@google-cloud/storage": "^6.9.3",
|
|
25
|
+
"@rytass/storages": "^0.2.0",
|
|
26
|
+
"uuid": "^9.0.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@types/uuid": "^
|
|
29
|
+
"@types/uuid": "^9.0.1"
|
|
30
30
|
},
|
|
31
31
|
"main": "./index.cjs.js",
|
|
32
32
|
"module": "./index.js",
|
package/storages-adapter-gcs.js
CHANGED
|
@@ -65,22 +65,31 @@ class StorageGCSService extends Storage {
|
|
|
65
65
|
} : {}
|
|
66
66
|
});
|
|
67
67
|
stream.pipe(uploadStream).pipe(writeStream1);
|
|
68
|
-
const [filename] = await Promise.all([
|
|
68
|
+
const [[filename, mime]] = await Promise.all([
|
|
69
69
|
getFilenamePromise,
|
|
70
70
|
new Promise((resolve)=>{
|
|
71
71
|
writeStream1.on('finish', resolve);
|
|
72
72
|
}),
|
|
73
73
|
]);
|
|
74
|
+
if (!options?.contentType && mime) {
|
|
75
|
+
await tempFile.setMetadata({
|
|
76
|
+
contentType: mime
|
|
77
|
+
});
|
|
78
|
+
}
|
|
74
79
|
await tempFile.move(filename);
|
|
75
80
|
return {
|
|
76
81
|
key: filename
|
|
77
82
|
};
|
|
78
83
|
}
|
|
79
84
|
async writeBufferFile(buffer, options) {
|
|
80
|
-
const
|
|
85
|
+
const fileInfo = options?.filename || await this.getBufferFilename(buffer);
|
|
86
|
+
const filename = Array.isArray(fileInfo) ? fileInfo[0] : fileInfo;
|
|
81
87
|
const file = this.bucket.file(filename);
|
|
82
88
|
await file.save(buffer, {
|
|
83
89
|
gzip: 'auto',
|
|
90
|
+
...Array.isArray(fileInfo) && fileInfo[1] ? {
|
|
91
|
+
ContentType: fileInfo[1]
|
|
92
|
+
} : {},
|
|
84
93
|
...options?.contentType ? {
|
|
85
94
|
contentType: options?.contentType
|
|
86
95
|
} : {}
|