1313use OCA \Bookmarks \Contract \IImage ;
1414use OCA \Bookmarks \Db \Bookmark ;
1515use OCA \Bookmarks \Image ;
16+ use OCP \IBinaryFinder ;
1617use OCP \IConfig ;
1718use OCP \ITempManager ;
1819use Psr \Log \LoggerInterface ;
20+ use function exec ;
1921
2022class PageresBookmarkPreviewer implements IBookmarkPreviewer {
2123 public const CACHE_PREFIX = 'bookmarks.PageresPreviewService ' ;
@@ -32,11 +34,18 @@ class PageresBookmarkPreviewer implements IBookmarkPreviewer {
3234 * @var IConfig
3335 */
3436 private $ config ;
35-
36- public function __construct (ITempManager $ tempManager , LoggerInterface $ logger , IConfig $ config ) {
37+ private IBinaryFinder $ binaryFinder ;
38+
39+ public function __construct (
40+ ITempManager $ tempManager ,
41+ LoggerInterface $ logger ,
42+ IConfig $ config ,
43+ IBinaryFinder $ binaryFinder ,
44+ ) {
3745 $ this ->tempManager = $ tempManager ;
3846 $ this ->logger = $ logger ;
3947 $ this ->config = $ config ;
48+ $ this ->binaryFinder = $ binaryFinder ;
4049 }
4150
4251 /**
@@ -49,8 +58,8 @@ public function getImage($bookmark, $cacheOnly = false): ?IImage {
4958 return null ;
5059 }
5160
52- $ serverPath = self :: getPageresPath ( );
53- if ($ serverPath === null || $ cacheOnly ) {
61+ $ serverPath = $ this -> binaryFinder -> findBinaryPath ( ' pageres ' );
62+ if ($ serverPath === false || $ cacheOnly ) {
5463 return null ;
5564 }
5665
@@ -100,17 +109,4 @@ protected function fetchImage(string $serverPath, string $url): Image {
100109
101110 throw new Exception ("Pageres Error \nCommand: {$ cmd }\nOutput: " . implode (' ' . PHP_EOL , $ output ) . PHP_EOL );
102111 }
103-
104- /**
105- * @return null|string
106- */
107- public static function getPageresPath (): ?string {
108- @exec ('which pageres ' , $ serverPath );
109- $ path = trim (implode ("\n" , $ serverPath ));
110- if (!empty ($ path ) && is_readable ($ path )) {
111- return $ path ;
112- }
113-
114- return null ;
115- }
116112}
0 commit comments