@@ -22,75 +22,75 @@ |
||
22 | 22 | use Sabre\HTTP\ResponseInterface; |
23 | 23 | |
24 | 24 | class Plugin extends ServerPlugin { |
25 | - private Server $server; |
|
26 | - |
|
27 | - public const LABEL = 'label'; |
|
28 | - |
|
29 | - public const AUTHOR = 'author'; |
|
30 | - |
|
31 | - public const VERSION_LABEL = '{http://nextcloud.org/ns}version-label'; |
|
32 | - |
|
33 | - public const VERSION_AUTHOR = '{http://nextcloud.org/ns}version-author'; // dav property for author |
|
34 | - |
|
35 | - public function __construct( |
|
36 | - private IRequest $request, |
|
37 | - private IPreview $previewManager, |
|
38 | - ) { |
|
39 | - $this->request = $request; |
|
40 | - } |
|
41 | - |
|
42 | - public function initialize(Server $server) { |
|
43 | - $this->server = $server; |
|
44 | - |
|
45 | - $server->on('afterMethod:GET', [$this, 'afterGet']); |
|
46 | - $server->on('propFind', [$this, 'propFind']); |
|
47 | - $server->on('propPatch', [$this, 'propPatch']); |
|
48 | - } |
|
49 | - |
|
50 | - public function afterGet(RequestInterface $request, ResponseInterface $response) { |
|
51 | - $path = $request->getPath(); |
|
52 | - if (!str_starts_with($path, 'versions')) { |
|
53 | - return; |
|
54 | - } |
|
55 | - |
|
56 | - try { |
|
57 | - $node = $this->server->tree->getNodeForPath($path); |
|
58 | - } catch (NotFound $e) { |
|
59 | - return; |
|
60 | - } |
|
61 | - |
|
62 | - if (!($node instanceof VersionFile)) { |
|
63 | - return; |
|
64 | - } |
|
65 | - |
|
66 | - $filename = $node->getVersion()->getSourceFileName(); |
|
67 | - |
|
68 | - if ($this->request->isUserAgent( |
|
69 | - [ |
|
70 | - Request::USER_AGENT_IE, |
|
71 | - Request::USER_AGENT_ANDROID_MOBILE_CHROME, |
|
72 | - Request::USER_AGENT_FREEBOX, |
|
73 | - ])) { |
|
74 | - $response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"'); |
|
75 | - } else { |
|
76 | - $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename) |
|
77 | - . '; filename="' . rawurlencode($filename) . '"'); |
|
78 | - } |
|
79 | - } |
|
80 | - |
|
81 | - public function propFind(PropFind $propFind, INode $node): void { |
|
82 | - if ($node instanceof VersionFile) { |
|
83 | - $propFind->handle(self::VERSION_LABEL, fn () => $node->getMetadataValue(self::LABEL)); |
|
84 | - $propFind->handle(self::VERSION_AUTHOR, fn () => $node->getMetadataValue(self::AUTHOR)); |
|
85 | - $propFind->handle(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, fn () => $this->previewManager->isMimeSupported($node->getContentType())); |
|
86 | - } |
|
87 | - } |
|
88 | - |
|
89 | - public function propPatch($path, PropPatch $propPatch): void { |
|
90 | - $node = $this->server->tree->getNodeForPath($path); |
|
91 | - |
|
92 | - if ($node instanceof VersionFile) { |
|
93 | - $propPatch->handle(self::VERSION_LABEL, fn (string $label) => $node->setMetadataValue(self::LABEL, $label)); |
|
94 | - } |
|
95 | - } |
|
25 | + private Server $server; |
|
26 | + |
|
27 | + public const LABEL = 'label'; |
|
28 | + |
|
29 | + public const AUTHOR = 'author'; |
|
30 | + |
|
31 | + public const VERSION_LABEL = '{http://nextcloud.org/ns}version-label'; |
|
32 | + |
|
33 | + public const VERSION_AUTHOR = '{http://nextcloud.org/ns}version-author'; // dav property for author |
|
34 | + |
|
35 | + public function __construct( |
|
36 | + private IRequest $request, |
|
37 | + private IPreview $previewManager, |
|
38 | + ) { |
|
39 | + $this->request = $request; |
|
40 | + } |
|
41 | + |
|
42 | + public function initialize(Server $server) { |
|
43 | + $this->server = $server; |
|
44 | + |
|
45 | + $server->on('afterMethod:GET', [$this, 'afterGet']); |
|
46 | + $server->on('propFind', [$this, 'propFind']); |
|
47 | + $server->on('propPatch', [$this, 'propPatch']); |
|
48 | + } |
|
49 | + |
|
50 | + public function afterGet(RequestInterface $request, ResponseInterface $response) { |
|
51 | + $path = $request->getPath(); |
|
52 | + if (!str_starts_with($path, 'versions')) { |
|
53 | + return; |
|
54 | + } |
|
55 | + |
|
56 | + try { |
|
57 | + $node = $this->server->tree->getNodeForPath($path); |
|
58 | + } catch (NotFound $e) { |
|
59 | + return; |
|
60 | + } |
|
61 | + |
|
62 | + if (!($node instanceof VersionFile)) { |
|
63 | + return; |
|
64 | + } |
|
65 | + |
|
66 | + $filename = $node->getVersion()->getSourceFileName(); |
|
67 | + |
|
68 | + if ($this->request->isUserAgent( |
|
69 | + [ |
|
70 | + Request::USER_AGENT_IE, |
|
71 | + Request::USER_AGENT_ANDROID_MOBILE_CHROME, |
|
72 | + Request::USER_AGENT_FREEBOX, |
|
73 | + ])) { |
|
74 | + $response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"'); |
|
75 | + } else { |
|
76 | + $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename) |
|
77 | + . '; filename="' . rawurlencode($filename) . '"'); |
|
78 | + } |
|
79 | + } |
|
80 | + |
|
81 | + public function propFind(PropFind $propFind, INode $node): void { |
|
82 | + if ($node instanceof VersionFile) { |
|
83 | + $propFind->handle(self::VERSION_LABEL, fn () => $node->getMetadataValue(self::LABEL)); |
|
84 | + $propFind->handle(self::VERSION_AUTHOR, fn () => $node->getMetadataValue(self::AUTHOR)); |
|
85 | + $propFind->handle(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, fn () => $this->previewManager->isMimeSupported($node->getContentType())); |
|
86 | + } |
|
87 | + } |
|
88 | + |
|
89 | + public function propPatch($path, PropPatch $propPatch): void { |
|
90 | + $node = $this->server->tree->getNodeForPath($path); |
|
91 | + |
|
92 | + if ($node instanceof VersionFile) { |
|
93 | + $propPatch->handle(self::VERSION_LABEL, fn (string $label) => $node->setMetadataValue(self::LABEL, $label)); |
|
94 | + } |
|
95 | + } |
|
96 | 96 | } |
@@ -20,36 +20,36 @@ |
||
20 | 20 | |
21 | 21 | /** @template-implements IEventListener<NodeWrittenEvent> */ |
22 | 22 | class VersionAuthorListener implements IEventListener { |
23 | - public function __construct( |
|
24 | - private IVersionManager $versionManager, |
|
25 | - private IUserSession $userSession, |
|
26 | - ) { |
|
27 | - } |
|
23 | + public function __construct( |
|
24 | + private IVersionManager $versionManager, |
|
25 | + private IUserSession $userSession, |
|
26 | + ) { |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * @abstract handles events from a nodes version being changed |
|
31 | - * @param Event $event the event that triggered this listener to activate |
|
32 | - */ |
|
33 | - public function handle(Event $event): void { |
|
34 | - if ($event instanceof NodeWrittenEvent) { |
|
35 | - $this->post_write_hook($event->getNode()); |
|
36 | - } |
|
37 | - } |
|
29 | + /** |
|
30 | + * @abstract handles events from a nodes version being changed |
|
31 | + * @param Event $event the event that triggered this listener to activate |
|
32 | + */ |
|
33 | + public function handle(Event $event): void { |
|
34 | + if ($event instanceof NodeWrittenEvent) { |
|
35 | + $this->post_write_hook($event->getNode()); |
|
36 | + } |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @abstract handles the NodeWrittenEvent, and sets the metadata for the associated node |
|
41 | - * @param Node $node the node that is currently being written |
|
42 | - */ |
|
43 | - public function post_write_hook(Node $node): void { |
|
44 | - $user = $this->userSession->getUser(); |
|
45 | - // Do not handle folders or users that we cannot get metadata from |
|
46 | - if ($node instanceof Folder || is_null($user)) { |
|
47 | - return; |
|
48 | - } |
|
49 | - // check if our version manager supports setting the metadata |
|
50 | - if ($this->versionManager instanceof IMetadataVersionBackend) { |
|
51 | - $author = $user->getUID(); |
|
52 | - $this->versionManager->setMetadataValue($node, $node->getMTime(), Plugin::AUTHOR, $author); |
|
53 | - } |
|
54 | - } |
|
39 | + /** |
|
40 | + * @abstract handles the NodeWrittenEvent, and sets the metadata for the associated node |
|
41 | + * @param Node $node the node that is currently being written |
|
42 | + */ |
|
43 | + public function post_write_hook(Node $node): void { |
|
44 | + $user = $this->userSession->getUser(); |
|
45 | + // Do not handle folders or users that we cannot get metadata from |
|
46 | + if ($node instanceof Folder || is_null($user)) { |
|
47 | + return; |
|
48 | + } |
|
49 | + // check if our version manager supports setting the metadata |
|
50 | + if ($this->versionManager instanceof IMetadataVersionBackend) { |
|
51 | + $author = $user->getUID(); |
|
52 | + $this->versionManager->setMetadataValue($node, $node->getMTime(), Plugin::AUTHOR, $author); |
|
53 | + } |
|
54 | + } |
|
55 | 55 | } |