From 4cb040d70dda7df4b4dede6751efd8ab5bfc955b Mon Sep 17 00:00:00 2001 From: Danny Coates Date: Mon, 24 Jul 2017 13:07:49 -0700 Subject: [PATCH] added environment variable for expire time --- frontend/src/upload.js | 4 ++-- server/config.js | 5 +++++ server/server.js | 1 + server/storage.js | 4 ++-- test/unit/aws.storage.test.js | 2 +- views/jsconfig.handlebars | 1 + 6 files changed, 12 insertions(+), 5 deletions(-) diff --git a/frontend/src/upload.js b/frontend/src/upload.js index 85c6fedc..cb05ec32 100644 --- a/frontend/src/upload.js +++ b/frontend/src/upload.js @@ -1,4 +1,4 @@ -/* global MAXFILESIZE */ +/* global MAXFILESIZE EXPIRE_SECONDS */ require('./common'); const FileSender = require('./fileSender'); const { @@ -256,7 +256,7 @@ $(document).ready(function() { const totalTime = endTime - startTime; const uploadTime = endTime - uploadStart; const uploadSpeed = file.size / (uploadTime / 1000); - const expiration = 24 * 60 * 60 * 1000; //will eventually come from a field + const expiration = EXPIRE_SECONDS * 1000; // record upload-stopped (completed) by sender sendEvent('sender', 'upload-stopped', { diff --git a/server/config.js b/server/config.js index 526d4eea..b3a2c5b1 100644 --- a/server/config.js +++ b/server/config.js @@ -41,6 +41,11 @@ const conf = convict({ format: Number, default: 1024 * 1024 * 1024 * 2, env: 'P2P_MAX_FILE_SIZE' + }, + expire_seconds: { + format: Number, + default: 86400, + env: 'EXPIRE_SECONDS' } }); diff --git a/server/server.js b/server/server.js index 873f6d6f..cd9c5e90 100644 --- a/server/server.js +++ b/server/server.js @@ -86,6 +86,7 @@ app.get('/jsconfig.js', (req, res) => { trackerId: conf.analytics_id, dsn: conf.sentry_id, maxFileSize: conf.max_file_size, + expireSeconds: conf.expire_seconds, layout: false }); }); diff --git a/server/storage.js b/server/storage.js index 40a699ec..66a1a192 100644 --- a/server/storage.js +++ b/server/storage.js @@ -152,7 +152,7 @@ function localSet(newId, file, filename, meta) { }); fstream.on('finish', () => { redis_client.hmset(newId, meta); - redis_client.expire(newId, 86400000); + redis_client.expire(newId, conf.expire_seconds); log.info('localSet:', 'Upload Finished of ' + newId); resolve(meta.delete); }); @@ -238,7 +238,7 @@ function awsSet(newId, file, filename, meta) { return upload.promise().then( () => { redis_client.hmset(newId, meta); - redis_client.expire(newId, 86400000); + redis_client.expire(newId, conf.expire_seconds); log.info('awsUploadFinish', 'Upload Finished of ' + filename); }, err => { diff --git a/test/unit/aws.storage.test.js b/test/unit/aws.storage.test.js index e7449d75..b4507e38 100644 --- a/test/unit/aws.storage.test.js +++ b/test/unit/aws.storage.test.js @@ -115,7 +115,7 @@ describe('Testing Set using aws', function() { .set('123', {on: sinon.stub()}, 'Filename.moz', {}) .then(() => { assert(expire.calledOnce); - assert(expire.calledWith('123', 86400000)); + assert(expire.calledWith('123', 86400)); }) .catch(err => assert.fail()); }); diff --git a/views/jsconfig.handlebars b/views/jsconfig.handlebars index 4ff25330..c9ddf16d 100644 --- a/views/jsconfig.handlebars +++ b/views/jsconfig.handlebars @@ -5,3 +5,4 @@ window.dsn = '{{{dsn}}}'; window.trackerId = '{{{trackerId}}}'; {{/if}} const MAXFILESIZE = {{{maxFileSize}}}; +const EXPIRE_SECONDS = {{{expireSeconds}}};