@@ -73,6 +73,7 @@ class PreviewManager implements IPreview {
7373 private IServerContainer $ container ;
7474 private IBinaryFinder $ binaryFinder ;
7575 private IMagickSupport $ imagickSupport ;
76+ private bool $ enablePreviews ;
7677
7778 public function __construct (
7879 IConfig $ config ,
@@ -96,6 +97,7 @@ public function __construct(
9697 $ this ->container = $ container ;
9798 $ this ->binaryFinder = $ binaryFinder ;
9899 $ this ->imagickSupport = $ imagickSupport ;
100+ $ this ->enablePreviews = $ config ->getSystemValueBool ('enable_previews ' , true );
99101 }
100102
101103 /**
@@ -109,7 +111,7 @@ public function __construct(
109111 * @return void
110112 */
111113 public function registerProvider ($ mimeTypeRegex , \Closure $ callable ): void {
112- if (!$ this ->config -> getSystemValueBool ( ' enable_previews ' , true ) ) {
114+ if (!$ this ->enablePreviews ) {
113115 return ;
114116 }
115117
@@ -124,7 +126,7 @@ public function registerProvider($mimeTypeRegex, \Closure $callable): void {
124126 * Get all providers
125127 */
126128 public function getProviders (): array {
127- if (!$ this ->config -> getSystemValueBool ( ' enable_previews ' , true ) ) {
129+ if (!$ this ->enablePreviews ) {
128130 return [];
129131 }
130132
@@ -181,6 +183,7 @@ private function getGenerator(): Generator {
181183 * @since 11.0.0 - \InvalidArgumentException was added in 12.0.0
182184 */
183185 public function getPreview (File $ file , $ width = -1 , $ height = -1 , $ crop = false , $ mode = IPreview::MODE_FILL , $ mimeType = null ) {
186+ $ this ->throwIfPreviewsDisabled ();
184187 $ previewConcurrency = $ this ->getGenerator ()->getNumConcurrentPreviews ('preview_concurrency_all ' );
185188 $ sem = Generator::guardWithSemaphore (Generator::SEMAPHORE_ID_ALL , $ previewConcurrency );
186189 try {
@@ -204,6 +207,7 @@ public function getPreview(File $file, $width = -1, $height = -1, $crop = false,
204207 * @since 19.0.0
205208 */
206209 public function generatePreviews (File $ file , array $ specifications , $ mimeType = null ) {
210+ $ this ->throwIfPreviewsDisabled ();
207211 return $ this ->getGenerator ()->generatePreviews ($ file , $ specifications , $ mimeType );
208212 }
209213
@@ -214,7 +218,7 @@ public function generatePreviews(File $file, array $specifications, $mimeType =
214218 * @return boolean
215219 */
216220 public function isMimeSupported ($ mimeType = '* ' ) {
217- if (!$ this ->config -> getSystemValueBool ( ' enable_previews ' , true ) ) {
221+ if (!$ this ->enablePreviews ) {
218222 return false ;
219223 }
220224
@@ -239,7 +243,7 @@ public function isMimeSupported($mimeType = '*') {
239243 * Check if a preview can be generated for a file
240244 */
241245 public function isAvailable (\OCP \Files \FileInfo $ file ): bool {
242- if (!$ this ->config -> getSystemValueBool ( ' enable_previews ' , true ) ) {
246+ if (!$ this ->enablePreviews ) {
243247 return false ;
244248 }
245249
@@ -475,4 +479,13 @@ private function registerBootstrapProviders(): void {
475479 });
476480 }
477481 }
482+
483+ /**
484+ * @throws NotFoundException if preview generation is disabled
485+ */
486+ private function throwIfPreviewsDisabled (): void {
487+ if (!$ this ->enablePreviews ) {
488+ throw new NotFoundException ('Previews disabled ' );
489+ }
490+ }
478491}
0 commit comments