From 1a923d21b5e565dbbcc7eec9b47522d7bfcae2f0 Mon Sep 17 00:00:00 2001 From: timvisee Date: Fri, 4 Jun 2021 14:03:58 +0200 Subject: [PATCH] Add DEFAULT_DOWNLOADS variable to set default download count Fixes https://github.com/timvisee/send/issues/39 --- android/android.js | 6 +++++- app/archive.js | 4 ++-- app/main.js | 2 +- docs/docker.md | 6 ++++-- server/clientConstants.js | 1 + server/config.js | 5 +++++ server/routes/ws.js | 2 +- 7 files changed, 19 insertions(+), 7 deletions(-) diff --git a/android/android.js b/android/android.js index 0cbdefe5..8e194c9e 100644 --- a/android/android.js +++ b/android/android.js @@ -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; diff --git a/app/archive.js b/app/archive.js index 45517754..340164e8 100644 --- a/app/archive.js +++ b/app/archive.js @@ -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; } diff --git a/app/main.js b/app/main.js index 469dfccb..c6a89dce 100644 --- a/app/main.js +++ b/app/main.js @@ -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, diff --git a/docs/docker.md b/docs/docker.md index ebc02d82..b24d6e09 100644 --- a/docs/docker.md +++ b/docs/docker.md @@ -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.** diff --git a/server/clientConstants.js b/server/clientConstants.js index 74bf48a5..063f4d58 100644 --- a/server/clientConstants.js +++ b/server/clientConstants.js @@ -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 diff --git a/server/config.js b/server/config.js index f95c0619..9d16d46b 100644 --- a/server/config.js +++ b/server/config.js @@ -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, diff --git a/server/routes/ws.js b/server/routes/ws.js index 30be0248..17e257fd 100644 --- a/server/routes/ws.js +++ b/server/routes/ws.js @@ -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);