Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion root/app/www/public/api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -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]);

Expand Down
9 changes: 9 additions & 0 deletions root/app/www/public/functions/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 10 additions & 0 deletions root/etc/nginx/template.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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/;
Expand Down