From 56580705e3a62eaf1c498c1c0456fc33fe3b2f76 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 5 Apr 2016 14:05:35 -0400 Subject: broaden media support --- app/node_modules/okserver/index.js | 2 +- app/node_modules/okservices/oks3/index.js | 54 ++++++++++++++++++-- examples/db.json | 29 ++++++++++- examples/index.js | 5 ++ package.json | 2 +- themes/okadmin/public/css/main.css | 3 ++ themes/okadmin/public/js/app.js | 18 ++++++- themes/okadmin/public/js/parser.js | 31 +++++++++-- themes/okadmin/public/js/upload.js | 61 ++++++++++++++++------ themes/okadmin/templates/partials/inputs.liquid | 68 ++++++++++++++++++------- 10 files changed, 226 insertions(+), 47 deletions(-) diff --git a/app/node_modules/okserver/index.js b/app/node_modules/okserver/index.js index ee1b4fb..3428565 100644 --- a/app/node_modules/okserver/index.js +++ b/app/node_modules/okserver/index.js @@ -60,7 +60,7 @@ function OKServer(options) { app.use(router); // Add services if (services.s3) { - app.use('/_services/image', services.s3.middleware()); + app.use('/_services/s3', services.s3.middleware()); } if (services.twitter) { app.use('/_services/twitter', services.twitter.middleware()) diff --git a/app/node_modules/okservices/oks3/index.js b/app/node_modules/okservices/oks3/index.js index d556c20..dc0ca19 100644 --- a/app/node_modules/okservices/oks3/index.js +++ b/app/node_modules/okservices/oks3/index.js @@ -4,7 +4,7 @@ var skipperS3 = require('skipper-s3') // Hack to prevent this god-forsaken module from crashing our shit var d = require('domain').create() d.on('error', function (err) { - console.error('Stupid error in S3 upload. Image upload probably prematurely canceled') + console.error('Stupid error in S3 upload. Upload probably prematurely canceled') }) function OKS3(options) { @@ -20,9 +20,9 @@ function OKS3(options) { router.use(skipper()); - router.post('/', function(req, res) { - // req should have a method `file` on it which is - // provided by skipper. Use that to do AWS stuff + // 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) { d.run(function () { req.file('image').upload({ adapter: skipperS3, @@ -38,7 +38,51 @@ function OKS3(options) { if (err) res.status(500).send(err) res.json(uploadedFiles); }); - }) + }); + }); + + router.post('/audio', function(req, res) { + d.run(function () { + if (! options.s3.allowAudioUploads) { + 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, + dirname: options.s3.dirname, + maxBytes: options.s3.maxbytesAudio, + headers: { + 'x-amz-acl': 'public-read' + } + }, function (err, uploadedFiles) { + if (err) res.status(500).send(err) + res.json(uploadedFiles); + }); + }); + }); + + router.post('/video', function(req, res) { + d.run(function () { + if (! options.s3.allowVideoUploads) { + 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, + dirname: options.s3.dirname, + maxBytes: options.s3.maxbytesVideo, + headers: { + 'x-amz-acl': 'public-read' + } + }, function (err, uploadedFiles) { + if (err) res.status(500).send(err) + res.json(uploadedFiles); + }); + }); }); this._middleware = router; diff --git a/examples/db.json b/examples/db.json index 1d045c3..3650355 100644 --- a/examples/db.json +++ b/examples/db.json @@ -174,7 +174,34 @@ "title": "Green", "__index": 1, "dateCreated": "Tue, 05 Apr 2016 15:17:57 GMT", - "media": [] + "media": [ + { + "type": "video", + "token": "https://ltho.s3.amazonaws.com/ee12b137-1c8a-400a-87e3-89cbee7b4da6.mp4", + "uri": "", + "width": "400", + "height": "400", + "title": "ee12b137-1c8a-400a-87e3-89cbee7b4da6.mp4", + "thumb": "http://okfocus.s3.amazonaws.com/misc/okcms/video.png" + }, + { + "type": "youtube", + "token": "y_35kXCQxN4", + "uri": "", + "width": "640", + "height": "360", + "title": "dëf lëöpär¨d¨¨¨¨<>~!@~#!:I!@", + "thumb": "http://i.ytimg.com/vi/y_35kXCQxN4/hqdefault.jpg" + }, + { + "type": "audio", + "token": "http://asdf.us/clouds35.mp3", + "uri": "", + "duration": "225.645792", + "title": "clouds35.mp3", + "thumb": "http://okfocus.s3.amazonaws.com/misc/okcms/video.png" + } + ] } ] } \ No newline at end of file diff --git a/examples/index.js b/examples/index.js index 81d9241..e9de0a3 100644 --- a/examples/index.js +++ b/examples/index.js @@ -40,6 +40,11 @@ var app = okcms.createApp({ key: process.env.S3_KEY, secret: process.env.S3_SECRET, bucket: process.env.S3_BUCKET, + allowVideoUploads: true, + allowAudioUploads: true, + maxsize: 200, + maxsizeVideo: 150000000, + maxsizeAudio: 150000000, } }, diff --git a/package.json b/package.json index c95a2bc..c3a7280 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "okcms", - "version": "0.1.24", + "version": "0.1.27", "description": "great", "main": "app/index.js", "scripts": { diff --git a/themes/okadmin/public/css/main.css b/themes/okadmin/public/css/main.css index 2f2d376..15b8781 100644 --- a/themes/okadmin/public/css/main.css +++ b/themes/okadmin/public/css/main.css @@ -303,6 +303,7 @@ button, input[type=submit] { width: 15em; height: 6em; } +.main.resource form .audio-element input[type=text], .main.resource form .video-element input[type=text] { width: 15em; } @@ -353,10 +354,12 @@ button, input[type=submit] { margin: 0; padding: 0; cursor: pointer; } +.audio-element:hover .remove, .video-element:hover .remove, .image-element:hover .remove { display: block; } +.audio-element .remove:hover, .video-element .remove:hover, .image-element .remove:hover { color: red; diff --git a/themes/okadmin/public/js/app.js b/themes/okadmin/public/js/app.js index e79f704..a12f517 100644 --- a/themes/okadmin/public/js/app.js +++ b/themes/okadmin/public/js/app.js @@ -5,7 +5,8 @@ var OKAdmin = function(){ var parent = this var uploader = new OKUpload () uploader.bind( this ) - uploader.add = function(url){ + uploader.add = function(media){ + var url = media.url var imageTemplate = $(".image-template", parent).html() var $el = $(imageTemplate) $el.find(".uri").val(url) @@ -46,7 +47,7 @@ var OKAdmin = function(){ $el.find("img").attr("src", url) $("ol", parent).prepend($el) } - uploader.addVideo = function(media){ + uploader.addMedia = function(media){ switch (media.type) { case 'youtube': case 'vimeo': @@ -64,6 +65,19 @@ var OKAdmin = function(){ $el.find("img").attr("src", media.thumbnail ) $("ol", parent).prepend($el) break + case 'audio': + var audioTemplate = $(".audio-template", parent).html() + var $el = $(audioTemplate) + $el.addClass("loaded") + $el.find(".audio-type").val( media.type ) + $el.find(".audio-token").val( media.token ) + $el.find(".audio-uri").val( media.uri ) + $el.find(".audio-title").val( media.title ) + $el.find(".audio-thumb").val( media.thumbnail ) + $el.find(".audio-duration").val( media.duration ) + $el.find("img").attr("src", media.thumbnail ) + $("ol", parent).prepend($el) + break case 'link': var linkTemplate = $(".link-template", parent).html() var $el = $(linkTemplate) diff --git a/themes/okadmin/public/js/parser.js b/themes/okadmin/public/js/parser.js index b4a087d..4ab9a6c 100644 --- a/themes/okadmin/public/js/parser.js +++ b/themes/okadmin/public/js/parser.js @@ -52,6 +52,31 @@ var Parser = { tag: function (media) { return '