Skip to content

Commit

Permalink
preventing this rejections in move actions
Browse files Browse the repository at this point in the history
  • Loading branch information
frytg committed Jul 27, 2020
1 parent 8d2ff2a commit 0eefa16
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@swrlab/node-storage-wrapper",
"version": "0.0.5",
"version": "0.0.6",
"description": "Wrapping AWS S3, GCP GCS, file storage",
"main": "./src/index.js",
"engines": {
Expand Down
19 changes: 10 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function StorageWrapper(config) {
};

// set logging
this.sdk.log = (that, level, message) => {
this.sdk.log = function (that, level, message) {
if (message instanceof Array) {
message = message.join(' ');
}
Expand All @@ -49,16 +49,17 @@ function StorageWrapper(config) {
}
};

// import functions
this.createUri = require('./createUri');
this.delete = require('./delete');
this.list = require('./list');
this.load = require('./load');
this.move = require('./move');
this.save = require('./save');

// log progress
this.sdk.log(this, 'log', ['storage.index', 'loaded config >', JSON.stringify({ config })]);
}

// enable utils
StorageWrapper.prototype.createUri = require('./createUri');
StorageWrapper.prototype.delete = require('./delete');
StorageWrapper.prototype.list = require('./list');
StorageWrapper.prototype.load = require('./load');
StorageWrapper.prototype.move = require('./move');
StorageWrapper.prototype.save = require('./save');

// export
module.exports = StorageWrapper;
2 changes: 0 additions & 2 deletions src/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ module.exports = async function (uri) {
bucket = structure.shift();
path = structure.join('/');

console.log(this);

// log progress
this.sdk.log(this, 'log', ['storage.load.aws >', uri]);

Expand Down
13 changes: 3 additions & 10 deletions src/move.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@
*/

// load own sub-utils
const storage = {
delete: require('./delete'),
load: require('./load'),
save: require('./save'),
};

module.exports = async function (sourceUri, destinationUri, keepOriginal) {
try {
let structure, bucket, path, blob;
Expand Down Expand Up @@ -96,14 +89,14 @@ module.exports = async function (sourceUri, destinationUri, keepOriginal) {
this.sdk.log(this, 'log', ['storage.move.any2any >', keepOriginal, sourceUri, destinationUri]);

// download file
blob = await storage.load(sourceUri);
blob = await this.load(sourceUri);

// save file to destination
await storage.save(destinationUri, blob);
await this.save(destinationUri, blob);

// delete file if in production
if (keepOriginal != true) {
await storage.delete(sourceUri);
await this.delete(sourceUri);
} else {
this.sdk.log(this, 'log', [
'storage.move.any2any not deleting sourceUri >',
Expand Down

0 comments on commit 0eefa16

Please sign in to comment.