mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2024-11-26 11:26:31 +03:00
41df17bc46
* test: refactor test suite * docs * refactor * yup * docs
46 lines
1.3 KiB
PHP
46 lines
1.3 KiB
PHP
<?php
|
|
|
|
class SetBridgeCacheAction implements ActionInterface
|
|
{
|
|
private CacheInterface $cache;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->cache = RssBridge::getCache();
|
|
}
|
|
|
|
public function execute(array $request)
|
|
{
|
|
$authenticationMiddleware = new ApiAuthenticationMiddleware();
|
|
$authenticationMiddleware($request);
|
|
|
|
$key = $request['key'] ?? null;
|
|
if (!$key) {
|
|
returnClientError('You must specify key!');
|
|
}
|
|
|
|
$bridgeFactory = new BridgeFactory();
|
|
|
|
$bridgeName = $request['bridge'] ?? null;
|
|
$bridgeClassName = $bridgeFactory->createBridgeClassName($bridgeName);
|
|
if (!$bridgeClassName) {
|
|
throw new \Exception(sprintf('Bridge not found: %s', $bridgeName));
|
|
}
|
|
|
|
// whitelist control
|
|
if (!$bridgeFactory->isEnabled($bridgeClassName)) {
|
|
throw new \Exception('This bridge is not whitelisted', 401);
|
|
}
|
|
|
|
$bridge = $bridgeFactory->create($bridgeClassName);
|
|
$bridge->loadConfiguration();
|
|
$value = $request['value'];
|
|
|
|
$cacheKey = get_class($bridge) . '_' . $key;
|
|
$ttl = 86400 * 3;
|
|
$this->cache->set($cacheKey, $value, $ttl);
|
|
|
|
header('Content-Type: text/plain');
|
|
echo 'done';
|
|
}
|
|
}
|