From 01e738e26e41f60106f6f74d5955b04cd5d6f161 Mon Sep 17 00:00:00 2001 From: g-div Date: Wed, 11 Oct 2017 16:58:53 +0200 Subject: [PATCH] fix(push): use pushover-notifications instead of node-pushover This allows to set notification sounds manually Closes #3. --- build/embed.js | 2 +- package-lock.json | 954 +----------------------------------- package.json | 2 +- src/db/queries.js | 7 +- src/db/schema.sql | 5 + src/embed/comments.jst.html | 6 + src/server.js | 35 +- 7 files changed, 69 insertions(+), 942 deletions(-) diff --git a/build/embed.js b/build/embed.js index b9feddf..4e78d3a 100644 --- a/build/embed.js +++ b/build/embed.js @@ -1 +1 @@ -!function(){"use strict";var n="function"==typeof fetch?fetch.bind():function(n,t){return t=t||{},new Promise(function(e,a){function s(){var n,t=[],e=[],a={};return o.getAllResponseHeaders().replace(/^(.*?):\s*([\s\S]*?)$/gm,function(s,o,c){t.push(o=o.toLowerCase()),e.push([o,c]),n=a[o],a[o]=n?n+","+c:c}),{ok:1==(o.status/200|0),status:o.status,statusText:o.statusText,url:o.responseURL,clone:s,text:function(){return Promise.resolve(o.responseText)},json:function(){return Promise.resolve(o.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([o.response]))},headers:{keys:function(){return t},entries:function(){return e},get:function(n){return a[n.toLowerCase()]},has:function(n){return n.toLowerCase()in a}}}}var o=new XMLHttpRequest;o.open(t.method||"get",n);for(var c in t.headers)o.setRequestHeader(c,t.headers[c]);o.withCredentials="include"==t.credentials,o.onload=function(){e(s())},o.onerror=a,o.send(t.body)})},t=function(n){var t,e="";return n.user?e+='\n
\n \n \n
\n \n  \n
\n (signed in as @'+(null==(t=n.user.name)?"":t)+' :: sign out)\n
\n':(e+="\nTo post a comment you need to sign in via
\n",n.auth.forEach(function(n,a){e+="\n "+(null==(t=a?" or ":"")?"":t)+'\n"}),e+="\n"),e+='\n"};!function(){function e(){n(l,{credentials:"include",headers:{"Content-Type":"application/json"}}).then(function(n){return n.json()}).then(function(s){a(u).innerHTML=t(s);var o=a(u+" textarea.schnack-body"),r=a(u+" .schnack-form blockquote.schnack-body"),d=window.localStorage.getItem("schnack-draft-"+c);d&&o&&(o.value=d);var h=a(u+" .schnack-button"),p=a(u+" .schnack-preview"),f=a(u+" .schnack-write");if(h&&(h.addEventListener("click",function(t){var a=o.value;n(l,{credentials:"include",method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({comment:a})}).then(function(n){return n.json()}).then(function(n){console.log(n),o.value="",window.localStorage.setItem("schnack-draft-"+c,o.value),e()})}),p.addEventListener("click",function(t){var e=o.value;o.style.display="none",p.style.display="none",r.style.display="block",f.style.display="inline",n(i+"/markdown",{credentials:"include",method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({comment:e})}).then(function(n){return n.json()}).then(function(n){console.log(n),r.innerHTML=n.html})}),f.addEventListener("click",function(n){o.style.display="inline",p.style.display="inline",r.style.display="none",f.style.display="none"}),o.addEventListener("keyup",function(){window.localStorage.setItem("schnack-draft-"+c,o.value)})),s.user){var k=a("a.schnack-signout");k&&k.addEventListener("click",function(t){t.preventDefault(),n(i+"/signout",{credentials:"include",headers:{"Content-Type":"application/json"}}).then(function(n){return n.json()}).then(function(n){console.log(n),e()})})}else s.auth.forEach(function(n){var t=a(u+" .schnack-signin-"+n.id);t&&t.addEventListener("click",function(t){var a=window.open(i+"/auth/"+n.id,n.name+" Sign-In","resizable,scrollbars,status,width=600,height=500");window.__schnack_wait_for_oauth=function(){a.close(),e()}})});if(s.user&&s.user.admin){var m=function(t){var a=t.target.dataset;n(i+"/"+a.class+"/"+a.target+"/"+a.action,{credentials:"include",method:"POST",headers:{"Content-Type":"application/json"},body:""}).then(function(n){return n.json()}).then(function(n){console.log(n),e()})};document.querySelectorAll(".schnack-action").forEach(function(n){n.addEventListener("click",m)})}})}var a=function(n){return document.querySelector(n)},s=a("script[data-schnack-target]");if(!s)return console.warn("schnack script tag needs some data attributes");var o=s.dataset,c=o.schnackSlug,r=new URL(s.getAttribute("src")),i=r.protocol+"//"+r.host,l=i+"/comments/"+c,u=o.schnackTarget;document.domain=r.host.split(".").slice(1).join("."),e()}()}(); +!function(){"use strict";var n="function"==typeof fetch?fetch.bind():function(n,t){return t=t||{},new Promise(function(e,a){function s(){var n,t=[],e=[],a={};return o.getAllResponseHeaders().replace(/^(.*?):\s*([\s\S]*?)$/gm,function(s,o,c){t.push(o=o.toLowerCase()),e.push([o,c]),n=a[o],a[o]=n?n+","+c:c}),{ok:1==(o.status/200|0),status:o.status,statusText:o.statusText,url:o.responseURL,clone:s,text:function(){return Promise.resolve(o.responseText)},json:function(){return Promise.resolve(o.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([o.response]))},headers:{keys:function(){return t},entries:function(){return e},get:function(n){return a[n.toLowerCase()]},has:function(n){return n.toLowerCase()in a}}}}var o=new XMLHttpRequest;o.open(t.method||"get",n);for(var c in t.headers)o.setRequestHeader(c,t.headers[c]);o.withCredentials="include"==t.credentials,o.onload=function(){e(s())},o.onerror=a,o.send(t.body)})},t=function(n){var t,e="";return n.user?(e+="\n ",n.user.admin&&(e+='\n
\n \n \n
\n '),e+='\n
\n \n \n
\n \n  \n
\n (signed in as @'+(null==(t=n.user.name)?"":t)+' :: sign out)\n
\n'):(e+="\nTo post a comment you need to sign in via
\n",n.auth.forEach(function(n,a){e+="\n "+(null==(t=a?" or ":"")?"":t)+'\n"}),e+="\n"),e+='\n\n"};!function(){function e(){n(l,{credentials:"include",headers:{"Content-Type":"application/json"}}).then(function(n){return n.json()}).then(function(s){a(u).innerHTML=t(s);var o=a(u+" textarea.schnack-body"),i=a(u+" .schnack-form blockquote.schnack-body"),d=window.localStorage.getItem("schnack-draft-"+c);d&&o&&(o.value=d);var h=a(u+" .schnack-button"),f=a(u+" .schnack-preview"),p=a(u+" .schnack-write");if(h&&(h.addEventListener("click",function(t){var a=o.value;n(l,{credentials:"include",method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({comment:a})}).then(function(n){return n.json()}).then(function(n){console.log(n),o.value="",window.localStorage.setItem("schnack-draft-"+c,o.value),e()})}),f.addEventListener("click",function(t){var e=o.value;o.style.display="none",f.style.display="none",i.style.display="block",p.style.display="inline",n(r+"/markdown",{credentials:"include",method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({comment:e})}).then(function(n){return n.json()}).then(function(n){console.log(n),i.innerHTML=n.html})}),p.addEventListener("click",function(n){o.style.display="inline",f.style.display="inline",i.style.display="none",p.style.display="none"}),o.addEventListener("keyup",function(){window.localStorage.setItem("schnack-draft-"+c,o.value)})),s.user){var k=a("a.schnack-signout");k&&k.addEventListener("click",function(t){t.preventDefault(),n(r+"/signout",{credentials:"include",headers:{"Content-Type":"application/json"}}).then(function(n){return n.json()}).then(function(n){console.log(n),e()})})}else s.auth.forEach(function(n){var t=a(u+" .schnack-signin-"+n.id);t&&t.addEventListener("click",function(t){var a=window.open(r+"/auth/"+n.id,n.name+" Sign-In","resizable,scrollbars,status,width=600,height=500");window.__schnack_wait_for_oauth=function(){a.close(),e()}})});if(s.user&&s.user.admin){var m=function(t){var a=t.target.dataset;n(r+"/"+a.class+"/"+a.target+"/"+a.action,{credentials:"include",method:"POST",headers:{"Content-Type":"application/json"},body:""}).then(function(n){return n.json()}).then(function(n){console.log(n),e()})};document.querySelectorAll(".schnack-action").forEach(function(n){n.addEventListener("click",m)})}})}var a=function(n){return document.querySelector(n)},s=a("script[data-schnack-target]");if(!s)return console.warn("schnack script tag needs some data attributes");var o=s.dataset,c=o.schnackSlug,i=new URL(s.getAttribute("src")),r=i.protocol+"//"+i.host,l=r+"/comments/"+c,u=o.schnackTarget;document.domain=i.host.split(".").slice(1).join("."),e()}()}(); diff --git a/package-lock.json b/package-lock.json index 112023e..4813476 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "schnack", - "version": "0.1.0-alpha", + "version": "0.1.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -314,7 +314,6 @@ "requires": { "anymatch": "1.3.2", "async-each": "1.0.1", - "fsevents": "1.1.2", "glob-parent": "2.0.0", "inherits": "2.0.3", "is-binary-path": "1.0.1", @@ -764,905 +763,6 @@ "integrity": "sha1-g8YK/Fi5xWmXAH7Rp2izqzA6RP4=", "dev": true }, - "fsevents": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.1.2.tgz", - "integrity": "sha512-Sn44E5wQW4bTHXvQmvSHwqbuiXtduD6Rrjm2ZtUEGbyrig+nUH3t/QD4M4/ZXViY556TBpRgZkHLDx3JxPwxiw==", - "dev": true, - "optional": true, - "requires": { - "nan": "2.7.0", - "node-pre-gyp": "0.6.36" - }, - "dependencies": { - "abbrev": { - "version": "1.1.0", - "bundled": true, - "dev": true, - "optional": true - }, - "ajv": { - "version": "4.11.8", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "co": "4.6.0", - "json-stable-stringify": "1.0.1" - } - }, - "ansi-regex": { - "version": "2.1.1", - "bundled": true, - "dev": true - }, - "aproba": { - "version": "1.1.1", - "bundled": true, - "dev": true, - "optional": true - }, - "are-we-there-yet": { - "version": "1.1.4", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "delegates": "1.0.0", - "readable-stream": "2.2.9" - } - }, - "asn1": { - "version": "0.2.3", - "bundled": true, - "dev": true, - "optional": true - }, - "assert-plus": { - "version": "0.2.0", - "bundled": true, - "dev": true, - "optional": true - }, - "asynckit": { - "version": "0.4.0", - "bundled": true, - "dev": true, - "optional": true - }, - "aws-sign2": { - "version": "0.6.0", - "bundled": true, - "dev": true, - "optional": true - }, - "aws4": { - "version": "1.6.0", - "bundled": true, - "dev": true, - "optional": true - }, - "balanced-match": { - "version": "0.4.2", - "bundled": true, - "dev": true - }, - "bcrypt-pbkdf": { - "version": "1.0.1", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "tweetnacl": "0.14.5" - } - }, - "block-stream": { - "version": "0.0.9", - "bundled": true, - "dev": true, - "requires": { - "inherits": "2.0.3" - } - }, - "boom": { - "version": "2.10.1", - "bundled": true, - "dev": true, - "requires": { - "hoek": "2.16.3" - } - }, - "brace-expansion": { - "version": "1.1.7", - "bundled": true, - "dev": true, - "requires": { - "balanced-match": "0.4.2", - "concat-map": "0.0.1" - } - }, - "buffer-shims": { - "version": "1.0.0", - "bundled": true, - "dev": true - }, - "caseless": { - "version": "0.12.0", - "bundled": true, - "dev": true, - "optional": true - }, - "co": { - "version": "4.6.0", - "bundled": true, - "dev": true, - "optional": true - }, - "code-point-at": { - "version": "1.1.0", - "bundled": true, - "dev": true - }, - "combined-stream": { - "version": "1.0.5", - "bundled": true, - "dev": true, - "requires": { - "delayed-stream": "1.0.0" - } - }, - "concat-map": { - "version": "0.0.1", - "bundled": true, - "dev": true - }, - "console-control-strings": { - "version": "1.1.0", - "bundled": true, - "dev": true - }, - "core-util-is": { - "version": "1.0.2", - "bundled": true, - "dev": true - }, - "cryptiles": { - "version": "2.0.5", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "boom": "2.10.1" - } - }, - "dashdash": { - "version": "1.14.1", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "assert-plus": "1.0.0" - }, - "dependencies": { - "assert-plus": { - "version": "1.0.0", - "bundled": true, - "dev": true, - "optional": true - } - } - }, - "debug": { - "version": "2.6.8", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "ms": "2.0.0" - } - }, - "deep-extend": { - "version": "0.4.2", - "bundled": true, - "dev": true, - "optional": true - }, - "delayed-stream": { - "version": "1.0.0", - "bundled": true, - "dev": true - }, - "delegates": { - "version": "1.0.0", - "bundled": true, - "dev": true, - "optional": true - }, - "ecc-jsbn": { - "version": "0.1.1", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "jsbn": "0.1.1" - } - }, - "extend": { - "version": "3.0.1", - "bundled": true, - "dev": true, - "optional": true - }, - "extsprintf": { - "version": "1.0.2", - "bundled": true, - "dev": true - }, - "forever-agent": { - "version": "0.6.1", - "bundled": true, - "dev": true, - "optional": true - }, - "form-data": { - "version": "2.1.4", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "asynckit": "0.4.0", - "combined-stream": "1.0.5", - "mime-types": "2.1.15" - } - }, - "fs.realpath": { - "version": "1.0.0", - "bundled": true, - "dev": true - }, - "fstream": { - "version": "1.0.11", - "bundled": true, - "dev": true, - "requires": { - "graceful-fs": "4.1.11", - "inherits": "2.0.3", - "mkdirp": "0.5.1", - "rimraf": "2.6.1" - } - }, - "fstream-ignore": { - "version": "1.0.5", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "fstream": "1.0.11", - "inherits": "2.0.3", - "minimatch": "3.0.4" - } - }, - "gauge": { - "version": "2.7.4", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "aproba": "1.1.1", - "console-control-strings": "1.1.0", - "has-unicode": "2.0.1", - "object-assign": "4.1.1", - "signal-exit": "3.0.2", - "string-width": "1.0.2", - "strip-ansi": "3.0.1", - "wide-align": "1.1.2" - } - }, - "getpass": { - "version": "0.1.7", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "assert-plus": "1.0.0" - }, - "dependencies": { - "assert-plus": { - "version": "1.0.0", - "bundled": true, - "dev": true, - "optional": true - } - } - }, - "glob": { - "version": "7.1.2", - "bundled": true, - "dev": true, - "requires": { - "fs.realpath": "1.0.0", - "inflight": "1.0.6", - "inherits": "2.0.3", - "minimatch": "3.0.4", - "once": "1.4.0", - "path-is-absolute": "1.0.1" - } - }, - "graceful-fs": { - "version": "4.1.11", - "bundled": true, - "dev": true - }, - "har-schema": { - "version": "1.0.5", - "bundled": true, - "dev": true, - "optional": true - }, - "har-validator": { - "version": "4.2.1", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "ajv": "4.11.8", - "har-schema": "1.0.5" - } - }, - "has-unicode": { - "version": "2.0.1", - "bundled": true, - "dev": true, - "optional": true - }, - "hawk": { - "version": "3.1.3", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "boom": "2.10.1", - "cryptiles": "2.0.5", - "hoek": "2.16.3", - "sntp": "1.0.9" - } - }, - "hoek": { - "version": "2.16.3", - "bundled": true, - "dev": true - }, - "http-signature": { - "version": "1.1.1", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "assert-plus": "0.2.0", - "jsprim": "1.4.0", - "sshpk": "1.13.0" - } - }, - "inflight": { - "version": "1.0.6", - "bundled": true, - "dev": true, - "requires": { - "once": "1.4.0", - "wrappy": "1.0.2" - } - }, - "inherits": { - "version": "2.0.3", - "bundled": true, - "dev": true - }, - "ini": { - "version": "1.3.4", - "bundled": true, - "dev": true, - "optional": true - }, - "is-fullwidth-code-point": { - "version": "1.0.0", - "bundled": true, - "dev": true, - "requires": { - "number-is-nan": "1.0.1" - } - }, - "is-typedarray": { - "version": "1.0.0", - "bundled": true, - "dev": true, - "optional": true - }, - "isarray": { - "version": "1.0.0", - "bundled": true, - "dev": true - }, - "isstream": { - "version": "0.1.2", - "bundled": true, - "dev": true, - "optional": true - }, - "jodid25519": { - "version": "1.0.2", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "jsbn": "0.1.1" - } - }, - "jsbn": { - "version": "0.1.1", - "bundled": true, - "dev": true, - "optional": true - }, - "json-schema": { - "version": "0.2.3", - "bundled": true, - "dev": true, - "optional": true - }, - "json-stable-stringify": { - "version": "1.0.1", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "jsonify": "0.0.0" - } - }, - "json-stringify-safe": { - "version": "5.0.1", - "bundled": true, - "dev": true, - "optional": true - }, - "jsonify": { - "version": "0.0.0", - "bundled": true, - "dev": true, - "optional": true - }, - "jsprim": { - "version": "1.4.0", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "assert-plus": "1.0.0", - "extsprintf": "1.0.2", - "json-schema": "0.2.3", - "verror": "1.3.6" - }, - "dependencies": { - "assert-plus": { - "version": "1.0.0", - "bundled": true, - "dev": true, - "optional": true - } - } - }, - "mime-db": { - "version": "1.27.0", - "bundled": true, - "dev": true - }, - "mime-types": { - "version": "2.1.15", - "bundled": true, - "dev": true, - "requires": { - "mime-db": "1.27.0" - } - }, - "minimatch": { - "version": "3.0.4", - "bundled": true, - "dev": true, - "requires": { - "brace-expansion": "1.1.7" - } - }, - "minimist": { - "version": "0.0.8", - "bundled": true, - "dev": true - }, - "mkdirp": { - "version": "0.5.1", - "bundled": true, - "dev": true, - "requires": { - "minimist": "0.0.8" - } - }, - "ms": { - "version": "2.0.0", - "bundled": true, - "dev": true, - "optional": true - }, - "node-pre-gyp": { - "version": "0.6.36", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "mkdirp": "0.5.1", - "nopt": "4.0.1", - "npmlog": "4.1.0", - "rc": "1.2.1", - "request": "2.81.0", - "rimraf": "2.6.1", - "semver": "5.3.0", - "tar": "2.2.1", - "tar-pack": "3.4.0" - } - }, - "nopt": { - "version": "4.0.1", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "abbrev": "1.1.0", - "osenv": "0.1.4" - } - }, - "npmlog": { - "version": "4.1.0", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "are-we-there-yet": "1.1.4", - "console-control-strings": "1.1.0", - "gauge": "2.7.4", - "set-blocking": "2.0.0" - } - }, - "number-is-nan": { - "version": "1.0.1", - "bundled": true, - "dev": true - }, - "oauth-sign": { - "version": "0.8.2", - "bundled": true, - "dev": true, - "optional": true - }, - "object-assign": { - "version": "4.1.1", - "bundled": true, - "dev": true, - "optional": true - }, - "once": { - "version": "1.4.0", - "bundled": true, - "dev": true, - "requires": { - "wrappy": "1.0.2" - } - }, - "os-homedir": { - "version": "1.0.2", - "bundled": true, - "dev": true, - "optional": true - }, - "os-tmpdir": { - "version": "1.0.2", - "bundled": true, - "dev": true, - "optional": true - }, - "osenv": { - "version": "0.1.4", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "os-homedir": "1.0.2", - "os-tmpdir": "1.0.2" - } - }, - "path-is-absolute": { - "version": "1.0.1", - "bundled": true, - "dev": true - }, - "performance-now": { - "version": "0.2.0", - "bundled": true, - "dev": true, - "optional": true - }, - "process-nextick-args": { - "version": "1.0.7", - "bundled": true, - "dev": true - }, - "punycode": { - "version": "1.4.1", - "bundled": true, - "dev": true, - "optional": true - }, - "qs": { - "version": "6.4.0", - "bundled": true, - "dev": true, - "optional": true - }, - "rc": { - "version": "1.2.1", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "deep-extend": "0.4.2", - "ini": "1.3.4", - "minimist": "1.2.0", - "strip-json-comments": "2.0.1" - }, - "dependencies": { - "minimist": { - "version": "1.2.0", - "bundled": true, - "dev": true, - "optional": true - } - } - }, - "readable-stream": { - "version": "2.2.9", - "bundled": true, - "dev": true, - "requires": { - "buffer-shims": "1.0.0", - "core-util-is": "1.0.2", - "inherits": "2.0.3", - "isarray": "1.0.0", - "process-nextick-args": "1.0.7", - "string_decoder": "1.0.1", - "util-deprecate": "1.0.2" - } - }, - "request": { - "version": "2.81.0", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "aws-sign2": "0.6.0", - "aws4": "1.6.0", - "caseless": "0.12.0", - "combined-stream": "1.0.5", - "extend": "3.0.1", - "forever-agent": "0.6.1", - "form-data": "2.1.4", - "har-validator": "4.2.1", - "hawk": "3.1.3", - "http-signature": "1.1.1", - "is-typedarray": "1.0.0", - "isstream": "0.1.2", - "json-stringify-safe": "5.0.1", - "mime-types": "2.1.15", - "oauth-sign": "0.8.2", - "performance-now": "0.2.0", - "qs": "6.4.0", - "safe-buffer": "5.0.1", - "stringstream": "0.0.5", - "tough-cookie": "2.3.2", - "tunnel-agent": "0.6.0", - "uuid": "3.0.1" - } - }, - "rimraf": { - "version": "2.6.1", - "bundled": true, - "dev": true, - "requires": { - "glob": "7.1.2" - } - }, - "safe-buffer": { - "version": "5.0.1", - "bundled": true, - "dev": true - }, - "semver": { - "version": "5.3.0", - "bundled": true, - "dev": true, - "optional": true - }, - "set-blocking": { - "version": "2.0.0", - "bundled": true, - "dev": true, - "optional": true - }, - "signal-exit": { - "version": "3.0.2", - "bundled": true, - "dev": true, - "optional": true - }, - "sntp": { - "version": "1.0.9", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "hoek": "2.16.3" - } - }, - "sshpk": { - "version": "1.13.0", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "asn1": "0.2.3", - "assert-plus": "1.0.0", - "bcrypt-pbkdf": "1.0.1", - "dashdash": "1.14.1", - "ecc-jsbn": "0.1.1", - "getpass": "0.1.7", - "jodid25519": "1.0.2", - "jsbn": "0.1.1", - "tweetnacl": "0.14.5" - }, - "dependencies": { - "assert-plus": { - "version": "1.0.0", - "bundled": true, - "dev": true, - "optional": true - } - } - }, - "string-width": { - "version": "1.0.2", - "bundled": true, - "dev": true, - "requires": { - "code-point-at": "1.1.0", - "is-fullwidth-code-point": "1.0.0", - "strip-ansi": "3.0.1" - } - }, - "string_decoder": { - "version": "1.0.1", - "bundled": true, - "dev": true, - "requires": { - "safe-buffer": "5.0.1" - } - }, - "stringstream": { - "version": "0.0.5", - "bundled": true, - "dev": true, - "optional": true - }, - "strip-ansi": { - "version": "3.0.1", - "bundled": true, - "dev": true, - "requires": { - "ansi-regex": "2.1.1" - } - }, - "strip-json-comments": { - "version": "2.0.1", - "bundled": true, - "dev": true, - "optional": true - }, - "tar": { - "version": "2.2.1", - "bundled": true, - "dev": true, - "requires": { - "block-stream": "0.0.9", - "fstream": "1.0.11", - "inherits": "2.0.3" - } - }, - "tar-pack": { - "version": "3.4.0", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "debug": "2.6.8", - "fstream": "1.0.11", - "fstream-ignore": "1.0.5", - "once": "1.4.0", - "readable-stream": "2.2.9", - "rimraf": "2.6.1", - "tar": "2.2.1", - "uid-number": "0.0.6" - } - }, - "tough-cookie": { - "version": "2.3.2", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "punycode": "1.4.1" - } - }, - "tunnel-agent": { - "version": "0.6.0", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "safe-buffer": "5.0.1" - } - }, - "tweetnacl": { - "version": "0.14.5", - "bundled": true, - "dev": true, - "optional": true - }, - "uid-number": { - "version": "0.0.6", - "bundled": true, - "dev": true, - "optional": true - }, - "util-deprecate": { - "version": "1.0.2", - "bundled": true, - "dev": true - }, - "uuid": { - "version": "3.0.1", - "bundled": true, - "dev": true, - "optional": true - }, - "verror": { - "version": "1.3.6", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "extsprintf": "1.0.2" - } - }, - "wide-align": { - "version": "1.1.2", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "string-width": "1.0.2" - } - }, - "wrappy": { - "version": "1.0.2", - "bundled": true, - "dev": true - } - } - }, "get-stream": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", @@ -1802,11 +902,6 @@ "union": "0.4.6" } }, - "httpreq": { - "version": "0.4.24", - "resolved": "https://registry.npmjs.org/httpreq/-/httpreq-0.4.24.tgz", - "integrity": "sha1-QzX/2CzZaWaKOUZckprGHWOTYn8=" - }, "iconv-lite": { "version": "0.4.19", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz", @@ -2286,14 +1381,6 @@ "lower-case": "1.1.4" } }, - "node-pushover": { - "version": "0.2.2", - "resolved": "https://registry.npmjs.org/node-pushover/-/node-pushover-0.2.2.tgz", - "integrity": "sha1-IrgSYwx1VJAZ69M1Ue9l2aRHNDI=", - "requires": { - "httpreq": "0.4.24" - } - }, "nodemon": { "version": "1.12.1", "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-1.12.1.tgz", @@ -2595,6 +1682,11 @@ "integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM=", "dev": true }, + "pushover-notifications": { + "version": "0.2.4", + "resolved": "https://registry.npmjs.org/pushover-notifications/-/pushover-notifications-0.2.4.tgz", + "integrity": "sha1-icuU+RgsNqpZqaxnROSa2K/00Gc=" + }, "qs": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/qs/-/qs-2.3.3.tgz", @@ -3734,6 +2826,14 @@ } } }, + "string_decoder": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", + "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", + "requires": { + "safe-buffer": "5.1.1" + } + }, "string-width": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", @@ -3744,14 +2844,6 @@ "strip-ansi": "3.0.1" } }, - "string_decoder": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", - "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", - "requires": { - "safe-buffer": "5.1.1" - } - }, "stringstream": { "version": "0.0.5", "resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz", @@ -3878,6 +2970,15 @@ "duplexer": "0.1.1" } }, + "string_decoder": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", + "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", + "dev": true, + "requires": { + "safe-buffer": "5.1.1" + } + }, "string-width": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", @@ -3888,15 +2989,6 @@ "strip-ansi": "4.0.0" } }, - "string_decoder": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", - "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", - "dev": true, - "requires": { - "safe-buffer": "5.1.1" - } - }, "strip-ansi": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", diff --git a/package.json b/package.json index a90d164..4a254f5 100644 --- a/package.json +++ b/package.json @@ -10,10 +10,10 @@ "lodash.countby": "^4.6.0", "marked": "^0.3.6", "moment": "^2.18.1", - "node-pushover": "^0.2.2", "passport": "^0.4.0", "passport-github2": "^0.1.11", "passport-twitter": "^1.0.4", + "pushover-notifications": "^0.2.4", "rss": "^1.2.2", "sqlite3": "^3.1.13", "unfetch": "^3.0.0" diff --git a/src/db/queries.js b/src/db/queries.js index e65e9d0..661d35f 100644 --- a/src/db/queries.js +++ b/src/db/queries.js @@ -41,5 +41,10 @@ module.exports = { `INSERT INTO user (provider, provider_id, display_name, name, created_at, trusted, blocked) - VALUES (?, ?, ?, ?, datetime(), ?, 0)` + VALUES (?, ?, ?, ?, datetime(), ?, 0)`, + set_settings: + `INSERT OR REPLACE INTO setting (id, value) + VALUES (?, ?)`, + get_settings: + `SELECT value FROM setting WHERE id = "notification"` }; diff --git a/src/db/schema.sql b/src/db/schema.sql index 505a305..3a73733 100644 --- a/src/db/schema.sql +++ b/src/db/schema.sql @@ -18,3 +18,8 @@ CREATE TABLE user ( blocked BOOLEAN, trusted BOOLEAN ); + +CREATE TABLE setting ( + id CHAR(128) PRIMARY KEY NOT NULL, + value BOOLEAN +); diff --git a/src/embed/comments.jst.html b/src/embed/comments.jst.html index 5aacaaa..ecf2811 100644 --- a/src/embed/comments.jst.html +++ b/src/embed/comments.jst.html @@ -1,4 +1,10 @@ <% if (data.user) { %> + <% if (data.user.admin) { %> +
+ + +
+ <% } %>
diff --git a/src/server.js b/src/server.js index 65ee337..31ae4e4 100644 --- a/src/server.js +++ b/src/server.js @@ -10,7 +10,7 @@ const moment = require('moment'); const countBy = require('lodash.countby'); const RSS = require('rss'); -const Pushover = require('node-pushover'); +const Pushover = require('pushover-notifications'); const marked = require('marked'); const dbHandler = require('./db'); @@ -146,6 +146,16 @@ function run(db) { reply.send({ html: marked(comment.trim()) }); }); + app.post('/setting/:property/:value', (request, reply) => { + const { property, value } = request.params; + const { user } = request.session.passport || {}; + if (!isAdmin(user)) return reply.status(403).send(request.params); + db.run(queries.set_settings, property, value, (err) => { + if (error(err, request, reply)) return; + reply.send({ status: 'ok' }); + }); + }); + // push notification apps const notifier = []; @@ -156,7 +166,7 @@ function run(db) { token: config.notify.pushover.app_token, user: config.notify.pushover.user_key }); - notifier.push((msg, callback) => push.send(null, msg, callback) ); + notifier.push((msg, callback) => push.send(msg, callback)); } // check for new comments in need of moderation @@ -170,12 +180,21 @@ function run(db) { function next(err) { var k = Object.keys(bySlug)[0]; if (!k || err) return; - var cnt = bySlug[k], - msg = `${cnt} new comment${cnt>1?'s':''} on "${k}" are awaiting moderation.`; - delete bySlug[k]; - setTimeout(() => { - notifier.forEach((f) => f(msg, next)); - }, 1000); + db.get(queries.get_settings, (err, row) => { + if (err) console.error(err.message); + + var cnt = bySlug[k], + msg = { + message: `${cnt} new comment${cnt>1?'s':''} on "${k}" are awaiting moderation.`, + url: url.resolve(config.schnack_host, k), + sound: (row.value === 'true') ? 'pushover' : 'none' + }; + console.log(msg); + delete bySlug[k]; + setTimeout(() => { + notifier.forEach((f) => f(msg, next)); + }, 1000); + }); } }, config.notification_interval || 300000); // five minutes