From d8e9b4d5334db049feec81b0083c3adcedaf7e12 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 28 Mar 2016 19:10:26 -0400 Subject: allow generic urls in media field --- themes/okadmin/public/js/parser.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'themes/okadmin/public/js/parser.js') diff --git a/themes/okadmin/public/js/parser.js b/themes/okadmin/public/js/parser.js index 411f425..95b391c 100644 --- a/themes/okadmin/public/js/parser.js +++ b/themes/okadmin/public/js/parser.js @@ -145,7 +145,6 @@ var Parser = { '&color=ff6600&auto_play=false&show_artwork=true">' } }, - /* { type: 'link', regex: /^http.+/i, @@ -163,8 +162,7 @@ var Parser = { tag: function (media) { return '' + media.url + '' } - } - */ + }, ], tumblr: function(url, cb){ -- cgit v1.2.3-70-g09d2 From 3ae6b122cbb6e3491677fd79e2d0c1b1a506db93 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 4 Apr 2016 19:43:34 -0400 Subject: Improve response for mp4 videos in parser --- package.json | 2 +- themes/okadmin/public/js/parser.js | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'themes/okadmin/public/js/parser.js') diff --git a/package.json b/package.json index faf3cc9..09b24c8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "okcms", - "version": "0.1.19", + "version": "0.1.23", "description": "great", "main": "app/index.js", "scripts": { diff --git a/themes/okadmin/public/js/parser.js b/themes/okadmin/public/js/parser.js index 95b391c..6c964f7 100644 --- a/themes/okadmin/public/js/parser.js +++ b/themes/okadmin/public/js/parser.js @@ -31,6 +31,8 @@ var Parser = { regex: /\.(mp4|webm)(\?.*)?$/i, fetch: function(url, done) { var video = document.createElement("video") + var url_parts = url.replace(/\?.*$/, "").split("/") + var filename = url_parts[ url_parts.length-1 ] video.addEventListener("loadedmetadata", function(){ var width = video.videoWidth, height = video.videoHeight video = null @@ -38,8 +40,8 @@ var Parser = { url: url, type: "video", token: "", - thumbnail: "", - title: "", + thumbnail: "http://okfocus.s3.amazonaws.com/misc/okcms/video.png", + title: filename, width: width, height: height, }) -- cgit v1.2.3-70-g09d2 From cd929e1c38c02c1d048abe702c04c7d4d6188011 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 5 Apr 2016 11:46:47 -0400 Subject: Fix sorting bug when saving --- app/node_modules/okschema/index.js | 23 ++++++++++++++++++++--- examples/db.json | 20 +++++++++++++++++--- examples/index.js | 2 +- themes/okadmin/public/js/app.js | 4 ++++ themes/okadmin/public/js/parser.js | 2 +- themes/okadmin/templates/partials/inputs.liquid | 2 ++ 6 files changed, 45 insertions(+), 8 deletions(-) (limited to 'themes/okadmin/public/js/parser.js') diff --git a/app/node_modules/okschema/index.js b/app/node_modules/okschema/index.js index cf041fb..8162fd4 100644 --- a/app/node_modules/okschema/index.js +++ b/app/node_modules/okschema/index.js @@ -174,8 +174,7 @@ function OKSchema(spec) { }); } -OKSchema.prototype.checkDataForMissingArrays = function(data) { - data = data || {}; +OKSchema.prototype.fixMissingLists = function(data) { var spec = this.spec; // The qs body-parser module does not have a way to represent @@ -189,10 +188,22 @@ OKSchema.prototype.checkDataForMissingArrays = function(data) { }) } +OKSchema.prototype.fixIndexField = function(data) { + // Likewise numbers always come in as strings. The field used to sort + // records, __index, is of type "meta", so the parseFloat in + // assertValid (below) never fires and we end up with sorting issues. + if (data.__index && typeof data.__index == "string") { + var __index = parseInt(data.__index) + if (! isNaN(__index)) { + data.__index = __index + } + } +} + OKSchema.prototype.assertValid = function(data) { data = data || {}; var spec = this.spec; - this.checkDataForMissingArrays(data) + // Run through custom validators, they'll throw if invalid Object.keys(data).forEach(function(prop) { var type = spec[prop].type; @@ -210,6 +221,12 @@ OKSchema.prototype.assertValid = function(data) { if (!result.valid) { throw result.errors; } + + // Fix various issues with our data, having to do + // with use of the "qs" body-parser module. + // TODO: just send JSON? + this.fixMissingLists(data) + this.fixIndexField(data) }; /** diff --git a/examples/db.json b/examples/db.json index bdad6c8..1d045c3 100644 --- a/examples/db.json +++ b/examples/db.json @@ -150,8 +150,8 @@ ], "test": [ { - "id": "test", - "title": "tEst", + "id": "red", + "title": "Red", "media": [ { "uri": "http://asdf.us/", @@ -159,8 +159,22 @@ "type": "link" } ], - "__index": "0", + "__index": 0, "dateCreated": "Mon, 28 Mar 2016 23:02:45 GMT" + }, + { + "id": "blue", + "title": "Blue", + "__index": 2, + "dateCreated": "Tue, 05 Apr 2016 15:17:54 GMT", + "media": [] + }, + { + "id": "green", + "title": "Green", + "__index": 1, + "dateCreated": "Tue, 05 Apr 2016 15:17:57 GMT", + "media": [] } ] } \ No newline at end of file diff --git a/examples/index.js b/examples/index.js index 4bf385f..81d9241 100644 --- a/examples/index.js +++ b/examples/index.js @@ -4,7 +4,7 @@ var app = okcms.createApp({ root: 'public', - debug: false, + debug: true, schemas: { page: { diff --git a/themes/okadmin/public/js/app.js b/themes/okadmin/public/js/app.js index e7f902d..e79f704 100644 --- a/themes/okadmin/public/js/app.js +++ b/themes/okadmin/public/js/app.js @@ -56,6 +56,7 @@ var OKAdmin = function(){ $el.addClass("loaded") $el.find(".video-type").val( media.type ) $el.find(".video-token").val( media.token ) + $el.find(".video-uri").val( media.uri ) $el.find(".video-title").val( media.title ) $el.find(".video-thumb").val( media.thumbnail ) $el.find(".video-width").val( media.width ) @@ -125,8 +126,11 @@ var OKAdmin = function(){ $el.parent().addClass("loaded") $el.parent().find(".video-type").val( media.type ) $el.parent().find(".video-token").val( media.token ) + $el.parent().find(".video-uri").val( media.uri ) $el.parent().find(".video-title").val( media.title ) $el.parent().find(".video-thumb").val( media.thumbnail ) + $el.parent().find(".video-width").val( media.width ) + $el.parent().find(".video-height").val( media.height ) }) })) diff --git a/themes/okadmin/public/js/parser.js b/themes/okadmin/public/js/parser.js index 6c964f7..b4a087d 100644 --- a/themes/okadmin/public/js/parser.js +++ b/themes/okadmin/public/js/parser.js @@ -39,7 +39,7 @@ var Parser = { done({ url: url, type: "video", - token: "", + token: url, thumbnail: "http://okfocus.s3.amazonaws.com/misc/okcms/video.png", title: filename, width: width, diff --git a/themes/okadmin/templates/partials/inputs.liquid b/themes/okadmin/templates/partials/inputs.liquid index fa03e48..e618c61 100644 --- a/themes/okadmin/templates/partials/inputs.liquid +++ b/themes/okadmin/templates/partials/inputs.liquid @@ -164,6 +164,7 @@
+ @@ -192,6 +193,7 @@
+ -- cgit v1.2.3-70-g09d2 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(-) (limited to 'themes/okadmin/public/js/parser.js') 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 '
{% elsif type == 'image' %}
@@ -47,8 +47,8 @@
- - {{spec.value.caption}} + + {{spec.value.caption | escape}}
@@ -78,7 +78,7 @@ {% elsif type == 'tag-list' %}
@@ -90,13 +90,13 @@
@@ -142,8 +142,8 @@
- - + +
@@ -177,6 +177,23 @@ + +