Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new args --disable-rate-limit #737

Merged
merged 2 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading