From 180cf3eaa829fd04f759488d76641c4656caa245 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 11 Apr 2016 14:20:33 -0400 Subject: rewrite file upload code to use knox directly --- examples/index.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'examples/index.js') diff --git a/examples/index.js b/examples/index.js index fe37954..31ae8d2 100644 --- a/examples/index.js +++ b/examples/index.js @@ -42,10 +42,9 @@ var app = okcms.createApp({ secret: process.env.S3_SECRET, bucket: process.env.S3_BUCKET, dirname: "okcms-example", - // TODO: maxbytes stuff isn't working, need to change underlying module - image: { preserveFilename: false, maxbytes: 20000 }, - video: { preserveFilename: true, maxbytes: 0 }, - audio: { preserveFilename: true, maxbytes: 150000000 }, + image: { allowed: true, preserveFilename: false, maxbytes: 2*1024*1024 }, + video: { allowed: true, preserveFilename: true, maxbytes: 200*1024*1024 }, + audio: { allowed: true, preserveFilename: true, maxbytes: 100*1024*1024 }, } }, -- cgit v1.2.3-70-g09d2 From fa343212514f1e6f975e5cf5957e440555afb815 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 14 Apr 2016 14:14:34 -0400 Subject: example services --- examples/index.js | 9 +++++++ examples/lib/okdumpfm/index.js | 39 ++++++++++++++++++++++++++++++ examples/lib/okdumpfm/package.json | 14 +++++++++++ examples/lib/okexample/index.js | 48 +++++++++++++++++++++++++++++++++++++ examples/lib/okexample/package.json | 11 +++++++++ 5 files changed, 121 insertions(+) create mode 100644 examples/lib/okdumpfm/index.js create mode 100644 examples/lib/okdumpfm/package.json create mode 100644 examples/lib/okexample/index.js create mode 100644 examples/lib/okexample/package.json (limited to 'examples/index.js') diff --git a/examples/index.js b/examples/index.js index 31ae8d2..3bbed28 100644 --- a/examples/index.js +++ b/examples/index.js @@ -45,6 +45,15 @@ var app = okcms.createApp({ image: { allowed: true, preserveFilename: false, maxbytes: 2*1024*1024 }, video: { allowed: true, preserveFilename: true, maxbytes: 200*1024*1024 }, audio: { allowed: true, preserveFilename: true, maxbytes: 100*1024*1024 }, + }, + + example: { + lib: require("./lib/okexample"), + stuff: "things", + }, + + dumpfm: { + lib: require("./lib/okdumpfm"), } }, diff --git a/examples/lib/okdumpfm/index.js b/examples/lib/okdumpfm/index.js new file mode 100644 index 0000000..4dc5461 --- /dev/null +++ b/examples/lib/okdumpfm/index.js @@ -0,0 +1,39 @@ +var request = require('request') + +/** + * Example service which queries the Dump search. + */ +function OKDumpfm (options) { + if (!(this instanceof OKDumpfm)) return new OKDumpfm(options) + options = options || {} + if (!options.express) + throw new Error('Express not provided to OKDumpfm'); + + var express = options.express + var router = express.Router() + + router.get('*', function (req, res) { + var query = req.query.q + request('http://dump.fm/cmd/search/' + query, function (err, response, body) { + if (err || response.statusCode !== 200) { + res.status(response.statusCode) + res.send(err) + } else { + res.set('Content-Type', 'application/json; charset=utf-8') + res.send(body) + } + }) + }) + + router.post('*', function (req, res) { + throw new Error('OKDumpfm POST requests not implemented') + }) + + this._router = router +} + +OKDumpfm.prototype.middleware = function () { + return this._router +} + +module.exports = OKDumpfm diff --git a/examples/lib/okdumpfm/package.json b/examples/lib/okdumpfm/package.json new file mode 100644 index 0000000..17bcba2 --- /dev/null +++ b/examples/lib/okdumpfm/package.json @@ -0,0 +1,14 @@ +{ + "name": "okdumpfm", + "version": "1.0.0", + "description": "service to query the dump search API", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "okfocus ", + "license": "LNT", + "dependencies": { + "request": "^2.71.0" + } +} diff --git a/examples/lib/okexample/index.js b/examples/lib/okexample/index.js new file mode 100644 index 0000000..b614697 --- /dev/null +++ b/examples/lib/okexample/index.js @@ -0,0 +1,48 @@ + +/** + * Example service to show how these things should be set up. + * + * Services should be added to index.js in the proper area, + * with any configuration parameters that you want passed in: + * + * services: { + * example: { + * lib: require("./lib/okexample"), + * stuff: "things", + * } + * }, + * + * The service will be mounted on /_services/example + * + * This binds to route '*' but you can specify e.g. "/thing", + * and it will be mounted on /_services/example/thing + */ + +function OKExample (options) { + if (!(this instanceof OKExample)) return new OKExample(options) + options = options || {} + if (!options.express) + throw new Error('Express not provided to OKDumpfm'); + if (!options.config) + throw new Error('Configuration not provided to OKDumpfm'); + + var express = options.express + var router = express.Router() + var config = options.config + + router.get('*', function (req, res) { + res.send(config.stuff) + }) + + router.post('*', function (req, res) { + throw new Error('OKExample POST requests not implemented') + }) + + this._router = router +} + +OKExample.prototype.middleware = function () { + return this._router +} + +module.exports = OKExample diff --git a/examples/lib/okexample/package.json b/examples/lib/okexample/package.json new file mode 100644 index 0000000..2b2a47c --- /dev/null +++ b/examples/lib/okexample/package.json @@ -0,0 +1,11 @@ +{ + "name": "okexample", + "version": "1.0.0", + "description": "example service", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "okfocus ", + "license": "LNT" +} -- cgit v1.2.3-70-g09d2 From c98560cca095ef27b909ac47baf843362bffb28d Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 14 Apr 2016 20:32:08 -0400 Subject: OKWebhook module for receiving pushes from git --- app/index.js | 7 ++ app/node_modules/okservices/okwebhook/index.js | 83 ++++++++++++++++++++++ app/node_modules/okservices/okwebhook/package.json | 11 +++ examples/index.js | 11 ++- examples/lib/okexample/index.js | 5 +- 5 files changed, 114 insertions(+), 3 deletions(-) create mode 100644 app/node_modules/okservices/okwebhook/index.js create mode 100644 app/node_modules/okservices/okwebhook/package.json (limited to 'examples/index.js') diff --git a/app/index.js b/app/index.js index 8c3abb9..48e713a 100644 --- a/app/index.js +++ b/app/index.js @@ -15,6 +15,7 @@ var OKServer = require('okserver'); var OKSchema = require('okschema'); var OKS3Service = require('okservices/oks3'); var OKTwitterService = require('okservices/oktwitter') +var OKWebhookService = require('okservices/okwebhook') require('dotenv').load(); @@ -110,6 +111,12 @@ function OKCMS(options) { credentials: config, }); break + case 'webhook': + services.webhook = OKWebhookService({ + express: express, + config: config, + }); + break default: services[key] = config.lib({ db: resourceCache, diff --git a/app/node_modules/okservices/okwebhook/index.js b/app/node_modules/okservices/okwebhook/index.js new file mode 100644 index 0000000..d04e662 --- /dev/null +++ b/app/node_modules/okservices/okwebhook/index.js @@ -0,0 +1,83 @@ + +/** + * Service which will listen for a Github webhook, fired on push. + * This service can be used to rebuild / restart the app automatically + * when new code is pushed. + */ + +var crypto = require('crypto') +var exec = require('child_process').exec +var path = require('path') + +function OKWebhook (options) { + if (!(this instanceof OKWebhook)) return new OKWebhook(options) + options = options || {} + if (!options.express) + throw new Error('Express not provided to OKWebhook'); + if (!options.config) + throw new Error('Configuration not provided to OKWebhook'); + if (options.config.active && !options.config.secret) + throw new Error('Github secret not provided to OKWebhook'); + if (options.config.active && !options.config.command) + throw new Error('Build command not provided to OKWebhook'); + + var express = options.express + var router = express.Router() + var config = options.config + + var secret = config.secret + var command = config.command + + router.get('/', function (req, res) { + res.send('GET not supported') + }) + + router.post('/', getBody, function (req, res) { + if (!config.active) + return + console.log("OKWebhook received push") + var event = req.headers['x-github-event'] + if (event !== "push") { + return res.sendStatus(500) + } + var sig = req.headers['x-hub-signature'].split('=')[1] + var text = req.rawBody + var hash = crypto.createHmac('sha1', secret).update(text).digest('hex') + if (hash !== sig) { + return res.sendStatus(500) + } + res.sendStatus(200) + var cwd = path.dirname(command) + exec(command, { cwd: cwd }, function(err, stdout, stderr){ + // may not fire if process was restarted.. + console.log(process.env) + console.log(stdout) + }) + }) + + function getBody (req, res, next) { + req.rawBody = '' + // req.setEncoding('utf8') + + req.on('data', function(chunk) { + req.rawBody += chunk + }) + + req.on('end', function() { + try { + req.body = JSON.parse(req.rawBody) + } catch (e) { + return res.sendStatus(500) + } + next() + }) + } + + this._router = router +} + +OKWebhook.prototype.middleware = function () { + return this._router +} + +module.exports = OKWebhook diff --git a/app/node_modules/okservices/okwebhook/package.json b/app/node_modules/okservices/okwebhook/package.json new file mode 100644 index 0000000..0436f01 --- /dev/null +++ b/app/node_modules/okservices/okwebhook/package.json @@ -0,0 +1,11 @@ +{ + "name": "okwebhook", + "version": "1.0.0", + "description": "webhook to receive pushes from github", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "okfocus ", + "license": "LNT" +} diff --git a/examples/index.js b/examples/index.js index 3bbed28..efbfc38 100644 --- a/examples/index.js +++ b/examples/index.js @@ -1,10 +1,13 @@ var okcms = require('..'); +var isProduction = process.env.OK_PRODUCTION === 'true' + var app = okcms.createApp({ root: 'public', - debug: true, + debug: !isProduction, + production: isProduction, schemas: { page: { @@ -47,6 +50,12 @@ var app = okcms.createApp({ audio: { allowed: true, preserveFilename: true, maxbytes: 100*1024*1024 }, }, + webhook: { + active: false, + secret: 'test', + command: '/path/to/build.sh', + }, + example: { lib: require("./lib/okexample"), stuff: "things", diff --git a/examples/lib/okexample/index.js b/examples/lib/okexample/index.js index b614697..04c5984 100644 --- a/examples/lib/okexample/index.js +++ b/examples/lib/okexample/index.js @@ -22,13 +22,14 @@ function OKExample (options) { if (!(this instanceof OKExample)) return new OKExample(options) options = options || {} if (!options.express) - throw new Error('Express not provided to OKDumpfm'); + throw new Error('Express not provided to OKExample'); if (!options.config) - throw new Error('Configuration not provided to OKDumpfm'); + throw new Error('Configuration not provided to OKExample'); var express = options.express var router = express.Router() var config = options.config + var db = options.db router.get('*', function (req, res) { res.send(config.stuff) -- cgit v1.2.3-70-g09d2 From f76ec56f3d70da6359905e9b9666f581599edd4f Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 21 Apr 2016 18:02:31 -0400 Subject: fix issue with single input fields, store image width/height --- examples/db.json | 24 ++++++++++++++++++++++- examples/index.js | 6 ++++++ package.json | 4 ++-- themes/okadmin/public/css/main.css | 4 +++- themes/okadmin/public/js/app.js | 26 ++++++++++++++++--------- themes/okadmin/templates/partials/inputs.liquid | 18 +++++++++++++++-- 6 files changed, 67 insertions(+), 15 deletions(-) (limited to 'examples/index.js') diff --git a/examples/db.json b/examples/db.json index 8805342..401bf26 100644 --- a/examples/db.json +++ b/examples/db.json @@ -153,6 +153,13 @@ "id": "red", "title": "Red", "media": [ + { + "uri": "https://ltho.s3.amazonaws.com/okcms-example/a91c4210-080c-11e6-8a7d-f30231d4ec26.png", + "width": "800", + "height": "800", + "caption": "", + "type": "image" + }, { "uri": "http://asdf.us/", "caption": "ASDF", @@ -160,7 +167,8 @@ } ], "__index": 0, - "dateCreated": "Mon, 28 Mar 2016 23:02:45 GMT" + "dateCreated": "Mon, 28 Mar 2016 23:02:45 GMT", + "flagged": false }, { "id": "blue", @@ -210,5 +218,19 @@ ], "flagged": true } + ], + "flour": [ + { + "id": "test", + "title": "TEST", + "image": { + "uri": "https://ltho.s3.amazonaws.com/okcms-example/7be163d0-080b-11e6-8a7d-f30231d4ec26.png", + "caption": "", + "width": "800", + "height": "800" + }, + "__index": 0, + "dateCreated": "Thu, 21 Apr 2016 21:52:44 GMT" + } ] } \ No newline at end of file diff --git a/examples/index.js b/examples/index.js index efbfc38..341a50b 100644 --- a/examples/index.js +++ b/examples/index.js @@ -29,6 +29,11 @@ var app = okcms.createApp({ title: {type: 'string'}, flagged: {type: 'flag'}, media: {type: 'media-list'}, + }, + flour: { + id: {type: 'string', hidden: true}, + title: {type: 'string'}, + image: {type: 'image'}, } }, @@ -37,6 +42,7 @@ var app = okcms.createApp({ { type: 'page', static: {id: 'contact'}}, { type: 'bread' }, { type: 'test' }, + { type: 'flour' }, ], services: { diff --git a/package.json b/package.json index 619b1c8..971efed 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "okcms", - "version": "0.1.33", - "description": "great", + "version": "0.1.34", + "description": "The dopest CMS on the planet.", "main": "app/index.js", "scripts": { "postinstall": "./install.sh", diff --git a/themes/okadmin/public/css/main.css b/themes/okadmin/public/css/main.css index 15b8781..e539a71 100644 --- a/themes/okadmin/public/css/main.css +++ b/themes/okadmin/public/css/main.css @@ -291,7 +291,9 @@ button, input[type=submit] { height: 7em; } .main.resource form img { - width: 10em; + width: auto; + height: auto; + max-width: 10em; max-height: 6em; border: 0; } diff --git a/themes/okadmin/public/js/app.js b/themes/okadmin/public/js/app.js index 59fc6ae..578d99f 100644 --- a/themes/okadmin/public/js/app.js +++ b/themes/okadmin/public/js/app.js @@ -9,8 +9,10 @@ var OKAdmin = function(){ var url = media.url var imageTemplate = $(".image-template", parent).html() var $el = $(imageTemplate) - $el.find(".uri").val(url) - $el.find("img").attr("src", url) + $el.find(".uri").val(media.url) + $el.find(".image-width").val(media.width) + $el.find(".image-height").val(media.height) + $el.find("img").attr("src", media.url) $("ol", parent).prepend($el) } }) @@ -44,8 +46,10 @@ var OKAdmin = function(){ var url = media.url var imageTemplate = $(".image-template", parent).html() var $el = $(imageTemplate) - $el.find(".uri").val(url) - $el.find("img").attr("src", url) + $el.find(".uri").val(media.url) + $el.find(".image-width").val(media.width) + $el.find(".image-height").val(media.height) + $el.find("img").attr("src", media.url) $("ol", parent).prepend($el) } uploader.addMedia = function(media){ @@ -103,11 +107,13 @@ var OKAdmin = function(){ var $el = $(this) var uploader = new OKUpload () uploader.bind( this ) - uploader.add = function(url){ - console.log(url) - $el.find(".uri").val(url) + uploader.add = function(media){ + console.log(media) + $el.find(".uri").val(media.url) $el.find(".caption").val("") - $el.find("img").attr("src", url).show() + $el.find(".image-width").val(media.width) + $el.find(".image-height").val(media.height) + $el.find("img").attr("src", media.url).show() $el.addClass("loaded") } }) @@ -117,6 +123,8 @@ var OKAdmin = function(){ var $el = $(this).closest(".image") $el.removeClass('loaded') $el.find(".uri").val("") + $el.find(".image-width").val("") + $el.find(".image-height").val("") $el.find(".caption").val("") $el.find("img").attr("src", "") } @@ -141,7 +149,7 @@ 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-uri").val( media.url ) $el.parent().find(".video-title").val( media.title ) $el.parent().find(".video-thumb").val( media.thumbnail ) $el.parent().find(".video-width").val( media.width ) diff --git a/themes/okadmin/templates/partials/inputs.liquid b/themes/okadmin/templates/partials/inputs.liquid index 373e580..e71f4ad 100644 --- a/themes/okadmin/templates/partials/inputs.liquid +++ b/themes/okadmin/templates/partials/inputs.liquid @@ -48,6 +48,8 @@
+ + {{spec.value.caption | escape}}
@@ -154,6 +156,8 @@ + + @@ -165,8 +169,8 @@ - - + + @@ -249,6 +253,8 @@
  • + + {{image.caption | strip_html}} @@ -271,6 +277,8 @@