diff options
author | Joas Schilling <coding@schilljs.com> | 2023-10-12 12:25:16 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2023-10-13 08:34:42 +0200 |
commit | b246d51cbc5105b9c4e85867297ee19f6d2459e5 (patch) | |
tree | b0551f9a6b21c5fe776a3c1cd3dee1d3be54757f /lib/private/OCM | |
parent | 4dbe0677ad25d9ccbc4efcdc67c0e5b3d736d70f (diff) | |
download | nextcloud-server-b246d51cbc5105b9c4e85867297ee19f6d2459e5.tar.gz nextcloud-server-b246d51cbc5105b9c4e85867297ee19f6d2459e5.zip |
fix(OCM): Make the OCM provider stateful so apps can add resources
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private/OCM')
-rw-r--r-- | lib/private/OCM/OCMDiscoveryService.php | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/lib/private/OCM/OCMDiscoveryService.php b/lib/private/OCM/OCMDiscoveryService.php index e3b1d350813..ac9bf2a3965 100644 --- a/lib/private/OCM/OCMDiscoveryService.php +++ b/lib/private/OCM/OCMDiscoveryService.php @@ -27,7 +27,6 @@ declare(strict_types=1); namespace OC\OCM; use JsonException; -use OC\OCM\Model\OCMProvider; use OCP\AppFramework\Http; use OCP\Http\Client\IClientService; use OCP\ICache; @@ -54,7 +53,8 @@ class OCMDiscoveryService implements IOCMDiscoveryService { ICacheFactory $cacheFactory, private IClientService $clientService, private IConfig $config, - private LoggerInterface $logger + private IOCMProvider $provider, + private LoggerInterface $logger, ) { $this->cache = $cacheFactory->createDistributed('ocm-discovery'); } @@ -69,13 +69,12 @@ class OCMDiscoveryService implements IOCMDiscoveryService { */ public function discover(string $remote, bool $skipCache = false): IOCMProvider { $remote = rtrim($remote, '/'); - $provider = new OCMProvider(); if (!$skipCache) { try { - $provider->import(json_decode($this->cache->get($remote) ?? '', true, 8, JSON_THROW_ON_ERROR) ?? []); - if ($this->supportedAPIVersion($provider->getApiVersion())) { - return $provider; // if cache looks valid, we use it + $this->provider->import(json_decode($this->cache->get($remote) ?? '', true, 8, JSON_THROW_ON_ERROR) ?? []); + if ($this->supportedAPIVersion($this->provider->getApiVersion())) { + return $this->provider; // if cache looks valid, we use it } } catch (JsonException|OCMProviderException $e) { // we ignore cache on issues @@ -96,7 +95,7 @@ class OCMDiscoveryService implements IOCMDiscoveryService { if ($response->getStatusCode() === Http::STATUS_OK) { $body = $response->getBody(); // update provider with data returned by the request - $provider->import(json_decode($body, true, 8, JSON_THROW_ON_ERROR) ?? []); + $this->provider->import(json_decode($body, true, 8, JSON_THROW_ON_ERROR) ?? []); $this->cache->set($remote, $body, 60 * 60 * 24); } } catch (JsonException|OCMProviderException $e) { @@ -109,11 +108,11 @@ class OCMDiscoveryService implements IOCMDiscoveryService { throw new OCMProviderException('error while requesting remote ocm provider'); } - if (!$this->supportedAPIVersion($provider->getApiVersion())) { + if (!$this->supportedAPIVersion($this->provider->getApiVersion())) { throw new OCMProviderException('API version not supported'); } - return $provider; + return $this->provider; } /** |