@infurnia/backend-file-storage
Advanced tools
Comparing version 2.1.0 to 2.2.0
29
index.js
@@ -52,4 +52,4 @@ const utils = require('./utils'); | ||
try{ | ||
let files_list = await gcs_client.list_files_in_bucket(this.bucket_name, directory); | ||
return files_list[0].map(x=> x.name); | ||
let files_list = await this.gcs_client.list_files_in_bucket(this.bucket_name, directory); | ||
return files_list[0]; | ||
} | ||
@@ -68,3 +68,3 @@ catch(err){ | ||
destinationPath = clean_file_path(destinationPath); | ||
await gcs_client.write_file_from_path_to_bucket(this.bucket_name, destinationPath, sourcePath); | ||
await this.gcs_client.write_file_from_path_to_bucket(this.bucket_name, destinationPath, sourcePath); | ||
if (deleteSourceFileAfterUpload===true) { | ||
@@ -90,3 +90,3 @@ await fs_promises.rm(sourcePath); | ||
destinationPath = clean_file_path(destinationPath); | ||
await gcs_client.write_file_obj_to_bucket(this.bucket_name, destinationPath, object); | ||
await this.gcs_client.write_file_obj_to_bucket(this.bucket_name, destinationPath, object); | ||
return OK_RESPONSE_TEXT; | ||
@@ -105,3 +105,3 @@ } | ||
filePath = clean_file_path(filePath); | ||
return await gcs_client.get_write_stream_for_bucket(this.bucket_name, filePath); | ||
return await this.gcs_client.get_write_stream_for_bucket(this.bucket_name, filePath); | ||
} | ||
@@ -123,3 +123,3 @@ catch(err){ | ||
//check if the key exists | ||
let response = await gcs_client.check_if_file_exists( | ||
let response = await this.gcs_client.check_if_file_exists( | ||
this.bucket_name, | ||
@@ -144,3 +144,3 @@ filePath | ||
//copy the file | ||
await gcs_client.copy(this.bucket_name, sourceFilePath, this.bucket_name, destFilePath); | ||
await this.gcs_client.copy(this.bucket_name, sourceFilePath, this.bucket_name, destFilePath); | ||
return OK_RESPONSE_TEXT; | ||
@@ -159,3 +159,3 @@ } | ||
filePath = clean_file_path(filePath); | ||
return (await gcs_client.read_file(this.bucket_name, filePath)).toString('utf-8'); | ||
return (await this.gcs_client.read_file(this.bucket_name, filePath)).toString('utf-8'); | ||
} | ||
@@ -168,2 +168,15 @@ catch(err){ | ||
} | ||
//gets a signed url for an object with read permission | ||
getSignedUrl = async(filePath) => { | ||
try{ | ||
filePath = clean_file_path(filePath); | ||
return await this.gcs_client.get_signed_url(this.bucket_name, filePath, 'read'); | ||
} | ||
catch(err){ | ||
console.error(`error in file_storage/index.js/getSignedUrl`); | ||
console.error(err); | ||
throw err; | ||
} | ||
} | ||
} | ||
@@ -170,0 +183,0 @@ |
@@ -100,4 +100,22 @@ const {Storage} = require('@google-cloud/storage'); | ||
} | ||
//get signed url | ||
get_signed_url = async(bucket_name, key, permission='read', expiry_in_secs=180) => { | ||
try{ | ||
if (!bucket_name) throw new Error(`bucket_name must be specified`); | ||
if (!key) throw new Error(`key must be specified`); | ||
if (permission!='read' && permission!='write') { | ||
throw new Error(`permission level ${permission} is not supported, must be one of ['read', 'write']`); | ||
} | ||
const gcs_file = this.gcsClient.bucket(bucket_name).file(key); | ||
const res = await gcs_file.getSignedUrl({action: permission, expires: expiry_in_secs}); | ||
return res[0]; | ||
} | ||
catch(err){ | ||
console.error(err); | ||
throw err; | ||
} | ||
} | ||
} | ||
module.exports = InfurniaGCSClient; |
{ | ||
"name": "@infurnia/backend-file-storage", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Storage engine for google cloud storage", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14250
324