mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-07-13 15:34: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
|
@ -98,21 +98,6 @@ final class Configuration
|
|||
self::setConfig($header, $key, $value);
|
||||
}
|
||||
}
|
||||
foreach ($env as $envName => $envValue) {
|
||||
$nameParts = explode('_', $envName);
|
||||
if ($nameParts[0] === 'RSSBRIDGE') {
|
||||
if (count($nameParts) < 3) {
|
||||
// Invalid env name
|
||||
continue;
|
||||
}
|
||||
$header = $nameParts[1];
|
||||
$key = $nameParts[2];
|
||||
if ($envValue === 'true' || $envValue === 'false') {
|
||||
$envValue = filter_var($envValue, FILTER_VALIDATE_BOOLEAN);
|
||||
}
|
||||
self::setConfig($header, $key, $envValue);
|
||||
}
|
||||
}
|
||||
|
||||
if (file_exists(__DIR__ . '/../DEBUG')) {
|
||||
// The debug mode has been moved to config. Preserve existing installs which has this DEBUG file.
|
||||
|
@ -123,6 +108,47 @@ final class Configuration
|
|||
}
|
||||
}
|
||||
|
||||
if (file_exists(__DIR__ . '/../whitelist.txt')) {
|
||||
$whitelist = trim(file_get_contents(__DIR__ . '/../whitelist.txt'));
|
||||
if ($whitelist === '*') {
|
||||
self::setConfig('system', 'enabled_bridges', ['*']);
|
||||
} else {
|
||||
self::setConfig('system', 'enabled_bridges', explode("\n", $whitelist));
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($env as $envName => $envValue) {
|
||||
$nameParts = explode('_', $envName);
|
||||
if ($nameParts[0] === 'RSSBRIDGE') {
|
||||
if (count($nameParts) < 3) {
|
||||
// Invalid env name
|
||||
continue;
|
||||
}
|
||||
|
||||
// The variable is named $header but it's actually the section in config.ini.php
|
||||
$header = $nameParts[1];
|
||||
|
||||
// Recombine the key if it had multiple underscores
|
||||
$key = implode('_', array_slice($nameParts, 2));
|
||||
|
||||
// Handle this specifically because it's an array
|
||||
if ($key === 'enabled_bridges') {
|
||||
$envValue = explode(',', $envValue);
|
||||
$envValue = array_map('trim', $envValue);
|
||||
}
|
||||
|
||||
if ($envValue === 'true' || $envValue === 'false') {
|
||||
$envValue = filter_var($envValue, FILTER_VALIDATE_BOOLEAN);
|
||||
}
|
||||
|
||||
self::setConfig($header, $key, $envValue);
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_array(self::getConfig('system', 'enabled_bridges'))) {
|
||||
self::throwConfigError('system', 'enabled_bridges', 'Is not an array');
|
||||
}
|
||||
|
||||
if (
|
||||
!is_string(self::getConfig('system', 'timezone'))
|
||||
|| !in_array(self::getConfig('system', 'timezone'), timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue