diff --git a/app/ui/expiryOptions.js b/app/ui/expiryOptions.js index 494093f4..2ee489f7 100644 --- a/app/ui/expiryOptions.js +++ b/app/ui/expiryOptions.js @@ -31,12 +31,11 @@ module.exports = function(state, emit) { counts, num => state.translate('downloadCount', { num }), value => { - const max = state.user.maxDownloads; - state.archive.dlimit = Math.min(value, max); - if (value > max) { - emit('signup-cta', 'count'); - } else { - emit('render'); + const selected = parseInt(value); + state.archive.dlimit = selected; + emit('render'); + if (selected > parseInt(state.user.maxDownloads || '0')) { + console.log('Chosen max download count is larger than the allowed limit', selected) } }, 'expire-after-dl-count-select' @@ -58,12 +57,11 @@ module.exports = function(state, emit) { return state.translate(l10n.id, l10n); }, value => { - const max = state.user.maxExpireSeconds; - state.archive.timeLimit = Math.min(value, max); - if (value > max) { - emit('signup-cta', 'time'); - } else { - emit('render'); + const selected = parseInt(value); + state.archive.timeLimit = selected; + emit('render'); + if (selected > parseInt(state.user.maxExpireSeconds || '0')) { + console.log('Chosen download expiration is larger than the allowed limit', selected) } }, 'expire-after-time-select' diff --git a/app/ui/selectbox.js b/app/ui/selectbox.js index cf1d1a4f..ce3e3ef8 100644 --- a/app/ui/selectbox.js +++ b/app/ui/selectbox.js @@ -1,32 +1,28 @@ const html = require('choo/html'); module.exports = function(selected, options, translate, changed, htmlId) { - let x = selected; - + function choose(event) { + if (event.target.value != selected) { + console.log('Selected new value from dropdown', htmlId, ':', selected, '->', event.target.value) + changed(event.target.value); + } + } + return html` `; - - function choose(event) { - const target = event.target; - const value = +target.value; - - if (x !== value) { - x = value; - changed(value); - } - } }; diff --git a/server/config.js b/server/config.js index d530610f..833ddf10 100644 --- a/server/config.js +++ b/server/config.js @@ -3,6 +3,23 @@ const { tmpdir } = require('os'); const path = require('path'); const { randomBytes } = require('crypto'); +convict.addFormat({ + name: 'positive-int-array', + coerce: (ints, schema) => { // can take: int[] | string[] | string (csv), returns -> int[] + const ints_arr = Array.isArray(ints) ? ints : ints.trim().split(',') + return ints_arr.map(int => + (typeof int === 'number') + ? int + : parseInt(int.trim(), 10)) + }, + validate: (ints, schema) => { // takes: int[], errors if any NaNs, negatives, or floats present + for (const int of ints) { + if (typeof(int) !== 'number' || isNaN(int) || int < 0 || int % 1 > 0) + throw new Error('must be a comma-separated list of positive integers') + } + }, +}); + const conf = convict({ s3_bucket: { format: String, @@ -25,7 +42,7 @@ const conf = convict({ env: 'GCS_BUCKET' }, expire_times_seconds: { - format: Array, + format: 'positive-int-array', default: [300, 3600, 86400, 604800], env: 'EXPIRE_TIMES_SECONDS' }, @@ -40,7 +57,7 @@ const conf = convict({ env: 'MAX_EXPIRE_SECONDS' }, download_counts: { - format: Array, + format: 'positive-int-array', default: [1, 2, 3, 4, 5, 20, 50, 100], env: 'DOWNLOAD_COUNTS' },