diff --git a/lib/private/Preview/Generator.php b/lib/private/Preview/Generator.php index 94fea7314b565..a2a330f881c67 100644 --- a/lib/private/Preview/Generator.php +++ b/lib/private/Preview/Generator.php @@ -34,6 +34,9 @@ class Generator { public const SEMAPHORE_ID_ALL = 0x0a11; public const SEMAPHORE_ID_NEW = 0x07ea; + /** The viewer only shows the max preview of images */ + private const MAX_NON_IMAGE_PREVIEW_SIZE = 1024; + private array $cachedNumConcurrentPreviews = []; public function __construct( @@ -327,6 +330,10 @@ private function getMaxPreview(array $previews, File $file, string $mimeType, ?s $maxWidth = $this->config->getSystemValueInt('preview_max_x', 4096); $maxHeight = $this->config->getSystemValueInt('preview_max_y', 4096); + if (!str_starts_with($mimeType, 'image/')) { + $maxWidth = min($maxWidth, self::MAX_NON_IMAGE_PREVIEW_SIZE); + $maxHeight = min($maxHeight, self::MAX_NON_IMAGE_PREVIEW_SIZE); + } try { return $this->generateProviderPreview($file, $maxWidth, $maxHeight, false, true, $mimeType, $version); diff --git a/tests/lib/Preview/GeneratorTest.php b/tests/lib/Preview/GeneratorTest.php index 1b62768ef390d..a32a91a0190dd 100644 --- a/tests/lib/Preview/GeneratorTest.php +++ b/tests/lib/Preview/GeneratorTest.php @@ -483,6 +483,38 @@ public function testCorrectSize(int $maxX, int $maxY, int $reqX, int $reqY, bool } } + #[TestWith(['image/jpeg', 4096])] + #[TestWith(['text/plain', 1024])] + #[TestWith(['application/pdf', 1024])] + public function testMaxPreviewSize(string $mimeType, int $expectedSize): void { + $file = $this->getFile(42, $mimeType); + + $this->getAutoMock(PreviewMapper::class)->method('getAvailablePreviews') + ->willReturn([42 => []]); + $this->getAutoMock(IConfig::class)->method('getSystemValueInt') + ->willReturnCallback(fn ($key, $default) => $default); + + $provider = $this->createMock(IProviderV2::class); + $provider->method('isAvailable')->willReturn(true); + $this->getAutoMock(IPreview::class)->method('getProviders') + ->willReturn(['/.*/' => ['provider']]); + $this->getAutoMock(GeneratorHelper::class)->method('getProvider') + ->willReturn($provider); + + $this->getAutoMock(GeneratorHelper::class)->expects($this->once()) + ->method('getThumbnail') + ->with($provider, $file, $expectedSize, $expectedSize) + ->willReturn($this->getMockImage($expectedSize, $expectedSize, 'my data')); + + $this->getAutoMock(PreviewMapper::class)->method('insert') + ->willReturnCallback(fn (Preview $preview): Preview => $preview); + $this->getAutoMock(StorageFactory::class)->method('writePreview') + ->willReturn(1000); + + $result = $this->generator->getPreview($file); + $this->assertSame("$expectedSize-$expectedSize-max.png", $result->getName()); + } + public function testUnreadbleFile(): void { $file = $this->createMock(File::class); $file->method('isReadable')