Skip to content

Commit

Permalink
feat: new args --disable-rate-limit (#737)
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 authored Apr 28, 2024
1 parent 1b31312 commit 5ff9cdd
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
7 changes: 7 additions & 0 deletions config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ const {argv: argvObj} = yargs(process.argv.slice(2))
describe: "Disable Flood's builtin access control system, deprecated, use auth=none instead",
type: 'boolean',
})
.option('disable-rate-limit', {
default: false,
describe: 'disable api request limit except for login',
hidden: true,
type: 'boolean',
})
.option('dehost', {
describe: 'Host of Deluge RPC interface',
type: 'string',
Expand Down Expand Up @@ -342,6 +348,7 @@ const result = configSchema.safeParse({
sslCert: argv.sslcert || path.resolve(path.join(argv.rundir, 'fullchain.pem')),
allowedPaths: allowedPaths.length > 0 ? allowedPaths : undefined,
serveAssets: argv.assets,
disableRateLimit: argv.disableRateLimit,
});

if (!result.success) {
Expand Down
2 changes: 1 addition & 1 deletion server/routes/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import express, {Response} from 'express';
import fs from 'fs';
import passport from 'passport';
import path from 'path';
import rateLimit from 'express-rate-limit';

import {contentTokenSchema} from '@shared/schema/api/torrents';

Expand All @@ -19,6 +18,7 @@ import eventStream from '../../middleware/eventStream';
import feedMonitorRoutes from './feed-monitor';
import {getAuthToken, verifyToken} from '../../util/authUtil';
import torrentsRoutes from './torrents';
import {rateLimit} from '../utils';

const router = express.Router();

Expand Down
2 changes: 1 addition & 1 deletion server/routes/api/torrents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import createTorrent from 'create-torrent';
import express, {Response} from 'express';
import fs from 'fs';
import path from 'path';
import rateLimit from 'express-rate-limit';
import sanitize from 'sanitize-filename';
import tar, {Pack} from 'tar-fs';

Expand Down Expand Up @@ -46,6 +45,7 @@ import {
import {getTempPath} from '../../models/TemporaryStorage';
import {getToken} from '../../util/authUtil';
import {asyncFilter} from '../../util/async';
import {rateLimit} from '../utils';

const getDestination = async (
services: Express.Request['services'],
Expand Down
14 changes: 14 additions & 0 deletions server/routes/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import config from '../../config';

import expressRateLimit, {Options} from 'express-rate-limit';
import {RequestHandler} from 'express';

export function rateLimit(passedOptions?: Partial<Options>): RequestHandler {
if (config.disableRateLimit) {
return function (req, res, next) {
next();
};
}

return expressRateLimit(passedOptions);
}
4 changes: 4 additions & 0 deletions shared/schema/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ export const configSchema = strictObject({
// Users may prefer to serve static assets via a "professional" web server such as nginx to
// increase performance or have more flexibility on compression or other options. [default: true]
serveAssets: boolean().optional(),

// CLI argument: --disable-rate-limit
// Disable api request limit except for login
disableRateLimit: boolean(),
})
.refine(
(config) => {
Expand Down

0 comments on commit 5ff9cdd

Please sign in to comment.