diff options
author | Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> | 2023-11-17 11:55:45 +0100 |
---|---|---|
committer | Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> | 2023-11-17 16:22:48 +0100 |
commit | 01de485aca52bfb3339b2122f2491b6c6a0ce247 (patch) | |
tree | bd7e6730958dd5883f4e352736e3b36942044d71 /apps | |
parent | 8c24a32fda99715fdcb4020eb6f0231d13eb6e79 (diff) | |
download | nextcloud-server-01de485aca52bfb3339b2122f2491b6c6a0ce247.tar.gz nextcloud-server-01de485aca52bfb3339b2122f2491b6c6a0ce247.zip |
fix(files): avoid sending thumbnail URL for directory as none exists
Signed-off-by: Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files/lib/Search/FilesSearchProvider.php | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/apps/files/lib/Search/FilesSearchProvider.php b/apps/files/lib/Search/FilesSearchProvider.php index 35dd0e21463..d2a30d10674 100644 --- a/apps/files/lib/Search/FilesSearchProvider.php +++ b/apps/files/lib/Search/FilesSearchProvider.php @@ -31,6 +31,7 @@ namespace OCA\Files\Search; use InvalidArgumentException; use OCP\Files\Search\ISearchOperator; +use OCP\IPreview; use OCP\Search\FilterDefinition; use OCP\Search\IFilter; use OCP\Search\IFilteringProvider; @@ -71,7 +72,8 @@ class FilesSearchProvider implements IFilteringProvider { IL10N $l10n, IURLGenerator $urlGenerator, IMimeTypeDetector $mimeTypeDetector, - IRootFolder $rootFolder + IRootFolder $rootFolder, + private IPreview $previewManager, ) { $this->l10n = $l10n; $this->urlGenerator = $urlGenerator; @@ -139,8 +141,12 @@ class FilesSearchProvider implements IFilteringProvider { return SearchResult::paginated( $this->l10n->t('Files'), array_map(function (Node $result) use ($userFolder) { - // Generate thumbnail url - $thumbnailUrl = $this->urlGenerator->linkToRouteAbsolute('core.Preview.getPreviewByFileId', ['x' => 32, 'y' => 32, 'fileId' => $result->getId()]); + $thumbnailUrl = $this->previewManager->isMimeSupported($result->getMimetype()) + ? $this->urlGenerator->linkToRouteAbsolute('core.Preview.getPreviewByFileId', ['x' => 32, 'y' => 32, 'fileId' => $result->getId()]) + : ''; + $icon = $result->getMimetype() === FileInfo::MIMETYPE_FOLDER + ? 'icon-folder' + : $this->mimeTypeDetector->mimeTypeIcon($result->getMimetype()); $path = $userFolder->getRelativePath($result->getPath()); // Use shortened link to centralize the various @@ -155,7 +161,7 @@ class FilesSearchProvider implements IFilteringProvider { $result->getName(), $this->formatSubline($path), $this->urlGenerator->getAbsoluteURL($link), - $result->getMimetype() === FileInfo::MIMETYPE_FOLDER ? 'icon-folder' : $this->mimeTypeDetector->mimeTypeIcon($result->getMimetype()) + $icon, ); $searchResultEntry->addAttribute('fileId', (string)$result->getId()); $searchResultEntry->addAttribute('path', $path); |