diff --git a/README.md b/README.md index 742f256..2ae859d 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,8 @@ Options: --flatten, -f Flatten filestructure [boolean] [default: false] --dry-run, -n Print a list of which files would be uploaded [boolean] --resumable, -r Resumable upload [boolean] [default: true] - --validation, -V Validation for upload [boolean] [default: true] + --validation, -V Validation for upload [string] [default: md5] + --timeout, -t Upload timeout [string] [default: 60000] --help, -h, -? Show help [boolean] --version, -v Show version number [boolean] ``` diff --git a/index.js b/index.js index 14286ca..ca9c2b5 100755 --- a/index.js +++ b/index.js @@ -54,15 +54,21 @@ const {argv} = require('yargs') }) .option('resumable', { alias: 'r', - describe: 'Resumable upload', - default: true, + describe: 'Force a resumable upload', + default: false, type: 'boolean', }) .option('validation', { alias: 'V', - describe: 'Validation for upload', - default: true, - type: 'boolean', + describe: 'Possible values: "md5", "crc32c", or false. By default, data integrity is validated with an MD5 checksum for maximum reliability', + default: 'md5', + type: 'string', + }) + .option('timeout', { + alias: 't', + describe: 'Set the HTTP request timeout in milliseconds. This option is not available for resumable uploads', + default: '60000', + type: 'string', }) .help() .version() diff --git a/lib/uploader.js b/lib/uploader.js index 41f6dec..cea473a 100644 --- a/lib/uploader.js +++ b/lib/uploader.js @@ -3,11 +3,12 @@ const { Storage } = require('@google-cloud/storage'); const { isDirectory, makeAbsolute, getFilesToUpload } = require('./file-util'); -function uploadToGCS(bucket, cacheControl, validate, resume, asset) { +function uploadToGCS(bucket, cacheControl, validate, resume, timelimit, asset) { const uploadOpt = { destination: asset.destination, validation: validate, resumable: resume, + timeout: timelimit, public: true, gzip: true, metadata: { cacheControl }, @@ -23,6 +24,7 @@ function uploadToCloud(options, assets) { cacheControl, validation, resumable, + timeout, } = options; const storage = new Storage({ @@ -34,7 +36,7 @@ function uploadToCloud(options, assets) { return Promise.all( assets.map(asset => - uploadToGCS(bucket, cacheControl, validation, resumable, asset) + uploadToGCS(bucket, cacheControl, validation, resumable, timeout, asset) ) ); }