Merge branch 'master' into pirate-patch-3

This commit is contained in:
timvisee 2021-05-19 11:30:50 +02:00
commit 1d6872e279
No known key found for this signature in database
GPG key ID: B8DB720BC383E172
3 changed files with 41 additions and 30 deletions

View file

@ -31,12 +31,11 @@ module.exports = function(state, emit) {
counts, counts,
num => state.translate('downloadCount', { num }), num => state.translate('downloadCount', { num }),
value => { value => {
const max = state.user.maxDownloads; const selected = parseInt(value);
state.archive.dlimit = Math.min(value, max); state.archive.dlimit = selected;
if (value > max) { emit('render');
emit('signup-cta', 'count'); if (selected > parseInt(state.user.maxDownloads || '0')) {
} else { console.log('Chosen max download count is larger than the allowed limit', selected)
emit('render');
} }
}, },
'expire-after-dl-count-select' 'expire-after-dl-count-select'
@ -58,12 +57,11 @@ module.exports = function(state, emit) {
return state.translate(l10n.id, l10n); return state.translate(l10n.id, l10n);
}, },
value => { value => {
const max = state.user.maxExpireSeconds; const selected = parseInt(value);
state.archive.timeLimit = Math.min(value, max); state.archive.timeLimit = selected;
if (value > max) { emit('render');
emit('signup-cta', 'time'); if (selected > parseInt(state.user.maxExpireSeconds || '0')) {
} else { console.log('Chosen download expiration is larger than the allowed limit', selected)
emit('render');
} }
}, },
'expire-after-time-select' 'expire-after-time-select'

View file

@ -1,32 +1,28 @@
const html = require('choo/html'); const html = require('choo/html');
module.exports = function(selected, options, translate, changed, htmlId) { 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` return html`
<select <select
id="${htmlId}" id="${htmlId}"
class="appearance-none cursor-pointer border rounded bg-grey-10 hover:border-blue-50 focus:border-blue-50 pl-1 pr-8 py-1 my-1 h-8 dark:bg-grey-80" class="appearance-none cursor-pointer border rounded bg-grey-10 hover:border-blue-50 focus:border-blue-50 pl-1 pr-8 py-1 my-1 h-8 dark:bg-grey-80"
data-selected="${selected}"
onchange="${choose}" onchange="${choose}"
> >
${options.map( ${options.map(
i => value =>
html` html`
<option value="${i}" ${i === selected ? 'selected' : ''} <option value="${value}" ${value == selected ? 'selected' : ''}>
>${translate(i)}</option ${translate(value)}
> </option>
` `
)} )}
</select> </select>
`; `;
function choose(event) {
const target = event.target;
const value = +target.value;
if (x !== value) {
x = value;
changed(value);
}
}
}; };

View file

@ -3,6 +3,23 @@ const { tmpdir } = require('os');
const path = require('path'); const path = require('path');
const { randomBytes } = require('crypto'); 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({ const conf = convict({
s3_bucket: { s3_bucket: {
format: String, format: String,
@ -25,7 +42,7 @@ const conf = convict({
env: 'GCS_BUCKET' env: 'GCS_BUCKET'
}, },
expire_times_seconds: { expire_times_seconds: {
format: Array, format: 'positive-int-array',
default: [300, 3600, 86400, 604800], default: [300, 3600, 86400, 604800],
env: 'EXPIRE_TIMES_SECONDS' env: 'EXPIRE_TIMES_SECONDS'
}, },
@ -40,7 +57,7 @@ const conf = convict({
env: 'MAX_EXPIRE_SECONDS' env: 'MAX_EXPIRE_SECONDS'
}, },
download_counts: { download_counts: {
format: Array, format: 'positive-int-array',
default: [1, 2, 3, 4, 5, 20, 50, 100], default: [1, 2, 3, 4, 5, 20, 50, 100],
env: 'DOWNLOAD_COUNTS' env: 'DOWNLOAD_COUNTS'
}, },