@infurnia/backend-file-storage
Advanced tools
Comparing version 2.9.0 to 2.10.0
12
index.js
@@ -65,7 +65,7 @@ const utils = require('./utils'); | ||
//Uploads file from a path to the main uploads bucket | ||
writeFileFromPath = async (sourcePath, destinationPath, deleteSourceFileAfterUpload=false) => { | ||
writeFileFromPath = async (sourcePath, destinationPath, deleteSourceFileAfterUpload=false, contentDispositionAttachment=false) => { | ||
//by default will upload to one bucket only...change priorityLevel to change | ||
try{ | ||
destinationPath = clean_file_path(destinationPath, false); | ||
await this.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, contentDispositionAttachment); | ||
if (deleteSourceFileAfterUpload===true) { | ||
@@ -88,7 +88,7 @@ await fs_promises.rm(sourcePath); | ||
//Uploads file a buffer or string to the uploads bucket as a file | ||
writeFileFromBuffer = async (object, destinationPath) => { | ||
writeFileFromBuffer = async (object, destinationPath, contentDispositionAttachment=false) => { | ||
try{ | ||
destinationPath = clean_file_path(destinationPath, false); | ||
console.info(`In writeFileFromBuffer, Writing file to ${this.bucket_name}, ${destinationPath}`); | ||
await this.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, contentDispositionAttachment); | ||
console.info(`In writeFileFromBuffer, Done writing file to ${this.bucket_name}, ${destinationPath}`); | ||
@@ -105,6 +105,6 @@ return OK_RESPONSE_TEXT; | ||
//Get a writable stream to pipe content to | ||
getWriteStream = async(filePath) => { | ||
getWriteStream = async(filePath, contentDispositionAttachment=false) => { | ||
try{ | ||
filePath = clean_file_path(filePath, false); | ||
return await this.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, contentDispositionAttachment); | ||
} | ||
@@ -111,0 +111,0 @@ catch(err){ |
@@ -12,6 +12,11 @@ const {Storage} = require('@google-cloud/storage'); | ||
//upload a file object to a single bucket | ||
write_file_obj_to_bucket = async(bucket_name, key, file_object) => { | ||
write_file_obj_to_bucket = async(bucket_name, key, file_object, content_disposition_attachment=false) => { | ||
try{ | ||
const gcs_file = this.gcsClient.bucket(bucket_name).file(key); | ||
await gcs_file.save(file_object, { resumable: false }); | ||
if (content_disposition_attachment) { | ||
await gcs_file.save(file_object, { resumable: false, metadata: { contentDisposition: 'attachment'}}); | ||
} | ||
else { | ||
await gcs_file.save(file_object, { resumable: false }); | ||
} | ||
return 1; | ||
@@ -26,6 +31,12 @@ } | ||
//upload a file from path to a single bucket | ||
write_file_from_path_to_bucket = async(bucket_name, key, file_path) => { | ||
write_file_from_path_to_bucket = async(bucket_name, key, file_path, content_disposition_attachment=false) => { | ||
try{ | ||
let save_res; | ||
const gcs_bucket = this.gcsClient.bucket(bucket_name); | ||
const save_res = await gcs_bucket.upload(file_path, {destination: key, resumable: false}); | ||
if(content_disposition_attachment){ | ||
save_res = await gcs_bucket.upload(file_path, {destination: key, resumable: false, metadata: { contentDisposition: 'attachment'}}); | ||
} | ||
else { | ||
save_res = await gcs_bucket.upload(file_path, {destination: key, resumable: false}); | ||
} | ||
return save_res; | ||
@@ -40,5 +51,10 @@ } | ||
//get a write stream to write to the bucket | ||
get_write_stream_for_bucket = async(bucket_name, key) => { | ||
get_write_stream_for_bucket = async(bucket_name, key, content_disposition_attachment=false) => { | ||
try{ | ||
return this.gcsClient.bucket(bucket_name).file(key).createWriteStream(); | ||
if (content_disposition_attachment) { | ||
return this.gcsClient.bucket(bucket_name).file(key).createWriteStream({ metadata: { contentDisposition: 'attachment' }}); | ||
} | ||
else { | ||
return this.gcsClient.bucket(bucket_name).file(key).createWriteStream(); | ||
} | ||
} | ||
@@ -45,0 +61,0 @@ catch(err) { |
{ | ||
"name": "@infurnia/backend-file-storage", | ||
"version": "2.9.0", | ||
"version": "2.10.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
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
4
16050
6
347