From c2150bd0795ba05e1ec94734b12350f544b08ad4 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 13 Mar 2023 09:58:31 +0100 Subject: [PATCH] feat: Add mimetype into BeforePreviewFetchedEvent event Signed-off-by: Thomas Citharel --- lib/private/Preview/Generator.php | 1 + .../Preview/BeforePreviewFetchedEvent.php | 17 +++++++++++++---- tests/lib/Preview/GeneratorTest.php | 12 ++++++------ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/private/Preview/Generator.php b/lib/private/Preview/Generator.php index 460637c9a99..c7eb3121825 100644 --- a/lib/private/Preview/Generator.php +++ b/lib/private/Preview/Generator.php @@ -80,6 +80,7 @@ class Generator { $height, $crop, $mode, + $mimeType, )); // since we only ask for one preview, and the generate method return the last one it created, it returns the one we want diff --git a/lib/public/Preview/BeforePreviewFetchedEvent.php b/lib/public/Preview/BeforePreviewFetchedEvent.php index 398358d5905..6aed6bcc704 100644 --- a/lib/public/Preview/BeforePreviewFetchedEvent.php +++ b/lib/public/Preview/BeforePreviewFetchedEvent.php @@ -17,6 +17,7 @@ use OCP\IPreview; * * @since 25.0.1 * @since 28.0.0 the constructor arguments ``$width``, ``$height``, ``$crop`` and ``$mode`` are no longer nullable. + * @since 31.0.0 the constructor arguments ``$mimeType`` was added */ class BeforePreviewFetchedEvent extends \OCP\EventDispatcher\Event { /** @@ -24,14 +25,15 @@ class BeforePreviewFetchedEvent extends \OCP\EventDispatcher\Event { */ public function __construct( private Node $node, - /** @deprecated 28.0.0 null deprecated **/ + /** @deprecated 28.0.0 passing null is deprecated **/ private ?int $width = null, - /** @deprecated 28.0.0 null deprecated **/ + /** @deprecated 28.0.0 passing null is null deprecated **/ private ?int $height = null, - /** @deprecated 28.0.0 null deprecated **/ + /** @deprecated 28.0.0 passing null is null deprecated **/ private ?bool $crop = null, - /** @deprecated 28.0.0 null deprecated **/ + /** @deprecated 28.0.0 passing null is null deprecated **/ private ?string $mode = null, + private ?string $mimeType = null, ) { parent::__construct(); } @@ -71,4 +73,11 @@ class BeforePreviewFetchedEvent extends \OCP\EventDispatcher\Event { public function getMode(): ?string { return $this->mode; } + + /** + * @since 31.0.0 + */ + public function getMimeType(): ?string { + return $this->mimeType; + } } diff --git a/tests/lib/Preview/GeneratorTest.php b/tests/lib/Preview/GeneratorTest.php index caac15c3532..d458062f561 100644 --- a/tests/lib/Preview/GeneratorTest.php +++ b/tests/lib/Preview/GeneratorTest.php @@ -91,7 +91,7 @@ class GeneratorTest extends \Test\TestCase { $this->eventDispatcher->expects($this->once()) ->method('dispatchTyped') - ->with(new BeforePreviewFetchedEvent($file, 100, 100, false, IPreview::MODE_FILL)); + ->with(new BeforePreviewFetchedEvent($file, 100, 100, false, IPreview::MODE_FILL, null)); $result = $this->generator->getPreview($file, 100, 100); $this->assertSame($previewFile, $result); @@ -219,7 +219,7 @@ class GeneratorTest extends \Test\TestCase { $this->eventDispatcher->expects($this->once()) ->method('dispatchTyped') - ->with(new BeforePreviewFetchedEvent($file, 100, 100, false, IPreview::MODE_FILL)); + ->with(new BeforePreviewFetchedEvent($file, 100, 100, false, IPreview::MODE_FILL, null)); $result = $this->generator->getPreview($file, 100, 100); $this->assertSame($previewFile, $result); @@ -258,7 +258,7 @@ class GeneratorTest extends \Test\TestCase { $this->eventDispatcher->expects($this->once()) ->method('dispatchTyped') - ->with(new BeforePreviewFetchedEvent($file, 1024, 512, true, IPreview::MODE_COVER)); + ->with(new BeforePreviewFetchedEvent($file, 1024, 512, true, IPreview::MODE_COVER, 'invalidType')); $this->generator->getPreview($file, 1024, 512, true, IPreview::MODE_COVER, 'invalidType'); } @@ -295,7 +295,7 @@ class GeneratorTest extends \Test\TestCase { $this->eventDispatcher->expects($this->once()) ->method('dispatchTyped') - ->with(new BeforePreviewFetchedEvent($file, 1024, 512, true, IPreview::MODE_COVER)); + ->with(new BeforePreviewFetchedEvent($file, 1024, 512, true, IPreview::MODE_COVER, 'invalidType')); $result = $this->generator->getPreview($file, 1024, 512, true, IPreview::MODE_COVER, 'invalidType'); $this->assertSame($preview, $result); @@ -323,7 +323,7 @@ class GeneratorTest extends \Test\TestCase { $this->eventDispatcher->expects($this->once()) ->method('dispatchTyped') - ->with(new BeforePreviewFetchedEvent($file, 100, 100, false, IPreview::MODE_FILL)); + ->with(new BeforePreviewFetchedEvent($file, 100, 100, false, IPreview::MODE_FILL, null)); $this->expectException(NotFoundException::class); $this->generator->getPreview($file, 100, 100); @@ -448,7 +448,7 @@ class GeneratorTest extends \Test\TestCase { $this->eventDispatcher->expects($this->once()) ->method('dispatchTyped') - ->with(new BeforePreviewFetchedEvent($file, $reqX, $reqY, $crop, $mode)); + ->with(new BeforePreviewFetchedEvent($file, $reqX, $reqY, $crop, $mode, null)); $result = $this->generator->getPreview($file, $reqX, $reqY, $crop, $mode); if ($expectedX === $maxX && $expectedY === $maxY) {