aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2023-03-13 09:58:31 +0100
committerCôme Chilliet <come.chilliet@nextcloud.com>2024-09-10 14:05:06 +0200
commitc2150bd0795ba05e1ec94734b12350f544b08ad4 (patch)
treeeaeb1cbd62e10fdfa9c2e6a80be8ff8a110180dc
parent5afe21210344e7596286797a005026188c696288 (diff)
downloadnextcloud-server-c2150bd0795ba05e1ec94734b12350f544b08ad4.tar.gz
nextcloud-server-c2150bd0795ba05e1ec94734b12350f544b08ad4.zip
feat: Add mimetype into BeforePreviewFetchedEvent event
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
-rw-r--r--lib/private/Preview/Generator.php1
-rw-r--r--lib/public/Preview/BeforePreviewFetchedEvent.php17
-rw-r--r--tests/lib/Preview/GeneratorTest.php12
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) {