From 05acd916b544352ace073dc87ea0556e363f528d Mon Sep 17 00:00:00 2001 From: Louis Chemineau Date: Thu, 29 Jun 2023 11:00:25 +0200 Subject: [PATCH] Base versions' has-preview on mimetype Signed-off-by: Louis Chemineau --- apps/files_versions/lib/Sabre/Plugin.php | 25 +++---------------- apps/files_versions/lib/Sabre/VersionFile.php | 4 --- 2 files changed, 3 insertions(+), 26 deletions(-) diff --git a/apps/files_versions/lib/Sabre/Plugin.php b/apps/files_versions/lib/Sabre/Plugin.php index b53f21039be..5aa64c812c6 100644 --- a/apps/files_versions/lib/Sabre/Plugin.php +++ b/apps/files_versions/lib/Sabre/Plugin.php @@ -28,10 +28,8 @@ namespace OCA\Files_Versions\Sabre; use OC\AppFramework\Http\Request; use OCA\DAV\Connector\Sabre\FilesPlugin; -use OCA\Files_Versions\Versions\IVersionManager; -use OCP\Files\NotFoundException; +use OCP\IPreview; use OCP\IRequest; -use OCP\IUserSession; use Sabre\DAV\Exception\NotFound; use Sabre\DAV\INode; use Sabre\DAV\PropFind; @@ -48,8 +46,7 @@ class Plugin extends ServerPlugin { public function __construct( private IRequest $request, - private IVersionManager $versionManager, - private IUserSession $userSession, + private IPreview $previewManager, ) { $this->request = $request; } @@ -94,25 +91,9 @@ class Plugin extends ServerPlugin { } public function propFind(PropFind $propFind, INode $node): void { - $user = $this->userSession->getUser(); - if ($node instanceof VersionFile) { $propFind->handle(self::VERSION_LABEL, fn() => $node->getLabel()); - - if ($user !== null) { - $propFind->handle(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, function () use ($node, $user) { - try { - $this->versionManager->getVersionFile( - $user, - $node->getSourceFile(), - $node->getVersion()->getRevisionId() - ); - return true; - } catch (NotFoundException $ex) { - return false; - } - }); - } + $propFind->handle(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, fn () => $this->previewManager->isMimeSupported($node->getContentType())); } } diff --git a/apps/files_versions/lib/Sabre/VersionFile.php b/apps/files_versions/lib/Sabre/VersionFile.php index bb05d66460a..a03ecd64b46 100644 --- a/apps/files_versions/lib/Sabre/VersionFile.php +++ b/apps/files_versions/lib/Sabre/VersionFile.php @@ -61,10 +61,6 @@ class VersionFile implements IFile { } } - public function getSourceFile(): FileInfo { - return $this->version->getSourceFile(); - } - public function getContentType(): string { return $this->version->getMimeType(); } -- 2.39.5