Add DEFAULT_DOWNLOADS variable to set default download count

Fixes https://github.com/timvisee/send/issues/39
This commit is contained in:
timvisee 2021-06-04 14:03:58 +02:00
parent 3bd9f00c25
commit 1a923d21b5
No known key found for this signature in database
GPG Key ID: B8DB720BC383E172
7 changed files with 19 additions and 7 deletions

View File

@ -77,7 +77,11 @@ function body(main) {
state.capabilities = {
account: true
}; //TODO
state.archive = new Archive([], DEFAULTS.EXPIRE_SECONDS);
state.archive = new Archive(
[],
DEFAULTS.EXPIRE_SECONDS,
DEFAULTS.DOWNLOADS
);
state.storage = storage;
state.user = new User(storage, LIMITS);
state.sentry = Sentry;

View File

@ -14,11 +14,11 @@ function isDupe(newFile, array) {
}
export default class Archive {
constructor(files = [], defaultTimeLimit = 86400) {
constructor(files = [], defaultTimeLimit = 86400, defaultDownloadLimit = 1) {
this.files = Array.from(files);
this.defaultTimeLimit = defaultTimeLimit;
this.timeLimit = defaultTimeLimit;
this.dlimit = 1;
this.dlimit = defaultDownloadLimit;
this.password = null;
}

View File

@ -52,7 +52,7 @@ if (process.env.NODE_ENV === 'production') {
DEFAULTS,
WEB_UI,
PREFS,
archive: new Archive([], DEFAULTS.EXPIRE_SECONDS),
archive: new Archive([], DEFAULTS.EXPIRE_SECONDS, DEFAULTS.DOWNLOADS),
capabilities,
translate,
storage,

View File

@ -29,7 +29,7 @@ Config options expecting array values (e.g. `EXPIRE_TIMES_SECONDS`, `DOWNLOAD_CO
| Name | Description |
|------------------|-------------|
| `BASE_URL` | The HTTPS URL where traffic will be served (e.g. `https://send.firefox.com`)
| `DETECT_BASE_URL` | Autodetect the base URL using browser if `BASE_URL` is unset (defaults to `false`)
| `DETECT_BASE_URL` | Autodetect the base URL using browser if `BASE_URL` is unset (defaults to `false`)
| `PORT` | Port the server will listen on (defaults to `1443`)
| `NODE_ENV` | Run in `development` mode (unsafe) or `production` mode (the default)
| `SEND_FOOTER_DMCA_URL` | A URL to a contact page for DMCA requests (empty / not shown by default)
@ -49,6 +49,8 @@ Configure the limits for uploads and downloads. Long expiration times are risky
| `MAX_DOWNLOADS` | Maximum number of downloads (defaults to `100`)
| `DOWNLOAD_COUNTS` | Download limit options to show in UI dropdown, e.g. `10,1,2,5,10,15,25,50,100,1000`
| `EXPIRE_TIMES_SECONDS` | Expire time options to show in UI dropdown, e.g. `3600,86400,604800,2592000,31536000`
| `DEFAULT_DOWNLOADS` | Default download limit in UI (defaults to `1`)
| `DEFAULT_EXPIRE_SECONDS` | Default expire time in UI (defaults to `86400`)
*Note: more options can be found here: https://github.com/timvisee/send/blob/master/server/config.js*
@ -89,7 +91,7 @@ $ docker run -p 1443:1443 \
registry.gitlab.com/timvisee/send:latest
```
*Note: make sure to replace the example values above with your real values before running.*
*Note: make sure to replace the example values above with your real values before running.*
**Run totally self-hosted using the current filesystem directry (`$PWD`) to store the Redis data and file uploads, with a `5GB` upload limit, 1 month expiry, and contact URL set.**

View File

@ -15,6 +15,7 @@ module.exports = {
FOOTER_SOURCE_URL: config.footer_source_url
},
DEFAULTS: {
DOWNLOADS: config.default_downloads,
DOWNLOAD_COUNTS: config.download_counts,
EXPIRE_TIMES_SECONDS: config.expire_times_seconds,
EXPIRE_SECONDS: config.default_expire_seconds

View File

@ -64,6 +64,11 @@ const conf = convict({
default: [1, 2, 3, 4, 5, 20, 50, 100],
env: 'DOWNLOAD_COUNTS'
},
default_downloads: {
format: Number,
default: 1,
env: 'DEFAULT_DOWNLOADS'
},
max_downloads: {
format: Number,
default: 100,

View File

@ -26,7 +26,7 @@ module.exports = function(ws, req) {
const fileInfo = JSON.parse(message);
const timeLimit = fileInfo.timeLimit || config.default_expire_seconds;
const dlimit = fileInfo.dlimit || 1;
const dlimit = fileInfo.dlimit || config.default_downloads;
const metadata = fileInfo.fileMetadata;
const auth = fileInfo.authorization;
const user = await fxa.verify(fileInfo.bearer);