summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2017-05-21 02:44:05 +0200
committerJules Laplace <julescarbon@gmail.com>2017-05-21 02:44:05 +0200
commitd91a5283e2c9246760c110332e59513de62cfa07 (patch)
tree7509e4bf897232deb558ec2f32aed1a190fcd4ba
parent113eca6e9d60c923da82474941acf5c9640bd917 (diff)
new backend to fetch feedback from a google doc
-rw-r--r--index.js6
-rw-r--r--lib/awfeedback/index.js63
-rw-r--r--lib/awfeedback/package.json15
-rw-r--r--lib/awfeedback/tokens/client_secret.json1
-rw-r--r--lib/awfeedback/tokens/client_token.json1
-rw-r--r--lib/okpush/index.js2
-rw-r--r--templates/photo.liquid11
7 files changed, 96 insertions, 3 deletions
diff --git a/index.js b/index.js
index 2c1a91a..dbfb6c7 100644
--- a/index.js
+++ b/index.js
@@ -114,6 +114,12 @@ var app = okcms.createApp({
from: 'Hansel and Gretel <mail@hanselandgretelarmory.com>',
subject: 'We Found Your Face',
},
+ awfeedback: {
+ lib: require("./lib/awfeedback"),
+ spreadsheet: '12fUN-pUlTpdly88pGVFlHuHDmAP8YCpVfn9IxIVf5Vs',
+ credentials: path.join(__dirname, "./lib/awfeedback/tokens/client_secret.json"),
+ token: path.join(__dirname, "./lib/awfeedback/tokens/client_token.json"),
+ },
push: {
lib: require("./lib/okpush"),
mongodbUrl: "mongodb://localhost/okpush_hga",
diff --git a/lib/awfeedback/index.js b/lib/awfeedback/index.js
new file mode 100644
index 0000000..187661b
--- /dev/null
+++ b/lib/awfeedback/index.js
@@ -0,0 +1,63 @@
+var fs = require('fs')
+var google = require('googleapis')
+var googleAuth = require('google-auth-library')
+
+function AWFeedback (options) { if (!(this instanceof AWFeedback)) return new AWFeedback(options)
+ options = options || {}
+ if (!options.express)
+ throw new Error('Express not provided to AWFeedback');
+ if (!options.config)
+ throw new Error('Configuration not provided to AWFeedback');
+
+ var express = options.express
+ var router = express.Router()
+ var config = options.config
+ var db = options.db
+
+ console.log(config)
+
+ var credentials = JSON.parse( fs.readFileSync(config.credentials) )
+ var token = JSON.parse( fs.readFileSync(config.token) )
+
+ var clientSecret = credentials.installed.client_secret
+ var clientId = credentials.installed.client_id
+ var redirectUrl = credentials.installed.redirect_uris[0]
+ var gauth = new googleAuth()
+ var auth = new gauth.OAuth2(clientId, clientSecret, redirectUrl)
+ auth.credentials = token
+
+ var sheets = google.sheets('v4');
+
+ router.get('/index', function (req, res) {
+ sheets.spreadsheets.values.get({
+ auth: auth,
+ spreadsheetId: config.spreadsheet,
+ range: 'Form Responses 1!A2:E',
+ }, function(err, response) {
+ if (err) {
+ res.json([])
+ return
+ }
+ var rows = response.values;
+ if (rows.length == 0) {
+ res.json([])
+ } else {
+ var parsed = rows.filter( row => row[4] === 'x' || row[4] === 'X' )
+ .map( row => [ row[0], row[1], row[3] ] )
+ res.json(parsed)
+ }
+ });
+ })
+
+ router.post('*', function (req, res) {
+ throw new Error('AWFeedback POST requests not implemented')
+ })
+
+ this._router = router
+}
+
+AWFeedback.prototype.middleware = function () {
+ return this._router
+}
+
+module.exports = AWFeedback
diff --git a/lib/awfeedback/package.json b/lib/awfeedback/package.json
new file mode 100644
index 0000000..4864e41
--- /dev/null
+++ b/lib/awfeedback/package.json
@@ -0,0 +1,15 @@
+{
+ "name": "awfeedback",
+ "version": "1.0.0",
+ "description": "",
+ "main": "index.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "author": "",
+ "license": "UNLICENSED",
+ "dependencies": {
+ "google-auth-library": "^0.10.0",
+ "googleapis": "^19.0.0"
+ }
+}
diff --git a/lib/awfeedback/tokens/client_secret.json b/lib/awfeedback/tokens/client_secret.json
new file mode 100644
index 0000000..4973155
--- /dev/null
+++ b/lib/awfeedback/tokens/client_secret.json
@@ -0,0 +1 @@
+{"installed":{"client_id":"607110202132-nenuro8k1eto67iorj6gkjncqrc4kfi6.apps.googleusercontent.com","project_id":"aerial-valor-168323","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://accounts.google.com/o/oauth2/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"8FeJgtC1Cv-FttEZPrSe7KHp","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]}} \ No newline at end of file
diff --git a/lib/awfeedback/tokens/client_token.json b/lib/awfeedback/tokens/client_token.json
new file mode 100644
index 0000000..8faae0c
--- /dev/null
+++ b/lib/awfeedback/tokens/client_token.json
@@ -0,0 +1 @@
+{"access_token":"ya29.GltQBM77mgZn34e0222_9njAqHHqj-KemaAmWEkmojLt224L20CYUyxyq5OoiQVGtVXEAAsQQYY95qGQjigQwTjg9pVMi71QAENejf43FjMlb1AucdPGEa390ERT","refresh_token":"1/glG1o8edgir-nUU9ln8E0Fc5MI3zzmlBPDqFHDYfV8Y","token_type":"Bearer","expiry_date":1495328054832} \ No newline at end of file
diff --git a/lib/okpush/index.js b/lib/okpush/index.js
index 5e6b040..67b7c00 100644
--- a/lib/okpush/index.js
+++ b/lib/okpush/index.js
@@ -114,6 +114,8 @@ function OKPush (options) {
channel: req.body.channel,
platform: req.body.platform,
})
+ .then( () => console.log('added new token') )
+ .catch( () => console.log('caught error') )
res.sendStatus(200)
})
diff --git a/templates/photo.liquid b/templates/photo.liquid
index 481e715..278d4fe 100644
--- a/templates/photo.liquid
+++ b/templates/photo.liquid
@@ -169,8 +169,13 @@ a {
</body>
<script>
var hash = document.location.pathname.replace('/photo/','').replace(/\/.*/,'')
-var img = new Image
-img.src = 'https://marsupial.s3.amazonaws.com/armory/mail/' + hash + '.jpg'
-document.querySelector('#container').appendChild(img)
+image('dots')
+image('lines')
+image('plain')
+function image(hash, type) {
+ var img = new Image
+ img.src = 'https://marsupial.s3.amazonaws.com/armory/mail/' + hash + '-' + type + '.jpg'
+ document.querySelector('#container').appendChild(img)
+}
</script>
</html>