You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PropfindPlugin.php 3.3KB

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