Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/richdocuments.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2019-02-05 17:56:56 +0300
committerRoeland Jago Douma <roeland@famdouma.nl>2019-02-06 23:08:20 +0300
commitafe96a4593fda23b1fc73746c489905704280647 (patch)
tree973d00e55d9d6055dbdef4b2a9e06556b4a32a48 /lib/Capabilities.php
parent1ce50035eb2bea529c05781ed22291f776ee1170 (diff)
Move fetching the capabilities to a backgroundjob
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/Capabilities.php')
-rw-r--r--lib/Capabilities.php41
1 files changed, 3 insertions, 38 deletions
diff --git a/lib/Capabilities.php b/lib/Capabilities.php
index 861231ec..9efc7b69 100644
--- a/lib/Capabilities.php
+++ b/lib/Capabilities.php
@@ -34,33 +34,21 @@ use OCP\IURLGenerator;
class Capabilities implements ICapability {
- /** @var IConfig */
- private $config;
- /** @var IClientService */
- private $clientService;
- /** @var ITimeFactory */
- private $timeFactory;
/** @var ISimpleFolder */
private $appData;
/**
* Capabilities constructor.
*
- * @param IConfig $config
- * @param IClientService $clientService
* @param IAppData $appData
- * @param ITimeFactory $timeFactory
* @throws \OCP\Files\NotPermittedException
*/
- public function __construct(IConfig $config, IClientService $clientService, IAppData $appData, ITimeFactory $timeFactory) {
- $this->config = $config;
- $this->clientService = $clientService;
+ public function __construct(IAppData $appData) {
try {
$this->appData = $appData->getFolder('richdocuments');
} catch (NotFoundException $e) {
$this->appData = $appData->newFolder('richdocuments');
}
- $this->timeFactory = $timeFactory;
}
public function getCapabilities() {
@@ -90,37 +78,14 @@ class Capabilities implements ICapability {
try {
$file = $this->appData->getFile('capabilities.json');
$decodedFile = \json_decode($file->getContent(), true);
- if($decodedFile['timestamp'] + 3600 > $this->timeFactory->getTime()) {
- return \json_decode($decodedFile['data'], true);
- }
} catch (NotFoundException $e) {
- $file = $this->appData->newFile('capabilities.json');
- }
- $remoteHost = $this->config->getAppValue('richdocuments', 'wopi_url');
- if ($remoteHost === '') {
return [];
}
- $capabilitiesEndpoint = $remoteHost . '/hosting/capabilities';
- $client = $this->clientService->newClient();
- try {
- $response = $client->get(
- $capabilitiesEndpoint,
- [
- 'timeout' => 5,
- ]
- );
- } catch (\Exception $e) {
+ if (!is_array($decodedFile)) {
return [];
}
- $responseBody = $response->getBody();
- $file->putContent(
- \json_encode([
- 'data' => $responseBody,
- 'timestamp' => $this->timeFactory->getTime(),
- ])
- );
- return \json_decode($responseBody, true);
+ return $decodedFile;
}
}