From c9da5b80780bfbc7855ab7d2e716ce12756f64ed Mon Sep 17 00:00:00 2001 From: Abhinav Adduri Date: Wed, 21 Jun 2017 13:23:36 -0700 Subject: [PATCH 1/2] added notifications --- frontend/src/download.js | 2 ++ frontend/src/fileSender.js | 4 ++-- frontend/src/upload.js | 4 ++++ frontend/src/utils.js | 16 +++++++++++++++- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/frontend/src/download.js b/frontend/src/download.js index 5ad2fb3e..05abb64b 100644 --- a/frontend/src/download.js +++ b/frontend/src/download.js @@ -1,4 +1,5 @@ const FileReceiver = require('./fileReceiver'); +const { notify } = require('./utils'); const $ = require('jquery'); $(document).ready(function() { @@ -16,6 +17,7 @@ $(document).ready(function() { if (percentComplete === 100) { fileReceiver.removeAllListeners('progress'); + notify('Your download has finished.'); btn.text('Download complete!'); btn.attr('disabled', 'true'); } diff --git a/frontend/src/fileSender.js b/frontend/src/fileSender.js index 8a70c2f9..fea1daf2 100644 --- a/frontend/src/fileSender.js +++ b/frontend/src/fileSender.js @@ -1,5 +1,5 @@ const EventEmitter = require('events'); -const { ivToStr } = require('./utils'); +const { ivToStr, notify } = require('./utils'); class FileSender extends EventEmitter { constructor(file) { @@ -23,7 +23,7 @@ class FileSender extends EventEmitter { } if (xhr.status === 200) { - console.log('The file was successfully deleted.'); + console.log('The file was successfully deleted.') } else { console.log('The file has expired, or has already been deleted.'); } diff --git a/frontend/src/upload.js b/frontend/src/upload.js index 17d4a3b8..96159ded 100644 --- a/frontend/src/upload.js +++ b/frontend/src/upload.js @@ -1,4 +1,5 @@ const FileSender = require('./fileSender'); +const { notify } = require('./utils') const $ = require('jquery'); $(document).ready(function() { @@ -84,6 +85,9 @@ $(document).ready(function() { $('#upload-progress').show(); $('#upload-filename').innerHTML += file.name; progress.innerText = `Progress: ${percentComplete}%`; + if (percentComplete === 100) { + notify('Your upload has finished.'); + } }); fileSender.upload().then(info => { const url = info.url.trim() + `#${info.secretKey}`.trim(); diff --git a/frontend/src/utils.js b/frontend/src/utils.js index a95026f8..3c504705 100644 --- a/frontend/src/utils.js +++ b/frontend/src/utils.js @@ -20,7 +20,21 @@ function strToIv(str) { return iv; } +function notify(str) { + if (!("Notification" in window)) { + return; + } else if (Notification.permission === 'granted') { + new Notification(str) + } else if (Notification.permission !== 'denied') { + Notification.requestPermission(function(permission) { + if (permission === 'granted') + new Notification(str); + }) + } +} + module.exports = { ivToStr, - strToIv + strToIv, + notify }; From 575f04a8246f6a359ee7e634ffbe1b9500619671 Mon Sep 17 00:00:00 2001 From: Abhinav Adduri Date: Wed, 21 Jun 2017 13:54:24 -0700 Subject: [PATCH 2/2] added in anonmyized ip google analytics --- server/config.js | 5 +++++ server/portal_server.js | 14 +++++++++++--- views/download.handlebars | 3 +++ views/index.handlebars | 3 +++ views/partials/analytics.handlebars | 10 ++++++++++ 5 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 views/partials/analytics.handlebars diff --git a/server/config.js b/server/config.js index 7e793f78..fd04dc57 100644 --- a/server/config.js +++ b/server/config.js @@ -22,6 +22,11 @@ const conf = convict({ arg: 'port', env: 'PORT' }, + analytics_id: { + format: String, + default: 'UA-101393094-1', + env: 'GOOGLE_ANALYTICS_ID' + }, env: { format: ['production', 'development', 'test'], default: 'development', diff --git a/server/portal_server.js b/server/portal_server.js index c6f74c68..5b129401 100644 --- a/server/portal_server.js +++ b/server/portal_server.js @@ -16,7 +16,10 @@ const log = mozlog('portal.server'); const app = express(); -app.engine('handlebars', exphbs({ defaultLayout: 'main' })); +app.engine('handlebars', exphbs({ + defaultLayout: 'main', + partialsDir: 'views/partials/' +})); app.set('view engine', 'handlebars'); app.use(helmet()); @@ -25,7 +28,10 @@ app.use(bodyParser.json()); app.use(express.static(path.join(__dirname, '../public'))); app.get('/', (req, res) => { - res.render('index'); + res.render('index', { + shouldRenderAnalytics: notLocalHost, + trackerId: conf.analytics_id + }); }); app.get('/exists/:id', (req, res) => { @@ -43,7 +49,9 @@ app.get('/download/:id', (req, res) => { .then(contentLength => { res.render('download', { filename: filename, - filesize: bytes(contentLength) + filesize: bytes(contentLength), + shouldRenderAnalytics: notLocalHost, + trackerId: conf.analytics_id }); }) .catch(() => { diff --git a/views/download.handlebars b/views/download.handlebars index da97535f..229184f6 100644 --- a/views/download.handlebars +++ b/views/download.handlebars @@ -6,6 +6,9 @@ + {{#if shouldRenderAnalytics}} + {{> analytics trackerId=trackerId}} + {{/if}} diff --git a/views/index.handlebars b/views/index.handlebars index 9dd4a70f..d66cda60 100644 --- a/views/index.handlebars +++ b/views/index.handlebars @@ -6,6 +6,9 @@ + {{#if shouldRenderAnalytics}} + {{> analytics trackerId=trackerId}} + {{/if}} diff --git a/views/partials/analytics.handlebars b/views/partials/analytics.handlebars new file mode 100644 index 00000000..4f6aaff9 --- /dev/null +++ b/views/partials/analytics.handlebars @@ -0,0 +1,10 @@ + \ No newline at end of file