@RequestMapping(value = {"/api", "/rss", "/torznab/api"}, consumes = MediaType.ALL_VALUE)
public ResponseEntity<? extends Object> api(NewznabParameters params) throws Exception {
logger.info("Received external {}API call: {}", (isTorznabCall() ? "torznab " : ""), params);
if (!noApiKeyNeeded && !Objects.equals(params.getApikey(), configProvider.getBaseConfig().getMain().getApiKey())) {
logger.error("Received API call with wrong API key");
throw new WrongApiKeyException("Wrong api key");
}
if (Stream.of(ActionAttribute.SEARCH, ActionAttribute.BOOK, ActionAttribute.TVSEARCH, ActionAttribute.MOVIE).anyMatch(x -> x == params.getT())) {
if (params.getCachetime() != null) {
return handleCachingSearch(params);
}
NewznabResponse searchResult = search(params);
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.set(HttpHeaders.CONTENT_TYPE, searchResult.getContentHeader());
if (params.getO() != OutputType.JSON) {
searchResult.setSearchType(isTorznabCall() ? "torznab" : "newznab");
}
return new ResponseEntity<>(searchResult, httpHeaders, HttpStatus.OK);
}
if (params.getT() == ActionAttribute.GET) {
return getNzb(params);
}
if (params.getT() == ActionAttribute.CAPS) {
return capsGenerator.getCaps(params.getO());
}
logger.error("Incorrect API request: {}", params);
NewznabXmlError error = new NewznabXmlError("200", "Unknown or incorrect parameter");
return new ResponseEntity<Object>(error, HttpStatus.OK);
}