Add maxAge to expire obsolete one-time downloads
This commit is contained in:
@@ -10,7 +10,7 @@ const config = {
|
|||||||
"port": 3000,
|
"port": 3000,
|
||||||
"iface": '0.0.0.0',
|
"iface": '0.0.0.0',
|
||||||
// retention options in seconds:label
|
// retention options in seconds:label
|
||||||
retentions: {
|
"retentions": {
|
||||||
"one-time": "one time download",
|
"one-time": "one time download",
|
||||||
"3600": "1 Hour",
|
"3600": "1 Hour",
|
||||||
"21600": "6 Hours",
|
"21600": "6 Hours",
|
||||||
@@ -22,6 +22,8 @@ const config = {
|
|||||||
"4838400": "8 Weeks"
|
"4838400": "8 Weeks"
|
||||||
},
|
},
|
||||||
"defaultRetention": 604800,
|
"defaultRetention": 604800,
|
||||||
|
// expire every file after maxAge (eg never downloaded one-time files)
|
||||||
|
"maxAge": 3600*24*75, // 75 days
|
||||||
// maximum file-size for previews in byte
|
// maximum file-size for previews in byte
|
||||||
"maxPreviewSize": Math.pow(2,20) * 2, // 2MB
|
"maxPreviewSize": Math.pow(2,20) * 2, // 2MB
|
||||||
"mailTemplate": 'mailto:?subject=File Transfer&body=You can download the files here: %%URL%%',
|
"mailTemplate": 'mailto:?subject=File Transfer&body=You can download the files here: %%URL%%',
|
||||||
|
|||||||
11
lib/db.js
11
lib/db.js
@@ -2,6 +2,7 @@
|
|||||||
const fsp = require('fs-promise');
|
const fsp = require('fs-promise');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const debug = require('debug')('psitransfer:db');
|
const debug = require('debug')('psitransfer:db');
|
||||||
|
const config = require('../config');
|
||||||
|
|
||||||
module.exports = class DB {
|
module.exports = class DB {
|
||||||
|
|
||||||
@@ -18,10 +19,14 @@ module.exports = class DB {
|
|||||||
let sid,f,expires;
|
let sid,f,expires;
|
||||||
for (sid of Object.keys(this.db)) {
|
for (sid of Object.keys(this.db)) {
|
||||||
for (f of this.db[sid]) {
|
for (f of this.db[sid]) {
|
||||||
// no removal of one-time downloads
|
// expire on maxAge
|
||||||
if(!Number.isInteger(+f.metadata.retention)) return;
|
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) {
|
if(expires <= 0) {
|
||||||
debug(`Expired ${sid}++${f.key}`);
|
debug(`Expired ${sid}++${f.key}`);
|
||||||
this.remove(sid, f.key).catch(e => console.error(e));
|
this.remove(sid, f.key).catch(e => console.error(e));
|
||||||
|
|||||||
Reference in New Issue
Block a user