Browse Source

feat: Add mimetype into BeforePreviewFetchedEvent event

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
pull/47865/head
Thomas Citharel 3 years ago
committed by Côme Chilliet
parent
commit
c2150bd079
No known key found for this signature in database GPG Key ID: A3E2F658B28C760A
  1. 1
      lib/private/Preview/Generator.php
  2. 17
      lib/public/Preview/BeforePreviewFetchedEvent.php
  3. 12
      tests/lib/Preview/GeneratorTest.php

1
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

17
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;
}
}

12
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) {

Loading…
Cancel
Save