mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
feat(dav): allow extending propfind properties via event
Signed-off-by: Benjamin Frueh <benjamin.frueh@gmail.com> Update lib/public/Files/Events/BeforePropfindEvent.php Co-authored-by: Julius Knorr <jus@bitgrid.net> Signed-off-by: Benjamin Früh <134610227+benjaminfrueh@users.noreply.github.com> Update lib/public/Files/Events/BeforePropfindEvent.php Co-authored-by: Julius Knorr <jus@bitgrid.net> Signed-off-by: Benjamin Früh <134610227+benjaminfrueh@users.noreply.github.com> refactor: rename BeforePropfindEvent to BeforeRemotePropfindEvent Signed-off-by: Benjamin Frueh <benjamin.frueh@gmail.com> chore: update composer autoloader for new event class Signed-off-by: Benjamin Frueh <benjamin.frueh@gmail.com> Update lib/public/Files/Events/BeforeRemotePropfindEvent.php Co-authored-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com> Signed-off-by: Benjamin Früh <134610227+benjaminfrueh@users.noreply.github.com>
This commit is contained in:
parent
9cea0183f4
commit
b75a1bce15
4 changed files with 76 additions and 2 deletions
|
|
@ -440,6 +440,7 @@ return array(
|
|||
'OCP\\Files\\Events\\BeforeFileScannedEvent' => $baseDir . '/lib/public/Files/Events/BeforeFileScannedEvent.php',
|
||||
'OCP\\Files\\Events\\BeforeFileSystemSetupEvent' => $baseDir . '/lib/public/Files/Events/BeforeFileSystemSetupEvent.php',
|
||||
'OCP\\Files\\Events\\BeforeFolderScannedEvent' => $baseDir . '/lib/public/Files/Events/BeforeFolderScannedEvent.php',
|
||||
'OCP\\Files\\Events\\BeforeRemotePropfindEvent' => $baseDir . '/lib/public/Files/Events/BeforeRemotePropfindEvent.php',
|
||||
'OCP\\Files\\Events\\BeforeZipCreatedEvent' => $baseDir . '/lib/public/Files/Events/BeforeZipCreatedEvent.php',
|
||||
'OCP\\Files\\Events\\FileCacheUpdated' => $baseDir . '/lib/public/Files/Events/FileCacheUpdated.php',
|
||||
'OCP\\Files\\Events\\FileScannedEvent' => $baseDir . '/lib/public/Files/Events/FileScannedEvent.php',
|
||||
|
|
|
|||
|
|
@ -481,6 +481,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
|
|||
'OCP\\Files\\Events\\BeforeFileScannedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/BeforeFileScannedEvent.php',
|
||||
'OCP\\Files\\Events\\BeforeFileSystemSetupEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/BeforeFileSystemSetupEvent.php',
|
||||
'OCP\\Files\\Events\\BeforeFolderScannedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/BeforeFolderScannedEvent.php',
|
||||
'OCP\\Files\\Events\\BeforeRemotePropfindEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/BeforeRemotePropfindEvent.php',
|
||||
'OCP\\Files\\Events\\BeforeZipCreatedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/BeforeZipCreatedEvent.php',
|
||||
'OCP\\Files\\Events\\FileCacheUpdated' => __DIR__ . '/../../..' . '/lib/public/Files/Events/FileCacheUpdated.php',
|
||||
'OCP\\Files\\Events\\FileScannedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/FileScannedEvent.php',
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ use OC\MemCache\ArrayCache;
|
|||
use OCP\AppFramework\Http;
|
||||
use OCP\Constants;
|
||||
use OCP\Diagnostics\IEventLogger;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\Files\Events\BeforeRemotePropfindEvent;
|
||||
use OCP\Files\FileInfo;
|
||||
use OCP\Files\ForbiddenException;
|
||||
use OCP\Files\IMimeTypeDetector;
|
||||
|
|
@ -232,6 +234,34 @@ class DAV extends Common {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string>
|
||||
*/
|
||||
protected function getPropfindProperties(): array {
|
||||
$event = new BeforeRemotePropfindEvent(self::PROPFIND_PROPS);
|
||||
Server::get(IEventDispatcher::class)->dispatchTyped($event);
|
||||
return $event->getProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get property value from cached PROPFIND response.
|
||||
* For accessing app-specific properties not included in getMetaData().
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $propertyName
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPropfindPropertyValue(string $path, string $propertyName): mixed {
|
||||
$path = $this->cleanPath($path);
|
||||
$propfindResponse = $this->statCache->get($path);
|
||||
|
||||
if (!is_array($propfindResponse)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $propfindResponse[$propertyName] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Propfind call with cache handling.
|
||||
*
|
||||
|
|
@ -254,7 +284,7 @@ class DAV extends Common {
|
|||
try {
|
||||
$response = $this->client->propFind(
|
||||
$this->encodePath($path),
|
||||
self::PROPFIND_PROPS
|
||||
$this->getPropfindProperties()
|
||||
);
|
||||
$this->statCache->set($path, $response);
|
||||
} catch (ClientHttpException $e) {
|
||||
|
|
@ -818,7 +848,7 @@ class DAV extends Common {
|
|||
try {
|
||||
$responses = $this->client->propFind(
|
||||
$this->encodePath($directory),
|
||||
self::PROPFIND_PROPS,
|
||||
$this->getPropfindProperties(),
|
||||
1
|
||||
);
|
||||
|
||||
|
|
|
|||
42
lib/public/Files/Events/BeforeRemotePropfindEvent.php
Normal file
42
lib/public/Files/Events/BeforeRemotePropfindEvent.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCP\Files\Events;
|
||||
|
||||
use OCP\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* This event is fired before a PROPFIND request is sent to remote WebDAV storage
|
||||
* Used to extend the list of properties to request additional data from the remote server
|
||||
*
|
||||
* @since 33.0.0
|
||||
*/
|
||||
class BeforeRemotePropfindEvent extends Event {
|
||||
public function __construct(
|
||||
private array $properties,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string>
|
||||
* @since 33.0.0
|
||||
*/
|
||||
public function getProperties(): array {
|
||||
return $this->properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string> $properties
|
||||
* @since 33.0.0
|
||||
*/
|
||||
public function addProperties(array $properties): void {
|
||||
array_push($this->properties, ...$properties);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue