Add maxAge to expire obsolete one-time downloads
This commit is contained in:
11
lib/db.js
11
lib/db.js
@@ -2,6 +2,7 @@
|
||||
const fsp = require('fs-promise');
|
||||
const path = require('path');
|
||||
const debug = require('debug')('psitransfer:db');
|
||||
const config = require('../config');
|
||||
|
||||
module.exports = class DB {
|
||||
|
||||
@@ -18,10 +19,14 @@ module.exports = class DB {
|
||||
let sid,f,expires;
|
||||
for (sid of Object.keys(this.db)) {
|
||||
for (f of this.db[sid]) {
|
||||
// no removal of one-time downloads
|
||||
if(!Number.isInteger(+f.metadata.retention)) return;
|
||||
// expire on maxAge
|
||||
expires = (+f.metadata.createdAt) + (config.maxAge * 1000) - Date.now();
|
||||
|
||||
// respect one-time downloads
|
||||
if(expires > 0 && Number.isInteger(+f.metadata.retention)) {
|
||||
expires = (+f.metadata.createdAt) + (+f.metadata.retention * 1000) - Date.now();
|
||||
}
|
||||
|
||||
expires = (+f.metadata.createdAt) + (+f.metadata.retention * 1000) - Date.now();
|
||||
if(expires <= 0) {
|
||||
debug(`Expired ${sid}++${f.key}`);
|
||||
this.remove(sid, f.key).catch(e => console.error(e));
|
||||
|
||||
Reference in New Issue
Block a user