@@ -151,7 +151,7 @@ public function getPreview(
151151 $ mimeType = null ,
152152 bool $ cacheResult = true ,
153153 ): ISimpleFile {
154- $ this ->throwIfPreviewsDisabled ($ file );
154+ $ this ->throwIfPreviewsDisabled ($ file, $ mimeType );
155155 $ previewConcurrency = $ this ->getGenerator ()->getNumConcurrentPreviews ('preview_concurrency_all ' );
156156 $ sem = Generator::guardWithSemaphore (Generator::SEMAPHORE_ID_ALL , $ previewConcurrency );
157157 try {
@@ -175,7 +175,7 @@ public function getPreview(
175175 * @since 19.0.0
176176 */
177177 public function generatePreviews (File $ file , array $ specifications , $ mimeType = null ) {
178- $ this ->throwIfPreviewsDisabled ($ file );
178+ $ this ->throwIfPreviewsDisabled ($ file, $ mimeType );
179179 return $ this ->getGenerator ()->generatePreviews ($ file , $ specifications , $ mimeType );
180180 }
181181
@@ -210,13 +210,15 @@ public function isMimeSupported($mimeType = '*') {
210210 /**
211211 * Check if a preview can be generated for a file
212212 */
213- public function isAvailable (\OCP \Files \FileInfo $ file ): bool {
213+ public function isAvailable (\OCP \Files \FileInfo $ file, ? string $ mimeType = null ): bool {
214214 if (!$ this ->enablePreviews ) {
215215 return false ;
216216 }
217217
218+ $ fileMimeType = $ mimeType ?? $ file ->getMimeType ();
219+
218220 $ this ->registerCoreProviders ();
219- if (!$ this ->isMimeSupported ($ file -> getMimetype () )) {
221+ if (!$ this ->isMimeSupported ($ fileMimeType )) {
220222 return false ;
221223 }
222224
@@ -226,7 +228,7 @@ public function isAvailable(\OCP\Files\FileInfo $file): bool {
226228 }
227229
228230 foreach ($ this ->providers as $ supportedMimeType => $ providers ) {
229- if (preg_match ($ supportedMimeType , $ file -> getMimetype () )) {
231+ if (preg_match ($ supportedMimeType , $ fileMimeType )) {
230232 foreach ($ providers as $ providerClosure ) {
231233 $ provider = $ this ->helper ->getProvider ($ providerClosure );
232234 if (!($ provider instanceof IProviderV2)) {
@@ -452,8 +454,8 @@ private function registerBootstrapProviders(): void {
452454 /**
453455 * @throws NotFoundException if preview generation is disabled
454456 */
455- private function throwIfPreviewsDisabled (File $ file ): void {
456- if (!$ this ->isAvailable ($ file )) {
457+ private function throwIfPreviewsDisabled (File $ file, ? string $ mimeType = null ): void {
458+ if (!$ this ->isAvailable ($ file, $ mimeType )) {
457459 throw new NotFoundException ('Previews disabled ' );
458460 }
459461 }
0 commit comments