From e14276957d196223b873419d5e80dd5c8ead945c Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 21 Sep 2017 15:49:50 +0200 Subject: endpoint --- lib/okpush/index.js | 23 ++++++++++++++++++++++- lib/okpush/public/push.js | 4 ++-- lib/okpush/templates/new.liquid | 4 ++-- 3 files changed, 26 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/okpush/index.js b/lib/okpush/index.js index 36588aa2..391f64f9 100644 --- a/lib/okpush/index.js +++ b/lib/okpush/index.js @@ -46,6 +46,7 @@ function OKPush (options) { var templates = {} templates['index'] = templateProvider.getTemplate('index') + templates['new'] = templateProvider.getTemplate('new') apn.init(config) db.init(config) @@ -92,8 +93,14 @@ function OKPush (options) { }) }) + router.get('/new', function (req, res) { + templates['new'].render(data).then(function(rendered) { + res.send(rendered); + }).fail(error(req, res, 500)) + }) + router.get('/list', function(req, res){ - db.getAllTokens("hub", function(err, hubz){ + db.getAllTokens('hub', function(err, hubz){ res.json(hubz) }) }) @@ -108,6 +115,20 @@ function OKPush (options) { }) }) + router.post('/custom', bodyParser.urlencoded({ extended: false }), function (req, res) { + var message = req.body.message + var url = req.body.url + var opt = { + alert: message, + payload: { 'url': url }, + } + var note = apn.buildPayload(opt, options.config.bundleId) + apn.push('hub', note) + db.addNotification(channel, function(){ + res.sendStatus(200) + }) + }) + // should work without middleware router.post('/add', bodyParser.urlencoded({ extended: false }), function (req, res) { db.addToken({ diff --git a/lib/okpush/public/push.js b/lib/okpush/public/push.js index 06588327..ca32fa98 100644 --- a/lib/okpush/public/push.js +++ b/lib/okpush/public/push.js @@ -31,7 +31,7 @@ $(function(){ $('#custom').submit(function(e){ e.preventDefault() var message = $("#message").val().trim() - var dest = $("#dest").val() + var url = $("#url").val() var msg = "This will send this push notification to everyone. Click OK to confirm.\n\n" + message if (! confirm(msg)) return @@ -40,7 +40,7 @@ $(function(){ url: "/_services/push/custom", data: { message: message, - dest: dest, + url: url, }, success: function(){ alert("Push notification sent.") diff --git a/lib/okpush/templates/new.liquid b/lib/okpush/templates/new.liquid index 0393535c..b16d0ae0 100644 --- a/lib/okpush/templates/new.liquid +++ b/lib/okpush/templates/new.liquid @@ -21,8 +21,8 @@
- - -- cgit v1.2.3-70-g09d2