Skip to content

Commit 08c785f

Browse files
committed
fix: don't persist previews used during blurhash generation
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
1 parent c882d78 commit 08c785f

1 file changed

Lines changed: 4 additions & 19 deletions

File tree

lib/private/Blurhash/Listener/GenerateBlurhashMetadata.php

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@
1515
use OCP\EventDispatcher\IEventDispatcher;
1616
use OCP\EventDispatcher\IEventListener;
1717
use OCP\Files\GenericFileException;
18-
use OCP\Files\NotFoundException;
1918
use OCP\Files\NotPermittedException;
2019
use OCP\FilesMetadata\AMetadataEvent;
2120
use OCP\FilesMetadata\Event\MetadataBackgroundEvent;
2221
use OCP\FilesMetadata\Event\MetadataLiveEvent;
23-
use OCP\IPreview;
2422
use OCP\Lock\LockedException;
2523

2624
/**
@@ -34,11 +32,6 @@ class GenerateBlurhashMetadata implements IEventListener {
3432
private const COMPONENTS_X = 4;
3533
private const COMPONENTS_Y = 3;
3634

37-
public function __construct(
38-
private IPreview $preview,
39-
) {
40-
}
41-
4235
/**
4336
* @throws NotPermittedException
4437
* @throws GenericFileException
@@ -67,20 +60,12 @@ public function handle(Event $event): void {
6760
return;
6861
}
6962

70-
$image = false;
71-
try {
72-
// using preview image to generate the blurhash
73-
$preview = $this->preview->getPreview($file, 256, 256);
74-
$image = @imagecreatefromstring($preview->getContent());
75-
} catch (NotFoundException $e) {
76-
// https://github.com/nextcloud/server/blob/9d70fd3e64b60a316a03fb2b237891380c310c58/lib/private/legacy/OC_Image.php#L668
77-
// The preview system can fail on huge picture, in that case we use our own image resizer.
78-
if (str_starts_with($file->getMimetype(), 'image/')) {
79-
$image = $this->resizedImageFromFile($file);
80-
}
63+
if (!str_starts_with($file->getMimetype(), 'image/')) {
64+
return;
8165
}
8266

83-
if ($image === false) {
67+
$image = $this->resizedImageFromFile($file);
68+
if (!$image) {
8469
return;
8570
}
8671

0 commit comments

Comments
 (0)