From 5b32e1d31d0cf3355e1d79de08cab95f3b807339 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Thu, 10 Nov 2016 00:13:12 +0100 Subject: [PATCH 1/2] Add files list support --- index.js | 8 ++++++++ package.json | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 64b022a..695ad2a 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,7 @@ // Stores Parse files in AWS S3. var AWS = require('aws-sdk'); +var S3LS = require('s3-ls'); var optionsFromArguments = require('./lib/optionsFromArguments'); // Creates an S3 session. @@ -134,5 +135,12 @@ S3Adapter.prototype.getFileLocation = function(config, filename) { return (config.mount + '/files/' + config.applicationId + '/' + encodeURIComponent(filename)); } +S3Adapter.prototype.getFilesList = function(config, filename) { + var lister = S3LS({bucket: this._bucket, s3: this._s3Client}); + lister.ls('/', function (error, data) { + return (data.files); + }); +} + module.exports = S3Adapter; module.exports.default = S3Adapter; diff --git a/package.json b/package.json index 6309c14..7552cf4 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ }, "homepage": "https://github.com/parse-server-modules/parse-server-s3-adapter#readme", "dependencies": { - "aws-sdk": "^2.2.46" + "aws-sdk": "^2.2.46", + "s3-ls": "^1.0.1" }, "devDependencies": { "codecov": "^1.0.1", From e0735ba4bdf7fda5e60968e8f7a9733a4ea1ebf8 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Thu, 10 Nov 2016 00:46:42 +0100 Subject: [PATCH 2/2] Throw error when needed and remove method arguments --- index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 695ad2a..b2d1060 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ // Stores Parse files in AWS S3. var AWS = require('aws-sdk'); -var S3LS = require('s3-ls'); +var s3ls = require('s3-ls'); var optionsFromArguments = require('./lib/optionsFromArguments'); // Creates an S3 session. @@ -135,9 +135,10 @@ S3Adapter.prototype.getFileLocation = function(config, filename) { return (config.mount + '/files/' + config.applicationId + '/' + encodeURIComponent(filename)); } -S3Adapter.prototype.getFilesList = function(config, filename) { - var lister = S3LS({bucket: this._bucket, s3: this._s3Client}); +S3Adapter.prototype.getFilesList = function() { + var lister = s3ls({bucket: this._bucket, s3: this._s3Client}); lister.ls('/', function (error, data) { + if (error) throw error; return (data.files); }); }