Files
nextcloud-server-mirror/apps/dav/lib/Files/NodeAttributes/HasPreviewProvider.php
John Molakvoæ defcdf7a16 refactor(dav): serve has-preview and favorite through node attribute providers
A Sabre plugin serves the registered attributes on remote.php, /webdav
and the public endpoints, preloading collections and search results at
once. has-preview and favorite move from FilesPlugin and TagsPlugin to
providers, so WebDAV and the serializer share one implementation.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: John Molakvoæ <14975046+skjnldsv@users.noreply.github.com>
2026-10-16 17:52:49 +02:00

39 lines
987 B
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\DAV\Files\NodeAttributes;
use NCU\Files\NodeAttributes\INodeAttributeProvider;
use NCU\Files\NodeAttributes\NodeAttributeContext;
use OCA\DAV\Connector\Sabre\FilesPlugin;
use OCP\Files\Node;
use OCP\IPreview;
/**
* Whether a preview can be generated for a node
*/
class HasPreviewProvider implements INodeAttributeProvider {
public function __construct(
private readonly IPreview $previewManager,
) {
}
#[\Override]
public function preload(NodeAttributeContext $context, array $nodes, array $attributes): void {
// Previews availability only depends on the node itself
}
#[\Override]
public function getAttributes(NodeAttributeContext $context, Node $node, array $attributes): array {
return [
FilesPlugin::HAS_PREVIEW_PROPERTYNAME => $this->previewManager->isAvailable($node),
];
}
}