1
0
mirror of https://gitlab.com/timvisee/send.git synced 2024-11-12 14:12:30 +01:00

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,
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'

View File

@ -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`
<select
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"
data-selected="${selected}"
onchange="${choose}"
>
${options.map(
i =>
value =>
html`
<option value="${i}" ${i === selected ? 'selected' : ''}
>${translate(i)}</option
>
<option value="${value}" ${value == selected ? 'selected' : ''}>
${translate(value)}
</option>
`
)}
</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 { 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'
},