@8ms/helpers 1.1.91 → 1.1.92
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.
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare type CopyToCloud = {
|
|
2
|
+
bucket: string;
|
|
3
|
+
data: any;
|
|
4
|
+
localFile: string;
|
|
5
|
+
key: string;
|
|
6
|
+
[options: string]: any;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Copy a local file to Google Cloud Storage.
|
|
10
|
+
*/
|
|
11
|
+
export declare const copyToCloud: ({ bucket, localFile, ...options }: CopyToCloud) => Promise<any>;
|
|
12
|
+
export default copyToCloud;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.copyToCloud = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Copy a local file to Google Cloud Storage.
|
|
6
|
+
*/
|
|
7
|
+
const copyToCloud = async ({ bucket, localFile, ...options }) => {
|
|
8
|
+
const bucketInstance = global.googleStorageClient.bucket(bucket);
|
|
9
|
+
const apiResponse = bucketInstance.upload(localFile, options);
|
|
10
|
+
return apiResponse;
|
|
11
|
+
};
|
|
12
|
+
exports.copyToCloud = copyToCloud;
|
|
13
|
+
exports.default = exports.copyToCloud;
|
|
@@ -2,10 +2,10 @@ declare type WriteFile = {
|
|
|
2
2
|
bucket: string;
|
|
3
3
|
data: any;
|
|
4
4
|
key: string;
|
|
5
|
-
|
|
5
|
+
[options: string]: any;
|
|
6
6
|
};
|
|
7
7
|
/**
|
|
8
8
|
* Write a file to Google Cloud Storage.
|
|
9
9
|
*/
|
|
10
|
-
export declare const writeFile: ({ bucket, data, key,
|
|
10
|
+
export declare const writeFile: ({ bucket, contentType, data, key, ...options }: WriteFile) => Promise<any>;
|
|
11
11
|
export default writeFile;
|
|
@@ -4,7 +4,7 @@ exports.writeFile = void 0;
|
|
|
4
4
|
/**
|
|
5
5
|
* Write a file to Google Cloud Storage.
|
|
6
6
|
*/
|
|
7
|
-
const writeFile = async ({ bucket, data, key,
|
|
7
|
+
const writeFile = async ({ bucket, contentType, data, key, ...options }) => {
|
|
8
8
|
const stream = require('stream');
|
|
9
9
|
const dataStream = new stream.PassThrough();
|
|
10
10
|
const googleFile = global.googleStorageClient.bucket(bucket)
|
|
@@ -16,13 +16,13 @@ const writeFile = async ({ bucket, data, key, metadata }) => {
|
|
|
16
16
|
contentType: 'auto',
|
|
17
17
|
resumable: false,
|
|
18
18
|
validation: false,
|
|
19
|
-
metadata:
|
|
19
|
+
metadata: {},
|
|
20
|
+
...options,
|
|
20
21
|
}))
|
|
21
22
|
.on('error', (error) => {
|
|
22
23
|
reject(error);
|
|
23
24
|
})
|
|
24
25
|
.on('finish', () => {
|
|
25
|
-
// console.log(`File uploaded successfully.`);
|
|
26
26
|
resolve(true);
|
|
27
27
|
});
|
|
28
28
|
});
|