Skip to content

Commit 00b89b7

Browse files
authored
feat: upgrade to latest Google Cloud Storage library (#40)
1 parent 5baee63 commit 00b89b7

File tree

3 files changed

+291
-691
lines changed

3 files changed

+291
-691
lines changed

index.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22
// GCSAdapter
33
// Store Parse Files in Google Cloud Storage: https://cloud.google.com/storage
4-
const storage = require('@google-cloud/storage');
4+
const { Storage } = require('@google-cloud/storage');
55

66
function requiredOrFromEnvironment(options, key, env) {
77
options[key] = options[key] || process.env[env];
@@ -29,7 +29,7 @@ function optionsFromArguments(args) {
2929
options.directAccess = otherOptions.directAccess;
3030
}
3131
} else {
32-
options = Object.assign( {}, projectIdOrOptions);
32+
options = Object.assign({}, projectIdOrOptions);
3333
}
3434
options = fromEnvironmentOrDefault(options, 'projectId', 'GCP_PROJECT_ID', undefined);
3535
options = fromEnvironmentOrDefault(options, 'keyFilename', 'GCP_KEYFILE_PATH', undefined);
@@ -55,14 +55,14 @@ function GCSAdapter() {
5555
this._bucketPrefix = options.bucketPrefix;
5656
this._directAccess = options.directAccess;
5757

58-
this._gcsClient = new storage(options);
58+
this._gcsClient = new Storage(options);
5959
}
6060

61-
GCSAdapter.prototype.createFile = function(filename, data, contentType) {
61+
GCSAdapter.prototype.createFile = function (filename, data, contentType) {
6262
let params = {
6363
metadata: {
6464
contentType: contentType || 'application/octet-stream'
65-
}
65+
}
6666
};
6767

6868
return new Promise((resolve, reject) => {
@@ -89,11 +89,11 @@ GCSAdapter.prototype.createFile = function(filename, data, contentType) {
8989
});
9090
}
9191

92-
GCSAdapter.prototype.deleteFile = function(filename) {
92+
GCSAdapter.prototype.deleteFile = function (filename) {
9393
return new Promise((resolve, reject) => {
9494
let file = this._gcsClient.bucket(this._bucket).file(this._bucketPrefix + filename);
9595
file.delete((err, res) => {
96-
if(err !== null) {
96+
if (err !== null) {
9797
return reject(err);
9898
}
9999
resolve(res);
@@ -103,7 +103,7 @@ GCSAdapter.prototype.deleteFile = function(filename) {
103103

104104
// Search for and return a file if found by filename.
105105
// Returns a promise that succeeds with the buffer result from GCS, or fails with an error.
106-
GCSAdapter.prototype.getFileData = function(filename) {
106+
GCSAdapter.prototype.getFileData = function (filename) {
107107
return new Promise((resolve, reject) => {
108108
let file = this._gcsClient.bucket(this._bucket).file(this._bucketPrefix + filename);
109109
// Check for existence, since gcloud-node seemed to be caching the result
@@ -125,7 +125,7 @@ GCSAdapter.prototype.getFileData = function(filename) {
125125
// Generates and returns the location of a file stored in GCS for the given request and filename.
126126
// The location is the direct GCS link if the option is set,
127127
// otherwise we serve the file through parse-server.
128-
GCSAdapter.prototype.getFileLocation = function(config, filename) {
128+
GCSAdapter.prototype.getFileLocation = function (config, filename) {
129129
if (this._directAccess) {
130130
return `https://storage.googleapis.com/${this._bucket}/${this._bucketPrefix + filename}`;
131131
}

0 commit comments

Comments
 (0)