diff options
Diffstat (limited to 'app/node_modules/okservices/oks3/index.js')
| -rw-r--r-- | app/node_modules/okservices/oks3/index.js | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/app/node_modules/okservices/oks3/index.js b/app/node_modules/okservices/oks3/index.js index cc40b71..41ee3dc 100644 --- a/app/node_modules/okservices/oks3/index.js +++ b/app/node_modules/okservices/oks3/index.js @@ -16,6 +16,7 @@ function OKS3(options) { if (!options.s3) throw new Error('S3 configuration not provided to OKS3'); + if (!options.s3.file) options.s3.file = {} if (!options.s3.image) options.s3.image = {} if (!options.s3.audio) options.s3.audio = {} if (!options.s3.video) options.s3.video = {} @@ -23,6 +24,8 @@ function OKS3(options) { // Make sure maxbytes property is there - it can be a number, // or zero/undefined (for no maximum upload size) if (options.s3.maxbytes) { + if (! ('maxbytes' in options.s3.file)) + options.s3.file.maxbytes = options.s3.maxbytes if (! ('maxbytes' in options.s3.image)) options.s3.image.maxbytes = options.s3.maxbytes if (! ('maxbytes' in options.s3.video)) @@ -30,6 +33,8 @@ function OKS3(options) { if (! ('maxbytes' in options.s3.audio)) options.s3.audio.maxbytes = options.s3.maxbytes } + if (typeof options.s3.file.allowed !== "boolean") + options.s3.file.allowed = true if (typeof options.s3.image.allowed !== "boolean") options.s3.image.allowed = true if (typeof options.s3.video.allowed !== "boolean") @@ -130,7 +135,34 @@ function OKS3(options) { }); }); - + + + router.post('/file', mult.single('file'), function(req, res) { + d.run(function () { + + if (! options.s3.image.allowed) { + return res.status(500).json({ error: "File uploading not permitted" }) + } + + upload.put({ + file: req.file, + preserveFilename: options.s3.video.preserveFilename, + dirname: options.s3.dirname, + types: { + 'application/pdf': 'pdf', + 'text/plain': 'txt', + 'text/html': 'html', + }, + unacceptable: function(err){ + res.json({ error: err }) + }, + success: function(url){ + res.json({ url: url }) + } + }) + + }); + }); function preserveFilename (stream, cb){ cb(null, stream.filename) } |
