Merge branch 'default-download-count' into 'master'

Add DEFAULT_DOWNLOADS variable to set default download count

See merge request timvisee/send!18
This commit is contained in:
Tim Visée 2021-06-04 12:06:05 +00:00
commit 42f5ca9701
7 changed files with 19 additions and 7 deletions

View File

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

View File

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

View File

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

View File

@ -29,7 +29,7 @@ Config options expecting array values (e.g. `EXPIRE_TIMES_SECONDS`, `DOWNLOAD_CO
| Name | Description | | Name | Description |
|------------------|-------------| |------------------|-------------|
| `BASE_URL` | The HTTPS URL where traffic will be served (e.g. `https://send.firefox.com`) | `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`) | `PORT` | Port the server will listen on (defaults to `1443`)
| `NODE_ENV` | Run in `development` mode (unsafe) or `production` mode (the default) | `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) | `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`) | `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` | `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` | `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* *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 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.** **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 FOOTER_SOURCE_URL: config.footer_source_url
}, },
DEFAULTS: { DEFAULTS: {
DOWNLOADS: config.default_downloads,
DOWNLOAD_COUNTS: config.download_counts, DOWNLOAD_COUNTS: config.download_counts,
EXPIRE_TIMES_SECONDS: config.expire_times_seconds, EXPIRE_TIMES_SECONDS: config.expire_times_seconds,
EXPIRE_SECONDS: config.default_expire_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], default: [1, 2, 3, 4, 5, 20, 50, 100],
env: 'DOWNLOAD_COUNTS' env: 'DOWNLOAD_COUNTS'
}, },
default_downloads: {
format: Number,
default: 1,
env: 'DEFAULT_DOWNLOADS'
},
max_downloads: { max_downloads: {
format: Number, format: Number,
default: 100, default: 100,

View File

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