Skip to content
Next Next commit
feat: Add mimetype into BeforePreviewFetchedEvent event
Signed-off-by: Thomas Citharel <[email protected]>
  • Loading branch information
tcitworld authored and come-nc committed Sep 10, 2024
commit c2150bd0795ba05e1ec94734b12350f544b08ad4
1 change: 1 addition & 0 deletions lib/private/Preview/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function getPreview(File $file, $width = -1, $height = -1, $crop = false,
$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
Expand Down
17 changes: 13 additions & 4 deletions lib/public/Preview/BeforePreviewFetchedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@
*
* @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 {
/**
* @since 25.0.1
*/
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();
}
Expand Down Expand Up @@ -71,4 +73,11 @@ public function isCrop(): ?bool {
public function getMode(): ?string {
return $this->mode;
}

/**
* @since 31.0.0
*/
public function getMimeType(): ?string {
return $this->mimeType;
}
}
12 changes: 6 additions & 6 deletions tests/lib/Preview/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function testGetCachedPreview() {

$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);
Expand Down Expand Up @@ -219,7 +219,7 @@ public function testGetNewPreview() {

$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);
Expand Down Expand Up @@ -258,7 +258,7 @@ public function testInvalidMimeType() {

$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');
}
Expand Down Expand Up @@ -295,7 +295,7 @@ public function testReturnCachedPreviewsWithoutCheckingSupportedMimetype() {

$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);
Expand Down Expand Up @@ -323,7 +323,7 @@ public function testNoProvider() {

$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);
Expand Down Expand Up @@ -448,7 +448,7 @@ public function testCorrectSize($maxX, $maxY, $reqX, $reqY, $crop, $mode, $expec

$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) {
Expand Down