mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2024-11-21 17:15:25 +03:00
refactor: frontpage and proxy setting (#4214)
This commit is contained in:
parent
e9d3a657ba
commit
c0e37bcf35
5 changed files with 26 additions and 17 deletions
|
@ -51,6 +51,7 @@ class DisplayAction implements ActionInterface
|
|||
return new Response(render(__DIR__ . '/../templates/error.html.php', ['message' => 'This bridge is not whitelisted']), 400);
|
||||
}
|
||||
|
||||
// Disable proxy (if enabled and per user's request)
|
||||
if (
|
||||
Configuration::getConfig('proxy', 'url')
|
||||
&& Configuration::getConfig('proxy', 'by_bridge')
|
||||
|
|
|
@ -4,6 +4,8 @@ final class FrontpageAction implements ActionInterface
|
|||
{
|
||||
public function __invoke(Request $request): Response
|
||||
{
|
||||
$token = $request->attribute('token');
|
||||
|
||||
$messages = [];
|
||||
$activeBridges = 0;
|
||||
|
||||
|
@ -20,19 +22,21 @@ final class FrontpageAction implements ActionInterface
|
|||
$body = '';
|
||||
foreach ($bridgeClassNames as $bridgeClassName) {
|
||||
if ($bridgeFactory->isEnabled($bridgeClassName)) {
|
||||
$body .= BridgeCard::render($bridgeClassName, $request);
|
||||
$body .= BridgeCard::render($bridgeClassName, $token);
|
||||
$activeBridges++;
|
||||
}
|
||||
}
|
||||
|
||||
// todo: cache this renderered template?
|
||||
return new Response(render(__DIR__ . '/../templates/frontpage.html.php', [
|
||||
'messages' => $messages,
|
||||
'admin_email' => Configuration::getConfig('admin', 'email'),
|
||||
'admin_telegram' => Configuration::getConfig('admin', 'telegram'),
|
||||
'bridges' => $body,
|
||||
'active_bridges' => $activeBridges,
|
||||
'total_bridges' => count($bridgeClassNames),
|
||||
$response = new Response(render(__DIR__ . '/../templates/frontpage.html.php', [
|
||||
'messages' => $messages,
|
||||
'admin_email' => Configuration::getConfig('admin', 'email'),
|
||||
'admin_telegram' => Configuration::getConfig('admin', 'telegram'),
|
||||
'bridges' => $body,
|
||||
'active_bridges' => $activeBridges,
|
||||
'total_bridges' => count($bridgeClassNames),
|
||||
]));
|
||||
|
||||
// TODO: The rendered template could be cached, but beware config changes that changes the html
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,8 +86,8 @@ telegram = ""
|
|||
donations = true
|
||||
|
||||
[proxy]
|
||||
|
||||
; Sets the proxy url (i.e. "tcp://192.168.0.0:32")
|
||||
; The HTTP proxy to tunnel requests through
|
||||
; https://curl.se/libcurl/c/CURLOPT_PROXY.html
|
||||
; "" = Proxy disabled (default)
|
||||
url = ""
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
final class BridgeCard
|
||||
{
|
||||
public static function render(string $bridgeClassName, Request $request): string
|
||||
public static function render(string $bridgeClassName, ?string $token): string
|
||||
{
|
||||
$bridgeFactory = new BridgeFactory();
|
||||
|
||||
|
@ -14,10 +14,15 @@ final class BridgeCard
|
|||
$description = $bridge->getDescription();
|
||||
$contexts = $bridge->getParameters();
|
||||
|
||||
if (Configuration::getConfig('proxy', 'url') && Configuration::getConfig('proxy', 'by_bridge')) {
|
||||
// Checkbox for disabling of proxy (if enabled)
|
||||
if (
|
||||
Configuration::getConfig('proxy', 'url')
|
||||
&& Configuration::getConfig('proxy', 'by_bridge')
|
||||
) {
|
||||
$proxyName = Configuration::getConfig('proxy', 'name') ?: Configuration::getConfig('proxy', 'url');
|
||||
$contexts['global']['_noproxy'] = [
|
||||
'name' => 'Disable proxy (' . (Configuration::getConfig('proxy', 'name') ?: Configuration::getConfig('proxy', 'url')) . ')',
|
||||
'type' => 'checkbox'
|
||||
'name' => sprintf('Disable proxy (%s)', $proxyName),
|
||||
'type' => 'checkbox',
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -47,8 +52,6 @@ final class BridgeCard
|
|||
|
||||
CARD;
|
||||
|
||||
$token = $request->attribute('token');
|
||||
|
||||
if (count($contexts) === 0) {
|
||||
// The bridge has zero parameters
|
||||
$card .= self::renderForm($bridgeClassName, '', [], $token);
|
||||
|
|
|
@ -113,6 +113,7 @@ final class CurlHttpClient implements HttpClient
|
|||
if ($config['proxy']) {
|
||||
curl_setopt($ch, CURLOPT_PROXY, $config['proxy']);
|
||||
}
|
||||
|
||||
if (curl_setopt_array($ch, $config['curl_options']) === false) {
|
||||
throw new \Exception('Tried to set an illegal curl option');
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue