feat: Allow to pass Node to BeforeDirectFileDownloadEvent

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
Ferdinand Thiessen 2024-10-07 17:29:57 +02:00
parent 064ea9c134
commit 4bcbe8a894
No known key found for this signature in database
GPG key ID: 45FAE7268762B400

View file

@ -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;
}
}
/**
@ -36,6 +46,13 @@ class BeforeDirectFileDownloadEvent extends Event {
return $this->path;
}
/**
* @since 31.0.0
*/
public function getNode(): ?Node {
return $this->node;
}
/**
* @since 25.0.0
*/