mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-08-04 18:14:44 +02:00
feat: enable bridges using env var (#3428)
* refactor: bridgefactory, add tests * refactor: move defaultly enabled bridges to config * refactor * refactor * feat: add support for enabling bridges with env var
This commit is contained in:
parent
d9490c6518
commit
0a8fe57003
19 changed files with 179 additions and 182 deletions
|
@ -41,18 +41,14 @@ class ConnectivityAction implements ActionInterface
|
|||
return render_template('connectivity.html.php');
|
||||
}
|
||||
|
||||
$bridgeClassName = $this->bridgeFactory->sanitizeBridgeName($request['bridge']);
|
||||
|
||||
if ($bridgeClassName === null) {
|
||||
throw new \InvalidArgumentException('Bridge name invalid!');
|
||||
}
|
||||
$bridgeClassName = $this->bridgeFactory->createBridgeClassName($request['bridge']);
|
||||
|
||||
return $this->reportBridgeConnectivity($bridgeClassName);
|
||||
}
|
||||
|
||||
private function reportBridgeConnectivity($bridgeClassName)
|
||||
{
|
||||
if (!$this->bridgeFactory->isWhitelisted($bridgeClassName)) {
|
||||
if (!$this->bridgeFactory->isEnabled($bridgeClassName)) {
|
||||
throw new \Exception('Bridge is not whitelisted!');
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ class DetectAction implements ActionInterface
|
|||
$bridgeFactory = new BridgeFactory();
|
||||
|
||||
foreach ($bridgeFactory->getBridgeClassNames() as $bridgeClassName) {
|
||||
if (!$bridgeFactory->isWhitelisted($bridgeClassName)) {
|
||||
if (!$bridgeFactory->isEnabled($bridgeClassName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,20 +18,13 @@ class DisplayAction implements ActionInterface
|
|||
{
|
||||
$bridgeFactory = new BridgeFactory();
|
||||
|
||||
$bridgeClassName = null;
|
||||
if (isset($request['bridge'])) {
|
||||
$bridgeClassName = $bridgeFactory->sanitizeBridgeName($request['bridge']);
|
||||
}
|
||||
|
||||
if ($bridgeClassName === null) {
|
||||
throw new \InvalidArgumentException('Bridge name invalid!');
|
||||
}
|
||||
$bridgeClassName = $bridgeFactory->createBridgeClassName($request['bridge'] ?? '');
|
||||
|
||||
$format = $request['format'] ?? null;
|
||||
if (!$format) {
|
||||
throw new \Exception('You must specify a format!');
|
||||
}
|
||||
if (!$bridgeFactory->isWhitelisted($bridgeClassName)) {
|
||||
if (!$bridgeFactory->isEnabled($bridgeClassName)) {
|
||||
throw new \Exception('This bridge is not whitelisted');
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ final class FrontpageAction implements ActionInterface
|
|||
|
||||
$body = '';
|
||||
foreach ($bridgeClassNames as $bridgeClassName) {
|
||||
if ($bridgeFactory->isWhitelisted($bridgeClassName)) {
|
||||
if ($bridgeFactory->isEnabled($bridgeClassName)) {
|
||||
$body .= BridgeCard::displayBridgeCard($bridgeClassName, $formats);
|
||||
$activeBridges++;
|
||||
} elseif ($showInactive) {
|
||||
|
|
|
@ -26,7 +26,7 @@ class ListAction implements ActionInterface
|
|||
$bridge = $bridgeFactory->create($bridgeClassName);
|
||||
|
||||
$list->bridges[$bridgeClassName] = [
|
||||
'status' => $bridgeFactory->isWhitelisted($bridgeClassName) ? 'active' : 'inactive',
|
||||
'status' => $bridgeFactory->isEnabled($bridgeClassName) ? 'active' : 'inactive',
|
||||
'uri' => $bridge->getURI(),
|
||||
'donationUri' => $bridge->getDonationURI(),
|
||||
'name' => $bridge->getName(),
|
||||
|
|
|
@ -23,17 +23,10 @@ class SetBridgeCacheAction implements ActionInterface
|
|||
|
||||
$bridgeFactory = new BridgeFactory();
|
||||
|
||||
$bridgeClassName = null;
|
||||
if (isset($request['bridge'])) {
|
||||
$bridgeClassName = $bridgeFactory->sanitizeBridgeName($request['bridge']);
|
||||
}
|
||||
|
||||
if ($bridgeClassName === null) {
|
||||
throw new \InvalidArgumentException('Bridge name invalid!');
|
||||
}
|
||||
$bridgeClassName = $bridgeFactory->createBridgeClassName($request['bridge'] ?? '');
|
||||
|
||||
// whitelist control
|
||||
if (!$bridgeFactory->isWhitelisted($bridgeClassName)) {
|
||||
if (!$bridgeFactory->isEnabled($bridgeClassName)) {
|
||||
throw new \Exception('This bridge is not whitelisted', 401);
|
||||
die;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue