PropfindPlugin.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Robin Appelman <robin@icewind.nl>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\Files_Trashbin\Sabre;
  27. use OCA\DAV\Connector\Sabre\FilesPlugin;
  28. use OCP\IPreview;
  29. use Sabre\DAV\INode;
  30. use Sabre\DAV\PropFind;
  31. use Sabre\DAV\Server;
  32. use Sabre\DAV\ServerPlugin;
  33. class PropfindPlugin extends ServerPlugin {
  34. public const TRASHBIN_FILENAME = '{http://nextcloud.org/ns}trashbin-filename';
  35. public const TRASHBIN_ORIGINAL_LOCATION = '{http://nextcloud.org/ns}trashbin-original-location';
  36. public const TRASHBIN_DELETION_TIME = '{http://nextcloud.org/ns}trashbin-deletion-time';
  37. public const TRASHBIN_TITLE = '{http://nextcloud.org/ns}trashbin-title';
  38. /** @var Server */
  39. private $server;
  40. /** @var IPreview */
  41. private $previewManager;
  42. public function __construct(
  43. IPreview $previewManager
  44. ) {
  45. $this->previewManager = $previewManager;
  46. }
  47. public function initialize(Server $server) {
  48. $this->server = $server;
  49. $this->server->on('propFind', [$this, 'propFind']);
  50. }
  51. public function propFind(PropFind $propFind, INode $node) {
  52. if (!($node instanceof ITrash)) {
  53. return;
  54. }
  55. $propFind->handle(self::TRASHBIN_FILENAME, function () use ($node) {
  56. return $node->getFilename();
  57. });
  58. $propFind->handle(self::TRASHBIN_ORIGINAL_LOCATION, function () use ($node) {
  59. return $node->getOriginalLocation();
  60. });
  61. $propFind->handle(self::TRASHBIN_TITLE, function () use ($node) {
  62. return $node->getTitle();
  63. });
  64. $propFind->handle(self::TRASHBIN_DELETION_TIME, function () use ($node) {
  65. return $node->getDeletionTime();
  66. });
  67. $propFind->handle(FilesPlugin::SIZE_PROPERTYNAME, function () use ($node) {
  68. return $node->getSize();
  69. });
  70. $propFind->handle(FilesPlugin::FILEID_PROPERTYNAME, function () use ($node) {
  71. return $node->getFileId();
  72. });
  73. $propFind->handle(FilesPlugin::PERMISSIONS_PROPERTYNAME, function () {
  74. return 'GD'; // read + delete
  75. });
  76. $propFind->handle(FilesPlugin::GETETAG_PROPERTYNAME, function () use ($node) {
  77. // add fake etag, it is only needed to identify the preview image
  78. return $node->getLastModified();
  79. });
  80. $propFind->handle(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME, function () use ($node) {
  81. // add fake etag, it is only needed to identify the preview image
  82. return $node->getFileId();
  83. });
  84. $propFind->handle(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, function () use ($node) {
  85. return $this->previewManager->isAvailable($node->getFileInfo());
  86. });
  87. $propFind->handle(FilesPlugin::MOUNT_TYPE_PROPERTYNAME, function () {
  88. return '';
  89. });
  90. }
  91. }