diff --git a/src/FederationServer/Methods/Operators/ListOperatorBlacklist.php b/src/FederationServer/Methods/Operators/ListOperatorBlacklist.php new file mode 100644 index 0000000..3a9328a --- /dev/null +++ b/src/FederationServer/Methods/Operators/ListOperatorBlacklist.php @@ -0,0 +1,68 @@ +isBlacklistPublic() && $authenticatedOperator === null) + { + throw new RequestException('Unauthorized: You must be authenticated to list blacklist records', 401); + } + + $limit = (int) (FederationServer::getParameter('limit') ?? Configuration::getServerConfiguration()->getListBlacklistMaxItems()); + $page = (int) (FederationServer::getParameter('page') ?? 1); + + if($limit < 1 || $limit > Configuration::getServerConfiguration()->getListBlacklistMaxItems()) + { + $limit = Configuration::getServerConfiguration()->getListBlacklistMaxItems(); + } + + if($page < 1) + { + $page = 1; + } + + if(!preg_match('#^/operators/([a-fA-F0-9\-]{36,})/blacklist$#', FederationServer::getPath(), $matches)) + { + throw new RequestException('Bad Request: Operator UUID is required', 400); + } + + $operatorUuid = $matches[1]; + if(!$operatorUuid || !Validate::uuid($operatorUuid)) + { + throw new RequestException('Bad Request: a valid operator UUID is required', 400); + } + + try + { + if(!OperatorManager::operatorExists($operatorUuid)) + { + throw new RequestException('Operator not found', 404); + } + + $blacklistRecords = BlacklistManager::getEntriesByOperator($operatorUuid, $limit, $page); + } + catch (DatabaseOperationException $e) + { + throw new RequestException('Internal Server Error: Unable to retrieve blacklist records from the operator', 500, $e); + } + + self::successResponse(array_map(fn($evidence) => $evidence->toArray(), $blacklistRecords)); + } + } +