Skip to content

Commit

Permalink
Rate limiting: limit query=askai to 5 requests every 30s (per user)
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardspec committed Dec 25, 2024
1 parent ebf7d32 commit 83e4cca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
"askai": true
}
},
"RateLimits": {
"askai": {
"user": [
5,
30
]
}
},
"AutoloadClasses": {
"MediaWiki\\AskAI\\ApiQueryAskAI": "includes/api/ApiQueryAskAI.php",
"MediaWiki\\AskAI\\Hooks": "includes/Hooks.php",
Expand Down
5 changes: 5 additions & 0 deletions includes/api/ApiQueryAskAI.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,17 @@
use ApiQueryBase;
use MediaWiki\AskAI\Service\ServiceFactory;
use Status;
use ThrottledError;
use Wikimedia\ParamValidator\ParamValidator;

class ApiQueryAskAI extends ApiQueryBase {
public function execute() {
$this->checkUserRightsAny( 'askai' );

if ( $this->getUser()->pingLimiter( 'askai' ) ) {
throw new ThrottledError;
}

$ai = ServiceFactory::getAI();
if ( !$ai ) {
$this->dieStatus( Status::newFatal( 'askai-unknown-service' ) );
Expand Down

0 comments on commit 83e4cca

Please sign in to comment.