3131
3232use InvalidArgumentException ;
3333use OCP \Files \Search \ISearchOperator ;
34+ use OCP \IPreview ;
3435use OCP \Search \FilterDefinition ;
3536use OCP \Search \IFilter ;
3637use OCP \Search \IFilteringProvider ;
@@ -71,7 +72,8 @@ public function __construct(
7172 IL10N $ l10n ,
7273 IURLGenerator $ urlGenerator ,
7374 IMimeTypeDetector $ mimeTypeDetector ,
74- IRootFolder $ rootFolder
75+ IRootFolder $ rootFolder ,
76+ private IPreview $ previewManager ,
7577 ) {
7678 $ this ->l10n = $ l10n ;
7779 $ this ->urlGenerator = $ urlGenerator ;
@@ -139,8 +141,12 @@ public function search(IUser $user, ISearchQuery $query): SearchResult {
139141 return SearchResult::paginated (
140142 $ this ->l10n ->t ('Files ' ),
141143 array_map (function (Node $ result ) use ($ userFolder ) {
142- // Generate thumbnail url
143- $ thumbnailUrl = $ this ->urlGenerator ->linkToRouteAbsolute ('core.Preview.getPreviewByFileId ' , ['x ' => 32 , 'y ' => 32 , 'fileId ' => $ result ->getId ()]);
144+ $ thumbnailUrl = $ this ->previewManager ->isMimeSupported ($ result ->getMimetype ())
145+ ? $ this ->urlGenerator ->linkToRouteAbsolute ('core.Preview.getPreviewByFileId ' , ['x ' => 32 , 'y ' => 32 , 'fileId ' => $ result ->getId ()])
146+ : '' ;
147+ $ icon = $ result ->getMimetype () === FileInfo::MIMETYPE_FOLDER
148+ ? 'icon-folder '
149+ : $ this ->mimeTypeDetector ->mimeTypeIcon ($ result ->getMimetype ());
144150 $ path = $ userFolder ->getRelativePath ($ result ->getPath ());
145151
146152 // Use shortened link to centralize the various
@@ -155,7 +161,7 @@ public function search(IUser $user, ISearchQuery $query): SearchResult {
155161 $ result ->getName (),
156162 $ this ->formatSubline ($ path ),
157163 $ this ->urlGenerator ->getAbsoluteURL ($ link ),
158- $ result -> getMimetype () === FileInfo:: MIMETYPE_FOLDER ? ' icon-folder ' : $ this -> mimeTypeDetector -> mimeTypeIcon ( $ result -> getMimetype ())
164+ $ icon,
159165 );
160166 $ searchResultEntry ->addAttribute ('fileId ' , (string )$ result ->getId ());
161167 $ searchResultEntry ->addAttribute ('path ' , $ path );
0 commit comments