diff --git a/apps/files/appinfo/routes.php b/apps/files/appinfo/routes.php index f900b5ffbd81e..9d889fe0e69ce 100644 --- a/apps/files/appinfo/routes.php +++ b/apps/files/appinfo/routes.php @@ -99,6 +99,11 @@ ], ], 'ocs' => [ + [ + 'name' => 'DirectEditing#info', + 'url' => '/api/v1/directEditing', + 'verb' => 'GET' + ], [ 'name' => 'DirectEditing#templates', 'url' => '/api/v1/directEditing/templates/{editorId}/{creatorId}', diff --git a/apps/files/composer/composer/autoload_classmap.php b/apps/files/composer/composer/autoload_classmap.php index 462e51ffe0949..b350bfae07e6e 100644 --- a/apps/files/composer/composer/autoload_classmap.php +++ b/apps/files/composer/composer/autoload_classmap.php @@ -40,6 +40,7 @@ 'OCA\\Files\\Exception\\TransferOwnershipException' => $baseDir . '/../lib/Exception/TransferOwnershipException.php', 'OCA\\Files\\Helper' => $baseDir . '/../lib/Helper.php', 'OCA\\Files\\Listener\\LegacyLoadAdditionalScriptsAdapter' => $baseDir . '/../lib/Listener/LegacyLoadAdditionalScriptsAdapter.php', + 'OCA\\Files\\Service\\DirectEditingService' => $baseDir . '/../lib/Service/DirectEditingService.php', 'OCA\\Files\\Service\\OwnershipTransferService' => $baseDir . '/../lib/Service/OwnershipTransferService.php', 'OCA\\Files\\Service\\TagService' => $baseDir . '/../lib/Service/TagService.php', ); diff --git a/apps/files/composer/composer/autoload_static.php b/apps/files/composer/composer/autoload_static.php index b41faa6f8c361..34a64f3253158 100644 --- a/apps/files/composer/composer/autoload_static.php +++ b/apps/files/composer/composer/autoload_static.php @@ -55,6 +55,7 @@ class ComposerStaticInitFiles 'OCA\\Files\\Exception\\TransferOwnershipException' => __DIR__ . '/..' . '/../lib/Exception/TransferOwnershipException.php', 'OCA\\Files\\Helper' => __DIR__ . '/..' . '/../lib/Helper.php', 'OCA\\Files\\Listener\\LegacyLoadAdditionalScriptsAdapter' => __DIR__ . '/..' . '/../lib/Listener/LegacyLoadAdditionalScriptsAdapter.php', + 'OCA\\Files\\Service\\DirectEditingService' => __DIR__ . '/..' . '/../lib/Service/DirectEditingService.php', 'OCA\\Files\\Service\\OwnershipTransferService' => __DIR__ . '/..' . '/../lib/Service/OwnershipTransferService.php', 'OCA\\Files\\Service\\TagService' => __DIR__ . '/..' . '/../lib/Service/TagService.php', ); diff --git a/apps/files/lib/Capabilities.php b/apps/files/lib/Capabilities.php index 1318a56f717b2..16b51872f1a86 100644 --- a/apps/files/lib/Capabilities.php +++ b/apps/files/lib/Capabilities.php @@ -26,6 +26,7 @@ namespace OCA\Files; use OC\DirectEditing\Manager; +use OCA\Files\Service\DirectEditingService; use OCP\Capabilities\ICapability; use OCP\DirectEditing\ACreateEmpty; use OCP\DirectEditing\ACreateFromTemplate; @@ -44,21 +45,17 @@ class Capabilities implements ICapability { /** @var IConfig */ protected $config; - /** @var Manager */ - protected $directEditingManager; - - /** @var IEventDispatcher */ - protected $eventDispatcher; + /** @var DirectEditingService */ + protected $directEditingService; /** * Capabilities constructor. * * @param IConfig $config */ - public function __construct(IConfig $config, Manager $manager, IEventDispatcher $eventDispatcher) { + public function __construct(IConfig $config, DirectEditingService $directEditingService) { $this->config = $config; - $this->directEditingManager = $manager; - $this->eventDispatcher = $eventDispatcher; + $this->directEditingService = $directEditingService; } /** @@ -71,43 +68,13 @@ public function getCapabilities() { 'files' => [ 'bigfilechunking' => true, 'blacklisted_files' => $this->config->getSystemValue('blacklisted_files', ['.htaccess']), - 'directEditing' => $this->getDirectEditingCapabilitites() + 'directEditing' => [ + 'url' => \OC::$server->getURLGenerator()->linkToOCSRouteAbsolute('files.DirectEditing.info'), + 'etag' => $this->directEditingService->getDirectEditingETag() + ] ], ]; } - private function getDirectEditingCapabilitites(): array { - $this->eventDispatcher->dispatchTyped(new RegisterDirectEditorEvent($this->directEditingManager)); - - $capabilities = [ - 'editors' => [], - 'creators' => [] - ]; - /** - * @var string $id - * @var IEditor $editor - */ - foreach ($this->directEditingManager->getEditors() as $id => $editor) { - $capabilities['editors'][$id] = [ - 'name' => $editor->getName(), - 'mimetypes' => $editor->getMimetypes(), - 'optionalMimetypes' => $editor->getMimetypesOptional(), - 'secure' => $editor->isSecure(), - ]; - /** @var ACreateEmpty|ACreateFromTemplate $creator */ - foreach ($editor->getCreators() as $creator) { - $id = $creator->getId(); - $capabilities['creators'][$id] = [ - 'id' => $id, - 'editor' => $editor->getId(), - 'name' => $creator->getName(), - 'extension' => $creator->getExtension(), - 'templates' => $creator instanceof ACreateFromTemplate, - 'mimetype' => $creator->getMimetype() - ]; - } - } - return $capabilities; - } } diff --git a/apps/files/lib/Controller/DirectEditingController.php b/apps/files/lib/Controller/DirectEditingController.php index 11d09e2f074b7..0a086c3da601d 100644 --- a/apps/files/lib/Controller/DirectEditingController.php +++ b/apps/files/lib/Controller/DirectEditingController.php @@ -25,6 +25,7 @@ use Exception; +use OCA\Files\Service\DirectEditingService; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCSController; @@ -52,16 +53,29 @@ class DirectEditingController extends OCSController { /** @var ILogger */ private $logger; + /** @var DirectEditingService */ + private $directEditingService; + public function __construct($appName, IRequest $request, $corsMethods, $corsAllowedHeaders, $corsMaxAge, - IEventDispatcher $eventDispatcher, IURLGenerator $urlGenerator, IManager $manager, ILogger $logger) { + IEventDispatcher $eventDispatcher, IURLGenerator $urlGenerator, IManager $manager, DirectEditingService $directEditingService, ILogger $logger) { parent::__construct($appName, $request, $corsMethods, $corsAllowedHeaders, $corsMaxAge); $this->eventDispatcher = $eventDispatcher; $this->directEditingManager = $manager; + $this->directEditingService = $directEditingService; $this->logger = $logger; $this->urlGenerator = $urlGenerator; } + /** + * @NoAdminRequired + */ + public function info(): DataResponse { + $response = new DataResponse($this->directEditingService->getDirectEditingCapabilitites()); + $response->setETag($this->directEditingService->getDirectEditingETag()); + return $response; + } + /** * @NoAdminRequired */ diff --git a/apps/files/lib/Service/DirectEditingService.php b/apps/files/lib/Service/DirectEditingService.php new file mode 100644 index 0000000000000..7e906238d87b2 --- /dev/null +++ b/apps/files/lib/Service/DirectEditingService.php @@ -0,0 +1,85 @@ + + * + * @author Julius Härtl + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\Files\Service; + + +use OCP\DirectEditing\ACreateEmpty; +use OCP\DirectEditing\ACreateFromTemplate; +use OCP\DirectEditing\IEditor; +use OCP\DirectEditing\IManager; +use OCP\DirectEditing\RegisterDirectEditorEvent; +use OCP\EventDispatcher\IEventDispatcher; + +class DirectEditingService { + + /** @var IManager */ + private $directEditingManager; + /** @var IEventDispatcher */ + private $eventDispatcher; + + public function __construct(IEventDispatcher $eventDispatcher, IManager $directEditingManager) { + $this->directEditingManager = $directEditingManager; + $this->eventDispatcher = $eventDispatcher; + } + + public function getDirectEditingETag(): string { + return \md5(\json_encode($this->getDirectEditingCapabilitites())); + } + + public function getDirectEditingCapabilitites(): array { + $this->eventDispatcher->dispatchTyped(new RegisterDirectEditorEvent($this->directEditingManager)); + + $capabilities = [ + 'editors' => [], + 'creators' => [] + ]; + + /** + * @var string $id + * @var IEditor $editor + */ + foreach ($this->directEditingManager->getEditors() as $id => $editor) { + $capabilities['editors'][$id] = [ + 'name' => $editor->getName(), + 'mimetypes' => $editor->getMimetypes(), + 'optionalMimetypes' => $editor->getMimetypesOptional(), + 'secure' => $editor->isSecure(), + ]; + /** @var ACreateEmpty|ACreateFromTemplate $creator */ + foreach ($editor->getCreators() as $creator) { + $id = $creator->getId(); + $capabilities['creators'][$id] = [ + 'id' => $id, + 'editor' => $editor->getId(), + 'name' => $creator->getName(), + 'extension' => $creator->getExtension(), + 'templates' => $creator instanceof ACreateFromTemplate, + 'mimetype' => $creator->getMimetype() + ]; + } + } + return $capabilities; + } + +}