diff --git a/root/app/www/public/api/index.php b/root/app/www/public/api/index.php index f1c08c4..6bac97b 100644 --- a/root/app/www/public/api/index.php +++ b/root/app/www/public/api/index.php @@ -255,6 +255,11 @@ $usageDb->adjustAppUsage($proxiedApp['proxiedAppDetails']['id'], $request['code']); + if (is_string($request['response']) && preg_match('#^/\d+/api$#', $originalEndpoint)) { //-- NEWZNAB/TORZNAB FEED, KEEP DOWNLOADS ON THE PROXY + $request['response'] = rewriteIndexerLinks($request['response'], $proxiedApp['starrAppDetails']['url'], $proxiedApp['starrAppDetails']['apikey'], $apikey); + $request['responseHeaders'] = array_filter($request['responseHeaders'], fn($rhKey) => strtolower($rhKey) != 'content-length', ARRAY_FILTER_USE_KEY); + } + if ($request['code'] <= 299 && str_contains($endpoint, 'mediacover')) { //-- OUTPUT THE REQUESTED IMAGE foreach ($request['responseHeaders'] as $rhKey => $rhVal) { header($rhKey . ': ' . $rhVal[0]); @@ -268,7 +273,7 @@ } //-- CHECK FOR FIELD REDACTIONS - if ($redactions = $proxiedApp['proxiedAppDetails']['redactions']) { + if (is_array($request['response']) && $redactions = $proxiedApp['proxiedAppDetails']['redactions']) { //-- XML (newznab/torznab) responses have no fields to redact logger($logfile, ['req' => $requestCounter, 'endpoint' => $originalEndpoint, 'redactions' => $redactions]); logger($proxiedAppLogfile, ['req' => $requestCounter, 'endpoint' => $originalEndpoint, 'redactions' => $redactions]); diff --git a/root/app/www/public/functions/api.php b/root/app/www/public/functions/api.php index ccd8b40..07e1f05 100644 --- a/root/app/www/public/functions/api.php +++ b/root/app/www/public/functions/api.php @@ -37,6 +37,15 @@ function forwardedQueryString($queryString, $strip = ['endpoint', 'apikey']) return implode('&', $kept); } +function rewriteIndexerLinks($response, $starrUrl, $starrApikey, $proxyApikey) +{ + //-- PROWLARR WRITES ITS OWN URL AND APIKEY INTO NEWZNAB/TORZNAB DOWNLOAD LINKS, POINT THEM AT THE PROXY AND THE CALLERS APIKEY + $requestPath = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); + $proxyUrl = APP_URL . preg_replace('#/\d+/api$#i', '', $requestPath); + + return str_replace([rtrim($starrUrl, '/'), $starrApikey], [rtrim($proxyUrl, '/'), $proxyApikey], $response); +} + function apiResponse($code, $response, $responseHeaders = []) { session_unset(); diff --git a/root/etc/nginx/template.conf b/root/etc/nginx/template.conf index f8f272b..cf0b62d 100644 --- a/root/etc/nginx/template.conf +++ b/root/etc/nginx/template.conf @@ -124,6 +124,16 @@ http { fastcgi_index index.php; } + # Newznab/Torznab indexer routing (Prowlarr /{id}/api and /{id}/download) + location ~ ^(.*)(/\d+/(?:api|download))$ { + alias $root/; + fastcgi_pass 127.0.0.1:9000; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $root/api/index.php; + fastcgi_param QUERY_STRING endpoint=$2&$args; + fastcgi_index index.php; + } + # API routing location ~ ^(.*)/api/(.*)$ { alias $root/;