1
0

PropfindPlugin.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. /** @var Server */
  37. private $server;
  38. /** @var IPreview */
  39. private $previewManager;
  40. public function __construct(
  41. IPreview $previewManager
  42. ) {
  43. $this->previewManager = $previewManager;
  44. }
  45. public function initialize(Server $server) {
  46. $this->server = $server;
  47. $this->server->on('propFind', [$this, 'propFind']);
  48. }
  49. public function propFind(PropFind $propFind, INode $node) {
  50. if (!($node instanceof ITrash)) {
  51. return;
  52. }
  53. $propFind->handle(self::TRASHBIN_FILENAME, function () use ($node) {
  54. return $node->getFilename();
  55. });
  56. $propFind->handle(self::TRASHBIN_ORIGINAL_LOCATION, function () use ($node) {
  57. return $node->getOriginalLocation();
  58. });
  59. $propFind->handle(self::TRASHBIN_DELETION_TIME, function () use ($node) {
  60. return $node->getDeletionTime();
  61. });
  62. $propFind->handle(FilesPlugin::SIZE_PROPERTYNAME, function () use ($node) {
  63. return $node->getSize();
  64. });
  65. $propFind->handle(FilesPlugin::FILEID_PROPERTYNAME, function () use ($node) {
  66. return $node->getFileId();
  67. });
  68. $propFind->handle(FilesPlugin::PERMISSIONS_PROPERTYNAME, function () {
  69. return 'GD'; // read + delete
  70. });
  71. $propFind->handle(FilesPlugin::GETETAG_PROPERTYNAME, function () use ($node) {
  72. // add fake etag, it is only needed to identify the preview image
  73. return $node->getLastModified();
  74. });
  75. $propFind->handle(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME, function () use ($node) {
  76. // add fake etag, it is only needed to identify the preview image
  77. return $node->getFileId();
  78. });
  79. $propFind->handle(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, function () use ($node) {
  80. return $this->previewManager->isAvailable($node->getFileInfo());
  81. });
  82. $propFind->handle(FilesPlugin::MOUNT_TYPE_PROPERTYNAME, function () {
  83. return '';
  84. });
  85. }
  86. }