Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't persist previews used during blurhash generation - take 2 #46864

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions lib/private/Blurhash/Listener/GenerateBlurhashMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
use OCP\EventDispatcher\IEventDispatcher;
use OCP\EventDispatcher\IEventListener;
use OCP\Files\GenericFileException;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\FilesMetadata\AMetadataEvent;
use OCP\FilesMetadata\Event\MetadataBackgroundEvent;
use OCP\FilesMetadata\Event\MetadataLiveEvent;
use OCP\IPreview;
use OCP\Lock\LockedException;

/**
Expand All @@ -34,11 +32,6 @@ class GenerateBlurhashMetadata implements IEventListener {
private const COMPONENTS_X = 4;
private const COMPONENTS_Y = 3;

public function __construct(
private IPreview $preview,
) {
}

/**
* @throws NotPermittedException
* @throws GenericFileException
Expand Down Expand Up @@ -67,20 +60,12 @@ public function handle(Event $event): void {
return;
}

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

if ($image === false) {
$image = $this->resizedImageFromFile($file);
if (!$image) {
return;
}

Expand Down
Loading