Skip to content

Commit 82bd502

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

File tree

1 file changed

+2
-21
lines changed

1 file changed

+2
-21
lines changed

lib/private/Blurhash/Listener/GenerateBlurhashMetadata.php

Lines changed: 2 additions & 21 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,23 +60,11 @@ 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-
}
81-
}
82-
83-
if ($image === false) {
63+
if (!str_starts_with($file->getMimetype(), 'image/')) {
8464
return;
8565
}
8666

67+
$image = $this->resizedImageFromFile($file);
8768
$metadata->setString('blurhash', $this->generateBlurHash($image))
8869
->setEtag('blurhash', $currentEtag);
8970
}

0 commit comments

Comments
 (0)