2022-11-20 12:41:38 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class SetBridgeCacheAction implements ActionInterface
|
|
|
|
{
|
2023-09-21 22:05:55 +02:00
|
|
|
private CacheInterface $cache;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->cache = RssBridge::getCache();
|
|
|
|
}
|
|
|
|
|
2022-11-20 12:41:38 +01:00
|
|
|
public function execute(array $request)
|
|
|
|
{
|
|
|
|
$authenticationMiddleware = new ApiAuthenticationMiddleware();
|
|
|
|
$authenticationMiddleware($request);
|
|
|
|
|
2023-09-10 21:50:15 +02:00
|
|
|
$key = $request['key'] ?? null;
|
|
|
|
if (!$key) {
|
|
|
|
returnClientError('You must specify key!');
|
|
|
|
}
|
2022-11-20 12:41:38 +01:00
|
|
|
|
2023-06-08 23:04:16 +02:00
|
|
|
$bridgeFactory = new BridgeFactory();
|
2022-11-20 12:41:38 +01:00
|
|
|
|
2023-08-01 19:35:15 +02:00
|
|
|
$bridgeName = $request['bridge'] ?? null;
|
|
|
|
$bridgeClassName = $bridgeFactory->createBridgeClassName($bridgeName);
|
|
|
|
if (!$bridgeClassName) {
|
|
|
|
throw new \Exception(sprintf('Bridge not found: %s', $bridgeName));
|
|
|
|
}
|
2022-11-20 12:41:38 +01:00
|
|
|
|
|
|
|
// whitelist control
|
2023-06-11 03:16:03 +02:00
|
|
|
if (!$bridgeFactory->isEnabled($bridgeClassName)) {
|
2022-11-20 12:41:38 +01:00
|
|
|
throw new \Exception('This bridge is not whitelisted', 401);
|
|
|
|
}
|
|
|
|
|
|
|
|
$bridge = $bridgeFactory->create($bridgeClassName);
|
|
|
|
$bridge->loadConfiguration();
|
|
|
|
$value = $request['value'];
|
|
|
|
|
2023-09-10 21:50:15 +02:00
|
|
|
$cacheKey = get_class($bridge) . '_' . $key;
|
|
|
|
$ttl = 86400 * 3;
|
2023-09-21 22:05:55 +02:00
|
|
|
$this->cache->set($cacheKey, $value, $ttl);
|
2022-11-20 12:41:38 +01:00
|
|
|
|
|
|
|
header('Content-Type: text/plain');
|
|
|
|
echo 'done';
|
|
|
|
}
|
|
|
|
}
|