Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(preview): don't create folder structure when previews are disabled #45866

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions lib/private/PreviewManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class PreviewManager implements IPreview {
private IServerContainer $container;
private IBinaryFinder $binaryFinder;
private IMagickSupport $imagickSupport;
private bool $enablePreviews;

public function __construct(
IConfig $config,
Expand All @@ -73,6 +74,7 @@ public function __construct(
$this->container = $container;
$this->binaryFinder = $binaryFinder;
$this->imagickSupport = $imagickSupport;
$this->enablePreviews = $config->getSystemValueBool('enable_previews', true);
}

/**
Expand All @@ -86,7 +88,7 @@ public function __construct(
* @return void
*/
public function registerProvider($mimeTypeRegex, \Closure $callable): void {
if (!$this->config->getSystemValueBool('enable_previews', true)) {
if (!$this->enablePreviews) {
return;
}

Expand All @@ -101,7 +103,7 @@ public function registerProvider($mimeTypeRegex, \Closure $callable): void {
* Get all providers
*/
public function getProviders(): array {
if (!$this->config->getSystemValueBool('enable_previews', true)) {
if (!$this->enablePreviews) {
return [];
}

Expand Down Expand Up @@ -158,6 +160,7 @@ private function getGenerator(): Generator {
* @since 11.0.0 - \InvalidArgumentException was added in 12.0.0
*/
public function getPreview(File $file, $width = -1, $height = -1, $crop = false, $mode = IPreview::MODE_FILL, $mimeType = null) {
$this->throwIfPreviewsDisabled();
$previewConcurrency = $this->getGenerator()->getNumConcurrentPreviews('preview_concurrency_all');
$sem = Generator::guardWithSemaphore(Generator::SEMAPHORE_ID_ALL, $previewConcurrency);
try {
Expand All @@ -181,6 +184,7 @@ public function getPreview(File $file, $width = -1, $height = -1, $crop = false,
* @since 19.0.0
*/
public function generatePreviews(File $file, array $specifications, $mimeType = null) {
$this->throwIfPreviewsDisabled();
return $this->getGenerator()->generatePreviews($file, $specifications, $mimeType);
}

Expand All @@ -191,7 +195,7 @@ public function generatePreviews(File $file, array $specifications, $mimeType =
* @return boolean
*/
public function isMimeSupported($mimeType = '*') {
if (!$this->config->getSystemValueBool('enable_previews', true)) {
if (!$this->enablePreviews) {
return false;
}

Expand All @@ -216,7 +220,7 @@ public function isMimeSupported($mimeType = '*') {
* Check if a preview can be generated for a file
*/
public function isAvailable(\OCP\Files\FileInfo $file): bool {
if (!$this->config->getSystemValueBool('enable_previews', true)) {
if (!$this->enablePreviews) {
return false;
}

Expand Down Expand Up @@ -452,4 +456,13 @@ private function registerBootstrapProviders(): void {
});
}
}

/**
* @throws NotFoundException if preview generation is disabled
*/
private function throwIfPreviewsDisabled(): void {
if (!$this->enablePreviews) {
throw new NotFoundException('Previews disabled');
}
}
}
Loading