diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-10-07 17:29:57 +0200 |
---|---|---|
committer | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-10-07 17:29:57 +0200 |
commit | 4bcbe8a894218f99a3b4426d36577928cdeea8cd (patch) | |
tree | 0595229e338db99929602c81c2288fd0a2996d94 | |
parent | 064ea9c1346e479f7fe8d8821b0a228251642df5 (diff) | |
download | nextcloud-server-4bcbe8a894218f99a3b4426d36577928cdeea8cd.tar.gz nextcloud-server-4bcbe8a894218f99a3b4426d36577928cdeea8cd.zip |
feat: Allow to pass `Node` to `BeforeDirectFileDownloadEvent`
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
-rw-r--r-- | lib/public/Files/Events/BeforeDirectFileDownloadEvent.php | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/lib/public/Files/Events/BeforeDirectFileDownloadEvent.php b/lib/public/Files/Events/BeforeDirectFileDownloadEvent.php index 550a5e17496..65a58e7193e 100644 --- a/lib/public/Files/Events/BeforeDirectFileDownloadEvent.php +++ b/lib/public/Files/Events/BeforeDirectFileDownloadEvent.php @@ -9,24 +9,34 @@ declare(strict_types=1); namespace OCP\Files\Events; use OCP\EventDispatcher\Event; +use OCP\Files\Node; /** - * This event is triggered when a user tries to download a file - * directly. + * This event is triggered when a user tries to download a file directly. + * Possible reasons are i.a. using the direct-download endpoint or WebDAV `GET` request. + * + * By setting `successful` to false the download can be aborted and denied. * * @since 25.0.0 */ class BeforeDirectFileDownloadEvent extends Event { private string $path; + private ?Node $node = null; private bool $successful = true; private ?string $errorMessage = null; /** * @since 25.0.0 + * @since 31.0.0 support `Node` as parameter for $path - passing a string is deprecated now. */ - public function __construct(string $path) { + public function __construct(string|Node $path) { parent::__construct(); - $this->path = $path; + if ($path instanceof Node) { + $this->node = $path; + $this->path = $path->getPath(); + } else { + $this->path = $path; + } } /** @@ -37,6 +47,13 @@ class BeforeDirectFileDownloadEvent extends Event { } /** + * @since 31.0.0 + */ + public function getNode(): ?Node { + return $this->node; + } + + /** * @since 25.0.0 */ public function isSuccessful(): bool { |