google-cloud-bucket
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -5,2 +5,12 @@ # Change Log | ||
<a name="0.1.2"></a> | ||
## [0.1.2](https://github.com/nicolasdao/google-cloud-bucket/compare/v0.1.1...v0.1.2) (2018-11-25) | ||
### Features | ||
* Add support for custom headers ([51eb3b3](https://github.com/nicolasdao/google-cloud-bucket/commit/51eb3b3)) | ||
<a name="0.1.1"></a> | ||
@@ -7,0 +17,0 @@ ## [0.1.1](https://github.com/nicolasdao/google-cloud-bucket/compare/v0.1.0...v0.1.1) (2018-11-21) |
@@ -60,3 +60,3 @@ /** | ||
const putObject = (object, filePath) => getToken(auth).then(token => gcp.insert(object, filePath, token)) | ||
const putObject = (object, filePath, options) => getToken(auth).then(token => gcp.insert(object, filePath, token, options)) | ||
const getObject = (bucket, filePath) => getToken(auth).then(token => gcp.get(bucket, filePath, token)) | ||
@@ -68,3 +68,3 @@ const makePublic = filePath => getToken(auth).then(token => { | ||
const retryPutObject = (object, filePath, options={}) => _retryFn(() => putObject(object, filePath), options) | ||
const retryPutObject = (object, filePath, options={}) => _retryFn(() => putObject(object, filePath, options), options) | ||
.then(res => { | ||
@@ -71,0 +71,0 @@ if (options.public) |
{ | ||
"name": "google-cloud-bucket", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Nodejs package to add objects to a Google Cloud Bucket.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -9,4 +9,9 @@ /** | ||
const { fetch, urlHelper } = require('./utils') | ||
// Uploading data: https://cloud.google.com/storage/docs/json_api/v1/how-tos/upload | ||
// Best practices: https://cloud.google.com/storage/docs/json_api/v1/how-tos/performance | ||
// Object versioning: https://cloud.google.com/storage/docs/object-versioning | ||
const { fetch, urlHelper, obj: { merge } } = require('./utils') | ||
const BUCKET_UPLOAD_URL = (bucket, fileName) => `https://www.googleapis.com/upload/storage/v1/b/${encodeURIComponent(bucket)}/o?uploadType=media&name=${encodeURIComponent(fileName)}` | ||
@@ -21,3 +26,3 @@ const BUCKET_URL = bucket => `https://www.googleapis.com/storage/v1/b/${encodeURIComponent(bucket)}` | ||
const putObject = (object, filePath, token) => Promise.resolve(null).then(() => { | ||
const putObject = (object, filePath, token, options={}) => Promise.resolve(null).then(() => { | ||
_validateRequiredParams({ object, filePath, token }) | ||
@@ -29,7 +34,11 @@ const payload = typeof(object) == 'string' ? object : JSON.stringify(object || {}) | ||
return fetch.post(BUCKET_UPLOAD_URL(bucket, names.join('/')), { | ||
'Content-Type': contentType || 'application/json', | ||
let headers = merge(options.headers || {}, { | ||
'Content-Length': payload.length, | ||
Authorization: `Bearer ${token}` | ||
}, payload) | ||
}) | ||
if (!headers['Content-Type']) | ||
headers['Content-Type'] = contentType || 'application/json' | ||
return fetch.post(BUCKET_UPLOAD_URL(bucket, names.join('/')), headers, payload) | ||
}) | ||
@@ -36,0 +45,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
36665
779
7