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