ip() ?? ''), userAgent: $request->userAgent() ?? '', apiToken: self::extractApiToken($request), referer: $request->headers->get('referer'), isDownload: $isDownload, isSearch: $isSearch, ); } /** * Resolve the user token used to correlate searches with downloads. * * Newznab (`apikey`), the RSS feeds (`api_token`) and the getnzb RSS token * (`r`) all identify the same underlying user, so any of them is a valid * correlation key. */ private static function extractApiToken(Request $request): ?string { foreach (['api_token', 'apikey', 'apiToken', 'r'] as $key) { $value = $request->input($key); if (is_string($value) && $value !== '') { return $value; } } return null; } }