Skip to content

Commit

Permalink
fix: rewrite and improve caching (#3594)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvikan authored Sep 10, 2023
1 parent a786bbd commit 4b9f6f7
Show file tree
Hide file tree
Showing 45 changed files with 985 additions and 1,161 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ Alternatively find another

Requires minimum PHP 7.4.

```shell
apt install nginx php-fpm php-mbstring php-simplexml php-curl
```

```shell
cd /var/www
composer create-project -v --no-dev rss-bridge/rss-bridge
Expand Down Expand Up @@ -334,10 +338,11 @@ This is the feed item structure that bridges are expected to produce.

### Cache backends

* `file`
* `sqlite`
* `memcached`
* `null`
* `File`
* `SQLite`
* `Memcached`
* `Array`
* `Null`

### Licenses

Expand Down
32 changes: 14 additions & 18 deletions actions/ConnectivityAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct()
public function execute(array $request)
{
if (!Debug::isEnabled()) {
throw new \Exception('This action is only available in debug mode!');
return new Response('This action is only available in debug mode!');
}

$bridgeName = $request['bridge'] ?? null;
Expand All @@ -43,7 +43,7 @@ public function execute(array $request)
}
$bridgeClassName = $this->bridgeFactory->createBridgeClassName($bridgeName);
if (!$bridgeClassName) {
throw new \Exception(sprintf('Bridge not found: %s', $bridgeName));
return new Response('Bridge not found', 404);
}
return $this->reportBridgeConnectivity($bridgeClassName);
}
Expand All @@ -54,29 +54,25 @@ private function reportBridgeConnectivity($bridgeClassName)
throw new \Exception('Bridge is not whitelisted!');
}

$retVal = [
'bridge' => $bridgeClassName,
'successful' => false,
'http_code' => 200,
];

$bridge = $this->bridgeFactory->create($bridgeClassName);
$curl_opts = [
CURLOPT_CONNECTTIMEOUT => 5
CURLOPT_CONNECTTIMEOUT => 5,
CURLOPT_FOLLOWLOCATION => true,
];
$result = [
'bridge' => $bridgeClassName,
'successful' => false,
'http_code' => null,
];
try {
$reply = getContents($bridge::URI, [], $curl_opts, true);

if ($reply['code'] === 200) {
$retVal['successful'] = true;
if (strpos(implode('', $reply['status_lines']), '301 Moved Permanently')) {
$retVal['http_code'] = 301;
}
$response = getContents($bridge::URI, [], $curl_opts, true);
$result['http_code'] = $response['code'];
if (in_array($response['code'], [200])) {
$result['successful'] = true;
}
} catch (\Exception $e) {
$retVal['successful'] = false;
}

return new Response(Json::encode($retVal), 200, ['Content-Type' => 'text/json']);
return new Response(Json::encode($result), 200, ['content-type' => 'text/json']);
}
}
2 changes: 1 addition & 1 deletion actions/DetectAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function execute(array $request)
$bridgeParams['format'] = $format;

$url = '?action=display&' . http_build_query($bridgeParams);
return new Response('', 301, ['Location' => $url]);
return new Response('', 301, ['location' => $url]);
}

throw new \Exception('No bridge found for given URL: ' . $targetURL);
Expand Down
Loading

0 comments on commit 4b9f6f7

Please sign in to comment.