diff options
| author | Jules Laplace <jules@okfoc.us> | 2016-08-17 02:18:49 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2016-08-17 02:18:49 -0400 |
| commit | 7bb493d94240513635fca668d169256aa502d009 (patch) | |
| tree | 1ac9c5fa78041c8f05f2092127b4d2d529d251f8 /app/node_modules/okservices/oks3/index.js | |
| parent | 071fdf9d53becb08b6a54c8c49effcb6c1a23e98 (diff) | |
| parent | 6ca70643c18df738fbad5a4e13b1c48fab9ea430 (diff) | |
Merge branch 'twohustlers' of github.com:okfocus/okcms into twohustlers
Diffstat (limited to 'app/node_modules/okservices/oks3/index.js')
| -rw-r--r-- | app/node_modules/okservices/oks3/index.js | 139 |
1 files changed, 77 insertions, 62 deletions
diff --git a/app/node_modules/okservices/oks3/index.js b/app/node_modules/okservices/oks3/index.js index 34c5840..cc40b71 100644 --- a/app/node_modules/okservices/oks3/index.js +++ b/app/node_modules/okservices/oks3/index.js @@ -1,5 +1,5 @@ -var skipper = require('skipper'); -var skipperS3 = require('skipper-s3') +var upload = require("./upload") +var multer = require('multer') // Hack to prevent this god-forsaken module from crashing our shit var d = require('domain').create() @@ -20,10 +20,6 @@ function OKS3(options) { if (!options.s3.audio) options.s3.audio = {} if (!options.s3.video) options.s3.video = {} -/* - // TODO: maxBytes property doesn't work - if you upload a large file, - // it will just hang until you reload the browser, and then CRASH. - // Make sure maxbytes property is there - it can be a number, // or zero/undefined (for no maximum upload size) if (options.s3.maxbytes) { @@ -34,85 +30,104 @@ function OKS3(options) { if (! ('maxbytes' in options.s3.audio)) options.s3.audio.maxbytes = options.s3.maxbytes } -*/ - if (options.s3.image.preserveFilename) - options.s3.image.preserveFilename = preserveFilename - if (options.s3.video.preserveFilename) - options.s3.video.preserveFilename = preserveFilename - if (options.s3.audio.preserveFilename) - options.s3.audio.preserveFilename = preserveFilename + if (typeof options.s3.image.allowed !== "boolean") + options.s3.image.allowed = true + if (typeof options.s3.video.allowed !== "boolean") + options.s3.video.allowed = false + if (typeof options.s3.audio.allowed !== "boolean") + options.s3.audio.allowed = false + + upload.init({ + key: options.s3.key, + secret: options.s3.secret, + bucket: options.s3.bucket, + }) var express = options.express; var router = express.Router(); - router.use(skipper()); + var mult = multer() - // req should have a method `file` on it which is - // provided by skipper. Use that to do AWS stuff - router.post('/image', function(req, res) { + router.post('/image', mult.single('image'), function(req, res) { d.run(function () { - var skip = req.file('image').upload({ - adapter: skipperS3, - key: options.s3.key, - secret: options.s3.secret, - bucket: options.s3.bucket, + + if (! options.s3.image.allowed) { + return res.status(500).json({ error: "Image uploading not permitted" }) + } + + upload.put({ + file: req.file, + preserveFilename: options.s3.image.preserveFilename, dirname: options.s3.dirname, - // maxBytes: options.s3.image.maxbytes, - saveAs: options.s3.image.preserveFilename, - headers: { - 'x-amz-acl': 'public-read' + types: { + 'image/gif': 'gif', + 'image/jpeg': 'jpg', + 'image/jpg': 'jpg', + 'image/png': 'png', + }, + unacceptable: function(err){ + res.json({ error: err }) + }, + success: function(url){ + res.json({ url: url }) } - }, function (err, uploadedFiles) { - if (err) return res.status(500).send(err) - res.json(uploadedFiles); - }); + }) + }); }); - router.post('/audio', function(req, res) { + router.post('/audio', mult.single('audio'), function(req, res) { d.run(function () { - if (! options.s3.allowAudioUploads) { - return res.status(500).json({ error: "audio uploading not permitted" }) + + if (! options.s3.image.allowed) { + return res.status(500).json({ error: "Audio uploading not permitted" }) } - req.file('audio').upload({ - adapter: skipperS3, - key: options.s3.key, - secret: options.s3.secret, - bucket: options.s3.bucket, + + upload.put({ + file: req.file, + preserveFilename: options.s3.audio.preserveFilename, dirname: options.s3.dirname, - // maxBytes: options.s3.audio.maxbytes, - saveAs: options.s3.audio.preserveFilename, - headers: { - 'x-amz-acl': 'public-read' + types: { + 'audio/mp3': 'mp3', + 'audio/mpeg': 'mp3', + 'audio/wav': 'wav', + 'audio/flac': 'flac', + }, + unacceptable: function(err){ + res.json({ error: err }) + }, + success: function(url){ + res.json({ url: url }) } - }, function (err, uploadedFiles) { - if (err) res.status(500).send(err) - res.json(uploadedFiles); - }); + }) + }); }); - router.post('/video', function(req, res) { + router.post('/video', mult.single('video'), function(req, res) { d.run(function () { - if (! options.s3.allowVideoUploads) { - return res.status(500).json({ error: "video uploading not permitted" }) + + if (! options.s3.image.allowed) { + return res.status(500).json({ error: "Video uploading not permitted" }) } - req.file('video').upload({ - adapter: skipperS3, - key: options.s3.key, - secret: options.s3.secret, - bucket: options.s3.bucket, + + upload.put({ + file: req.file, + preserveFilename: options.s3.video.preserveFilename, dirname: options.s3.dirname, - // maxBytes: options.s3.video.maxbytes, - saveAs: options.s3.video.preserveFilename, - headers: { - 'x-amz-acl': 'public-read' + types: { + 'video/mp4': 'mp4', + 'video/webm': 'webm', + }, + unacceptable: function(err){ + res.json({ error: err }) + }, + success: function(url){ + res.json({ url: url }) } - }, function (err, uploadedFiles) { - if (err) res.status(500).send(err) - res.json(uploadedFiles); - }); + }) + }); }); |
