mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-28 17:01:16 +00:00
Add dynamic api throthling
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
2018-06-04 DariusIII
|
||||
* Chg: Add dynamic api throthling
|
||||
* Fix: Fix headers that are being sent with getNzb function
|
||||
* Fix: Make queries properly formatted for API V2
|
||||
* Chg: Remove references to extended info in API V2, API always sends extended information
|
||||
|
||||
@@ -92,6 +92,7 @@ class UserController extends BasePageController
|
||||
'password' => '',
|
||||
'role' => User::ROLE_USER,
|
||||
'notes' => '',
|
||||
'rate_limit' => 60,
|
||||
];
|
||||
|
||||
$title = 'View User';
|
||||
|
||||
@@ -332,6 +332,8 @@ class User extends Authenticatable
|
||||
$userName = trim($userName);
|
||||
$email = trim($email);
|
||||
|
||||
$rateLimit = UserRole::query()->where('id', $role)->value('rate_limit');
|
||||
|
||||
if (! self::isValidUsername($userName)) {
|
||||
return self::ERR_SIGNUP_BADUNAME;
|
||||
}
|
||||
@@ -380,6 +382,7 @@ class User extends Authenticatable
|
||||
'nzbvortex_api_key' => $nzbvortexApiKey,
|
||||
'cp_url' => $cp_url,
|
||||
'cp_api' => $cp_api,
|
||||
'rate_limit' => $rateLimit,
|
||||
];
|
||||
|
||||
self::query()->where('id', $id)->update($sql);
|
||||
@@ -888,6 +891,8 @@ class User extends Authenticatable
|
||||
return false;
|
||||
}
|
||||
|
||||
$rateLimit = UserRole::query()->where('id', $role)->value('rate_limit');
|
||||
|
||||
if (\defined('NN_INSTALLER')) {
|
||||
$storeips = '';
|
||||
} else {
|
||||
@@ -906,6 +911,7 @@ class User extends Authenticatable
|
||||
'invitedby' => (int) $invitedBy === 0 ? 'NULL' : $invitedBy,
|
||||
'userseed' => md5(Utility::generateUuid()),
|
||||
'notes' => $notes,
|
||||
'rate_limit' => $rateLimit,
|
||||
]
|
||||
)->id;
|
||||
}
|
||||
|
||||
@@ -104,6 +104,7 @@ class UserRole extends Model
|
||||
'hideads' => $request['hideads'],
|
||||
'donation' => $request['donation'],
|
||||
'addyears' => $request['addyears'],
|
||||
'rate_limit' => $request['rate_limit'],
|
||||
]
|
||||
);
|
||||
}
|
||||
@@ -126,6 +127,7 @@ class UserRole extends Model
|
||||
'hideads' => $request['hideads'],
|
||||
'donation' => $request['donation'],
|
||||
'addyears' => $request['addyears'],
|
||||
'rate_limit' => $request['rate_limit'],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
+2
-2
@@ -16,8 +16,8 @@
|
||||
</last>
|
||||
</scripts>
|
||||
<sql>
|
||||
<db>347</db>
|
||||
<file>347</file>
|
||||
<db>348</db>
|
||||
<file>348</file>
|
||||
</sql>
|
||||
</versions>
|
||||
</nntmux>
|
||||
|
||||
@@ -39,6 +39,7 @@ class CreateUsersTable extends Migration {
|
||||
$table->integer('consoleview')->default(1);
|
||||
$table->integer('bookview')->default(1);
|
||||
$table->integer('gameview')->default(1);
|
||||
$table->integer('rate_limit')->default(60);
|
||||
$table->string('saburl')->nullable();
|
||||
$table->string('sabapikey')->nullable();
|
||||
$table->boolean('sabapikeytype')->nullable();
|
||||
|
||||
@@ -20,6 +20,7 @@ class CreateUserRolesTable extends Migration {
|
||||
$table->integer('id', true);
|
||||
$table->string('name', 32);
|
||||
$table->integer('apirequests')->unsigned();
|
||||
$table->integer('rate_limit')->default(60);
|
||||
$table->integer('downloadrequests')->unsigned();
|
||||
$table->integer('defaultinvites')->unsigned();
|
||||
$table->boolean('isdefault')->default(0);
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
# Add rate_limit column to users and user_roles tables, for api rate limiting purposes
|
||||
|
||||
ALTER TABLE users ADD rate_limit INT DEFAULT 60 COMMENT 'Rate limiting, requests per minute';
|
||||
|
||||
ALTER TABLE user_roles ADD rate_limit INT DEFAULT 60 COMMENT 'Rate limiting, requests per minute';
|
||||
@@ -0,0 +1,5 @@
|
||||
# Add rate_limit column to users and user_roles tables, for api rate limiting purposes
|
||||
|
||||
ALTER TABLE users ADD rate_limit INT DEFAULT 60 COMMENT 'Rate limiting, requests per minute';
|
||||
|
||||
ALTER TABLE user_roles ADD rate_limit INT DEFAULT 60 COMMENT 'Rate limiting, requests per minute';
|
||||
@@ -28,6 +28,14 @@
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Api rate limit:</td>
|
||||
<td>
|
||||
<input name="rate_limit" type="text" value="{$role.rate_limit}"/>
|
||||
<div class="hint">Number of api requests allowed per 1 minute</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Download Requests:</td>
|
||||
<td>
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ Route::prefix('v2')->group(function () {
|
||||
});
|
||||
});
|
||||
|
||||
Route::prefix('v2')->middleware('auth:api')->group(function () {
|
||||
Route::prefix('v2')->middleware('auth:api', 'throttle:rate_limit,1')->group(function () {
|
||||
Route::namespace('Api')->group(function () {
|
||||
Route::get('movies', 'ApiV2Controller@movie');
|
||||
Route::post('movies', 'ApiV2Controller@movie');
|
||||
|
||||
Reference in New Issue
Block a user