aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin/lib/Sabre
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_trashbin/lib/Sabre')
-rw-r--r--apps/files_trashbin/lib/Sabre/AbstractTrash.php89
-rw-r--r--apps/files_trashbin/lib/Sabre/AbstractTrashFile.php22
-rw-r--r--apps/files_trashbin/lib/Sabre/AbstractTrashFolder.php63
-rw-r--r--apps/files_trashbin/lib/Sabre/ITrash.php32
-rw-r--r--apps/files_trashbin/lib/Sabre/RestoreFolder.php60
-rw-r--r--apps/files_trashbin/lib/Sabre/RootCollection.php51
-rw-r--r--apps/files_trashbin/lib/Sabre/TrashFile.php21
-rw-r--r--apps/files_trashbin/lib/Sabre/TrashFolder.php17
-rw-r--r--apps/files_trashbin/lib/Sabre/TrashFolderFile.php15
-rw-r--r--apps/files_trashbin/lib/Sabre/TrashFolderFolder.php12
-rw-r--r--apps/files_trashbin/lib/Sabre/TrashHome.php71
-rw-r--r--apps/files_trashbin/lib/Sabre/TrashRoot.php93
-rw-r--r--apps/files_trashbin/lib/Sabre/TrashbinPlugin.php180
13 files changed, 726 insertions, 0 deletions
diff --git a/apps/files_trashbin/lib/Sabre/AbstractTrash.php b/apps/files_trashbin/lib/Sabre/AbstractTrash.php
new file mode 100644
index 00000000000..f032395437b
--- /dev/null
+++ b/apps/files_trashbin/lib/Sabre/AbstractTrash.php
@@ -0,0 +1,89 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Files_Trashbin\Sabre;
+
+use OCA\Files_Trashbin\Service\ConfigService;
+use OCA\Files_Trashbin\Trash\ITrashItem;
+use OCA\Files_Trashbin\Trash\ITrashManager;
+use OCP\Files\FileInfo;
+use OCP\IUser;
+use Sabre\DAV\Exception\Forbidden;
+
+abstract class AbstractTrash implements ITrash {
+ public function __construct(
+ protected ITrashManager $trashManager,
+ protected ITrashItem $data,
+ ) {
+ }
+
+ public function getFilename(): string {
+ return $this->data->getName();
+ }
+
+ public function getDeletionTime(): int {
+ return $this->data->getDeletedTime();
+ }
+
+ public function getFileId(): int {
+ return $this->data->getId();
+ }
+
+ public function getFileInfo(): FileInfo {
+ return $this->data;
+ }
+
+ /**
+ * @psalm-suppress ImplementedReturnTypeMismatch \Sabre\DAV\IFile::getSize signature does not support 32bit
+ * @return int|float
+ */
+ public function getSize(): int|float {
+ return $this->data->getSize();
+ }
+
+ public function getLastModified(): int {
+ return $this->data->getMtime();
+ }
+
+ public function getContentType(): string {
+ return $this->data->getMimetype();
+ }
+
+ public function getETag(): string {
+ return $this->data->getEtag();
+ }
+
+ public function getName(): string {
+ return $this->data->getName();
+ }
+
+ public function getOriginalLocation(): string {
+ return $this->data->getOriginalLocation();
+ }
+
+ public function getTitle(): string {
+ return $this->data->getTitle();
+ }
+
+ public function getDeletedBy(): ?IUser {
+ return $this->data->getDeletedBy();
+ }
+
+ public function delete() {
+ if (!ConfigService::getDeleteFromTrashEnabled()) {
+ throw new Forbidden('Not allowed to delete items from the trash bin');
+ }
+
+ $this->trashManager->removeItem($this->data);
+ }
+
+ public function restore(): bool {
+ $this->trashManager->restoreItem($this->data);
+ return true;
+ }
+}
diff --git a/apps/files_trashbin/lib/Sabre/AbstractTrashFile.php b/apps/files_trashbin/lib/Sabre/AbstractTrashFile.php
new file mode 100644
index 00000000000..03014d23669
--- /dev/null
+++ b/apps/files_trashbin/lib/Sabre/AbstractTrashFile.php
@@ -0,0 +1,22 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Files_Trashbin\Sabre;
+
+use Sabre\DAV\Exception\Forbidden;
+use Sabre\DAV\IFile;
+
+abstract class AbstractTrashFile extends AbstractTrash implements IFile, ITrash {
+ public function put($data) {
+ throw new Forbidden();
+ }
+
+ public function setName($name) {
+ throw new Forbidden();
+ }
+}
diff --git a/apps/files_trashbin/lib/Sabre/AbstractTrashFolder.php b/apps/files_trashbin/lib/Sabre/AbstractTrashFolder.php
new file mode 100644
index 00000000000..9e8f67f4db6
--- /dev/null
+++ b/apps/files_trashbin/lib/Sabre/AbstractTrashFolder.php
@@ -0,0 +1,63 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Files_Trashbin\Sabre;
+
+use OCA\Files_Trashbin\Trash\ITrashItem;
+use OCP\Files\FileInfo;
+use Sabre\DAV\Exception\Forbidden;
+use Sabre\DAV\Exception\NotFound;
+use Sabre\DAV\ICollection;
+
+abstract class AbstractTrashFolder extends AbstractTrash implements ICollection, ITrash {
+ public function getChildren(): array {
+ $entries = $this->trashManager->listTrashFolder($this->data);
+
+ $children = array_map(function (ITrashItem $entry) {
+ if ($entry->getType() === FileInfo::TYPE_FOLDER) {
+ return new TrashFolderFolder($this->trashManager, $entry);
+ }
+ return new TrashFolderFile($this->trashManager, $entry);
+ }, $entries);
+
+ return $children;
+ }
+
+ public function getChild($name): ITrash {
+ $entries = $this->getChildren();
+
+ foreach ($entries as $entry) {
+ if ($entry->getName() === $name) {
+ return $entry;
+ }
+ }
+
+ throw new NotFound();
+ }
+
+ public function childExists($name): bool {
+ try {
+ $this->getChild($name);
+ return true;
+ } catch (NotFound $e) {
+ return false;
+ }
+ }
+
+ public function setName($name) {
+ throw new Forbidden();
+ }
+
+ public function createFile($name, $data = null) {
+ throw new Forbidden();
+ }
+
+ public function createDirectory($name) {
+ throw new Forbidden();
+ }
+}
diff --git a/apps/files_trashbin/lib/Sabre/ITrash.php b/apps/files_trashbin/lib/Sabre/ITrash.php
new file mode 100644
index 00000000000..f37e1ccd9c3
--- /dev/null
+++ b/apps/files_trashbin/lib/Sabre/ITrash.php
@@ -0,0 +1,32 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Files_Trashbin\Sabre;
+
+use OCP\Files\FileInfo;
+use OCP\IUser;
+
+interface ITrash {
+ public function restore(): bool;
+
+ public function getFilename(): string;
+
+ public function getOriginalLocation(): string;
+
+ public function getTitle(): string;
+
+ public function getDeletionTime(): int;
+
+ public function getDeletedBy(): ?IUser;
+
+ public function getSize(): int|float;
+
+ public function getFileId(): int;
+
+ public function getFileInfo(): FileInfo;
+}
diff --git a/apps/files_trashbin/lib/Sabre/RestoreFolder.php b/apps/files_trashbin/lib/Sabre/RestoreFolder.php
new file mode 100644
index 00000000000..781a28bbc25
--- /dev/null
+++ b/apps/files_trashbin/lib/Sabre/RestoreFolder.php
@@ -0,0 +1,60 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Files_Trashbin\Sabre;
+
+use Sabre\DAV\Exception\Forbidden;
+use Sabre\DAV\ICollection;
+use Sabre\DAV\IMoveTarget;
+use Sabre\DAV\INode;
+
+class RestoreFolder implements ICollection, IMoveTarget {
+ public function createFile($name, $data = null) {
+ throw new Forbidden();
+ }
+
+ public function createDirectory($name) {
+ throw new Forbidden();
+ }
+
+ public function getChild($name) {
+ return null;
+ }
+
+ public function delete() {
+ throw new Forbidden();
+ }
+
+ public function getName() {
+ return 'restore';
+ }
+
+ public function setName($name) {
+ throw new Forbidden();
+ }
+
+ public function getLastModified(): int {
+ return 0;
+ }
+
+ public function getChildren(): array {
+ return [];
+ }
+
+ public function childExists($name): bool {
+ return false;
+ }
+
+ public function moveInto($targetName, $sourcePath, INode $sourceNode): bool {
+ if (!($sourceNode instanceof ITrash)) {
+ return false;
+ }
+
+ return $sourceNode->restore();
+ }
+}
diff --git a/apps/files_trashbin/lib/Sabre/RootCollection.php b/apps/files_trashbin/lib/Sabre/RootCollection.php
new file mode 100644
index 00000000000..8886dae0895
--- /dev/null
+++ b/apps/files_trashbin/lib/Sabre/RootCollection.php
@@ -0,0 +1,51 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Files_Trashbin\Sabre;
+
+use OCA\Files_Trashbin\Trash\ITrashManager;
+use OCP\IConfig;
+use OCP\IUserSession;
+use OCP\Server;
+use Sabre\DAV\INode;
+use Sabre\DAVACL\AbstractPrincipalCollection;
+use Sabre\DAVACL\PrincipalBackend;
+
+class RootCollection extends AbstractPrincipalCollection {
+ public function __construct(
+ private ITrashManager $trashManager,
+ PrincipalBackend\BackendInterface $principalBackend,
+ IConfig $config,
+ ) {
+ parent::__construct($principalBackend, 'principals/users');
+ $this->disableListing = !$config->getSystemValue('debug', false);
+ }
+
+ /**
+ * This method returns a node for a principal.
+ *
+ * The passed array contains principal information, and is guaranteed to
+ * at least contain a uri item. Other properties may or may not be
+ * supplied by the authentication backend.
+ *
+ * @param array $principalInfo
+ * @return INode
+ */
+ public function getChildForPrincipal(array $principalInfo): TrashHome {
+ [, $name] = \Sabre\Uri\split($principalInfo['uri']);
+ $user = Server::get(IUserSession::class)->getUser();
+ if (is_null($user) || $name !== $user->getUID()) {
+ throw new \Sabre\DAV\Exception\Forbidden();
+ }
+ return new TrashHome($principalInfo, $this->trashManager, $user);
+ }
+
+ public function getName(): string {
+ return 'trashbin';
+ }
+}
diff --git a/apps/files_trashbin/lib/Sabre/TrashFile.php b/apps/files_trashbin/lib/Sabre/TrashFile.php
new file mode 100644
index 00000000000..29bcde769d9
--- /dev/null
+++ b/apps/files_trashbin/lib/Sabre/TrashFile.php
@@ -0,0 +1,21 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Files_Trashbin\Sabre;
+
+use OCA\Files_Trashbin\Trashbin;
+
+class TrashFile extends AbstractTrashFile {
+ public function get() {
+ return $this->data->getStorage()->fopen(Trashbin::getTrashFilename($this->data->getInternalPath(), $this->getDeletionTime()), 'rb');
+ }
+
+ public function getName(): string {
+ return Trashbin::getTrashFilename($this->data->getName(), $this->getDeletionTime());
+ }
+}
diff --git a/apps/files_trashbin/lib/Sabre/TrashFolder.php b/apps/files_trashbin/lib/Sabre/TrashFolder.php
new file mode 100644
index 00000000000..e1c495bf08e
--- /dev/null
+++ b/apps/files_trashbin/lib/Sabre/TrashFolder.php
@@ -0,0 +1,17 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Files_Trashbin\Sabre;
+
+use OCA\Files_Trashbin\Trashbin;
+
+class TrashFolder extends AbstractTrashFolder {
+ public function getName(): string {
+ return Trashbin::getTrashFilename($this->data->getName(), $this->getDeletionTime());
+ }
+}
diff --git a/apps/files_trashbin/lib/Sabre/TrashFolderFile.php b/apps/files_trashbin/lib/Sabre/TrashFolderFile.php
new file mode 100644
index 00000000000..37e70b717ae
--- /dev/null
+++ b/apps/files_trashbin/lib/Sabre/TrashFolderFile.php
@@ -0,0 +1,15 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Files_Trashbin\Sabre;
+
+class TrashFolderFile extends AbstractTrashFile {
+ public function get() {
+ return $this->data->getStorage()->fopen($this->data->getInternalPath(), 'rb');
+ }
+}
diff --git a/apps/files_trashbin/lib/Sabre/TrashFolderFolder.php b/apps/files_trashbin/lib/Sabre/TrashFolderFolder.php
new file mode 100644
index 00000000000..1a5cb98e114
--- /dev/null
+++ b/apps/files_trashbin/lib/Sabre/TrashFolderFolder.php
@@ -0,0 +1,12 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Files_Trashbin\Sabre;
+
+class TrashFolderFolder extends AbstractTrashFolder {
+}
diff --git a/apps/files_trashbin/lib/Sabre/TrashHome.php b/apps/files_trashbin/lib/Sabre/TrashHome.php
new file mode 100644
index 00000000000..fc291c76f17
--- /dev/null
+++ b/apps/files_trashbin/lib/Sabre/TrashHome.php
@@ -0,0 +1,71 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Files_Trashbin\Sabre;
+
+use OCA\Files_Trashbin\Trash\ITrashManager;
+use OCP\IUser;
+use Sabre\DAV\Exception\Forbidden;
+use Sabre\DAV\Exception\NotFound;
+use Sabre\DAV\ICollection;
+
+class TrashHome implements ICollection {
+ public function __construct(
+ private array $principalInfo,
+ private ITrashManager $trashManager,
+ private IUser $user,
+ ) {
+ }
+
+ public function delete() {
+ throw new Forbidden();
+ }
+
+ public function getName(): string {
+ [, $name] = \Sabre\Uri\split($this->principalInfo['uri']);
+ return $name;
+ }
+
+ public function setName($name) {
+ throw new Forbidden('Permission denied to rename this trashbin');
+ }
+
+ public function createFile($name, $data = null) {
+ throw new Forbidden('Not allowed to create files in the trashbin');
+ }
+
+ public function createDirectory($name) {
+ throw new Forbidden('Not allowed to create folders in the trashbin');
+ }
+
+ public function getChild($name) {
+ if ($name === 'restore') {
+ return new RestoreFolder();
+ }
+ if ($name === 'trash') {
+ return new TrashRoot($this->user, $this->trashManager);
+ }
+
+ throw new NotFound();
+ }
+
+ public function getChildren(): array {
+ return [
+ new RestoreFolder(),
+ new TrashRoot($this->user, $this->trashManager)
+ ];
+ }
+
+ public function childExists($name): bool {
+ return $name === 'restore' || $name === 'trash';
+ }
+
+ public function getLastModified(): int {
+ return 0;
+ }
+}
diff --git a/apps/files_trashbin/lib/Sabre/TrashRoot.php b/apps/files_trashbin/lib/Sabre/TrashRoot.php
new file mode 100644
index 00000000000..dd89583d9a1
--- /dev/null
+++ b/apps/files_trashbin/lib/Sabre/TrashRoot.php
@@ -0,0 +1,93 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Files_Trashbin\Sabre;
+
+use OCA\Files_Trashbin\Service\ConfigService;
+use OCA\Files_Trashbin\Trash\ITrashItem;
+use OCA\Files_Trashbin\Trash\ITrashManager;
+use OCA\Files_Trashbin\Trashbin;
+use OCP\Files\FileInfo;
+use OCP\IUser;
+use Sabre\DAV\Exception\Forbidden;
+use Sabre\DAV\Exception\NotFound;
+use Sabre\DAV\ICollection;
+
+class TrashRoot implements ICollection {
+
+ public function __construct(
+ private IUser $user,
+ private ITrashManager $trashManager,
+ ) {
+ }
+
+ public function delete() {
+ if (!ConfigService::getDeleteFromTrashEnabled()) {
+ throw new Forbidden('Not allowed to delete items from the trash bin');
+ }
+
+ Trashbin::deleteAll();
+ foreach ($this->trashManager->listTrashRoot($this->user) as $trashItem) {
+ $this->trashManager->removeItem($trashItem);
+ }
+ }
+
+ public function getName(): string {
+ return 'trash';
+ }
+
+ public function setName($name) {
+ throw new Forbidden('Permission denied to rename this trashbin');
+ }
+
+ public function createFile($name, $data = null) {
+ throw new Forbidden('Not allowed to create files in the trashbin');
+ }
+
+ public function createDirectory($name) {
+ throw new Forbidden('Not allowed to create folders in the trashbin');
+ }
+
+ public function getChildren(): array {
+ $entries = $this->trashManager->listTrashRoot($this->user);
+
+ $children = array_map(function (ITrashItem $entry) {
+ if ($entry->getType() === FileInfo::TYPE_FOLDER) {
+ return new TrashFolder($this->trashManager, $entry);
+ }
+ return new TrashFile($this->trashManager, $entry);
+ }, $entries);
+
+ return $children;
+ }
+
+ public function getChild($name): ITrash {
+ $entries = $this->getChildren();
+
+ foreach ($entries as $entry) {
+ if ($entry->getName() === $name) {
+ return $entry;
+ }
+ }
+
+ throw new NotFound();
+ }
+
+ public function childExists($name): bool {
+ try {
+ $this->getChild($name);
+ return true;
+ } catch (NotFound $e) {
+ return false;
+ }
+ }
+
+ public function getLastModified(): int {
+ return 0;
+ }
+}
diff --git a/apps/files_trashbin/lib/Sabre/TrashbinPlugin.php b/apps/files_trashbin/lib/Sabre/TrashbinPlugin.php
new file mode 100644
index 00000000000..54bb1326966
--- /dev/null
+++ b/apps/files_trashbin/lib/Sabre/TrashbinPlugin.php
@@ -0,0 +1,180 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Files_Trashbin\Sabre;
+
+use OC\Files\FileInfo;
+use OC\Files\View;
+use OCA\DAV\Connector\Sabre\FilesPlugin;
+use OCA\Files_Trashbin\Trash\ITrashItem;
+use OCP\IPreview;
+use Psr\Log\LoggerInterface;
+use Sabre\DAV\INode;
+use Sabre\DAV\PropFind;
+use Sabre\DAV\Server;
+use Sabre\DAV\ServerPlugin;
+use Sabre\HTTP\RequestInterface;
+use Sabre\HTTP\ResponseInterface;
+
+class TrashbinPlugin extends ServerPlugin {
+ public const TRASHBIN_FILENAME = '{http://nextcloud.org/ns}trashbin-filename';
+ public const TRASHBIN_ORIGINAL_LOCATION = '{http://nextcloud.org/ns}trashbin-original-location';
+ public const TRASHBIN_DELETION_TIME = '{http://nextcloud.org/ns}trashbin-deletion-time';
+ public const TRASHBIN_TITLE = '{http://nextcloud.org/ns}trashbin-title';
+ public const TRASHBIN_DELETED_BY_ID = '{http://nextcloud.org/ns}trashbin-deleted-by-id';
+ public const TRASHBIN_DELETED_BY_DISPLAY_NAME = '{http://nextcloud.org/ns}trashbin-deleted-by-display-name';
+ public const TRASHBIN_BACKEND = '{http://nextcloud.org/ns}trashbin-backend';
+
+ /** @var Server */
+ private $server;
+
+ public function __construct(
+ private IPreview $previewManager,
+ private View $view,
+ ) {
+ }
+
+ public function initialize(Server $server) {
+ $this->server = $server;
+
+ $this->server->on('propFind', [$this, 'propFind']);
+ $this->server->on('afterMethod:GET', [$this,'httpGet']);
+ $this->server->on('beforeMove', [$this, 'beforeMove']);
+ }
+
+
+ public function propFind(PropFind $propFind, INode $node) {
+ if (!($node instanceof ITrash)) {
+ return;
+ }
+
+ $propFind->handle(self::TRASHBIN_FILENAME, function () use ($node) {
+ return $node->getFilename();
+ });
+
+ $propFind->handle(self::TRASHBIN_ORIGINAL_LOCATION, function () use ($node) {
+ return $node->getOriginalLocation();
+ });
+
+ $propFind->handle(self::TRASHBIN_TITLE, function () use ($node) {
+ return $node->getTitle();
+ });
+
+ $propFind->handle(self::TRASHBIN_DELETION_TIME, function () use ($node) {
+ return $node->getDeletionTime();
+ });
+
+ $propFind->handle(self::TRASHBIN_DELETED_BY_ID, function () use ($node) {
+ return $node->getDeletedBy()?->getUID();
+ });
+
+ $propFind->handle(self::TRASHBIN_DELETED_BY_DISPLAY_NAME, function () use ($node) {
+ return $node->getDeletedBy()?->getDisplayName();
+ });
+
+ // Pass the real filename as the DAV display name
+ $propFind->handle(FilesPlugin::DISPLAYNAME_PROPERTYNAME, function () use ($node) {
+ return $node->getFilename();
+ });
+
+ $propFind->handle(FilesPlugin::SIZE_PROPERTYNAME, function () use ($node) {
+ return $node->getSize();
+ });
+
+ $propFind->handle(FilesPlugin::FILEID_PROPERTYNAME, function () use ($node) {
+ return $node->getFileId();
+ });
+
+ $propFind->handle(FilesPlugin::PERMISSIONS_PROPERTYNAME, function () {
+ return 'GD'; // read + delete
+ });
+
+ $propFind->handle(FilesPlugin::GETETAG_PROPERTYNAME, function () use ($node) {
+ // add fake etag, it is only needed to identify the preview image
+ return $node->getLastModified();
+ });
+
+ $propFind->handle(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME, function () use ($node) {
+ // add fake etag, it is only needed to identify the preview image
+ return $node->getFileId();
+ });
+
+ $propFind->handle(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, function () use ($node): string {
+ return $this->previewManager->isAvailable($node->getFileInfo()) ? 'true' : 'false';
+ });
+
+ $propFind->handle(FilesPlugin::MOUNT_TYPE_PROPERTYNAME, function () {
+ return '';
+ });
+
+ $propFind->handle(self::TRASHBIN_BACKEND, function () use ($node) {
+ $fileInfo = $node->getFileInfo();
+ if (!($fileInfo instanceof ITrashItem)) {
+ return '';
+ }
+ return $fileInfo->getTrashBackend()::class;
+ });
+ }
+
+ /**
+ * Set real filename on trashbin download
+ *
+ * @param RequestInterface $request
+ * @param ResponseInterface $response
+ */
+ public function httpGet(RequestInterface $request, ResponseInterface $response): void {
+ $path = $request->getPath();
+ $node = $this->server->tree->getNodeForPath($path);
+ if ($node instanceof ITrash) {
+ $response->addHeader('Content-Disposition', 'attachment; filename="' . $node->getFilename() . '"');
+ }
+ }
+
+ /**
+ * Check if a user has available space before attempting to
+ * restore from trashbin unless they have unlimited quota.
+ *
+ * @param string $sourcePath
+ * @param string $destinationPath
+ * @return bool
+ */
+ public function beforeMove(string $sourcePath, string $destinationPath): bool {
+ try {
+ $node = $this->server->tree->getNodeForPath($sourcePath);
+ $destinationNodeParent = $this->server->tree->getNodeForPath(dirname($destinationPath));
+ } catch (\Sabre\DAV\Exception $e) {
+ \OCP\Server::get(LoggerInterface::class)
+ ->error($e->getMessage(), ['app' => 'files_trashbin', 'exception' => $e]);
+ return true;
+ }
+
+ // Check if a file is being restored before proceeding
+ if (!$node instanceof ITrash || !$destinationNodeParent instanceof RestoreFolder) {
+ return true;
+ }
+
+ $fileInfo = $node->getFileInfo();
+ if (!$fileInfo instanceof ITrashItem) {
+ return true;
+ }
+ $restoreFolder = dirname($fileInfo->getOriginalLocation());
+ $freeSpace = $this->view->free_space($restoreFolder);
+ if ($freeSpace === FileInfo::SPACE_NOT_COMPUTED
+ || $freeSpace === FileInfo::SPACE_UNKNOWN
+ || $freeSpace === FileInfo::SPACE_UNLIMITED) {
+ return true;
+ }
+ $filesize = $fileInfo->getSize();
+ if ($freeSpace < $filesize) {
+ $this->server->httpResponse->setStatus(507);
+ return false;
+ }
+
+ return true;
+ }
+}