blob: c21742d25ea2114ac527bc0c72cb2661b7cb6787 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
<?php
/**
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
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' => []
];
if (!$this->directEditingManager->isEnabled()) {
return $capabilities;
}
/**
* @var string $id
* @var IEditor $editor
*/
foreach ($this->directEditingManager->getEditors() as $id => $editor) {
$capabilities['editors'][$id] = [
'id' => $editor->getId(),
'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;
}
}
|