mirror of
https://github.com/nextcloud/server.git
synced 2026-06-11 09:42:09 -04:00
feat: Allow to pass Node to BeforeDirectFileDownloadEvent
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
parent
064ea9c134
commit
4bcbe8a894
1 changed files with 21 additions and 4 deletions
|
|
@ -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
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in a new issue