made download count and expiry options server configurable
This commit is contained in:
parent
b61bf3c867
commit
e2259ae737
6 changed files with 22 additions and 28 deletions
|
@ -9,16 +9,6 @@ const conf = convict({
|
|||
default: '',
|
||||
env: 'S3_BUCKET'
|
||||
},
|
||||
num_of_prefixes: {
|
||||
format: Number,
|
||||
default: 5,
|
||||
env: 'NUM_OF_PREFIXES'
|
||||
},
|
||||
expire_prefixes: {
|
||||
format: Array,
|
||||
default: ['5minutes', '1hour', '1day', '1week', '2weeks'],
|
||||
env: 'EXPIRE_PREFIXES'
|
||||
},
|
||||
expire_times_seconds: {
|
||||
format: Array,
|
||||
default: [300, 3600, 86400, 604800],
|
||||
|
@ -39,6 +29,11 @@ const conf = convict({
|
|||
default: 86400,
|
||||
env: 'ANON_MAX_EXPIRE_SECONDS'
|
||||
},
|
||||
download_counts: {
|
||||
format: Array,
|
||||
default: [1, 2, 3, 4, 5, 20, 50, 100, 200],
|
||||
env: 'DOWNLOAD_COUNTS'
|
||||
},
|
||||
max_downloads: {
|
||||
format: Number,
|
||||
default: 200,
|
||||
|
|
|
@ -55,6 +55,8 @@ module.exports = async function(req, res) {
|
|||
MAX_ARCHIVES_PER_USER: ${config.max_archives_per_user}
|
||||
};
|
||||
var DEFAULTS = {
|
||||
DOWNLOAD_COUNTS: ${JSON.stringify(config.download_counts)},
|
||||
EXPIRE_TIMES_SECONDS: ${JSON.stringify(config.expire_times_seconds)},
|
||||
EXPIRE_SECONDS: ${config.default_expire_seconds}
|
||||
};
|
||||
${authConfig};
|
||||
|
|
|
@ -3,6 +3,10 @@ const Metadata = require('../metadata');
|
|||
const mozlog = require('../log');
|
||||
const createRedisClient = require('./redis');
|
||||
|
||||
function getPrefix(seconds) {
|
||||
return Math.max(Math.floor(seconds / 86400), 1);
|
||||
}
|
||||
|
||||
class DB {
|
||||
constructor(config) {
|
||||
const Storage = config.s3_bucket ? require('./s3') : require('./fs');
|
||||
|
@ -37,14 +41,7 @@ class DB {
|
|||
}
|
||||
|
||||
async set(id, file, meta, expireSeconds = config.default_expire_seconds) {
|
||||
const expireTimes = config.expire_times_seconds;
|
||||
let i;
|
||||
for (i = 0; i < expireTimes.length - 1; i++) {
|
||||
if (expireSeconds <= expireTimes[i]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
const prefix = config.expire_prefixes[i];
|
||||
const prefix = getPrefix(expireSeconds);
|
||||
const filePath = `${prefix}-${id}`;
|
||||
await this.storage.set(filePath, file);
|
||||
this.redis.hset(id, 'prefix', prefix);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue