From 2667e43de13c0eb542eedebe26af3276c0e388cd Mon Sep 17 00:00:00 2001 From: Louis Chemineau Date: Tue, 9 Jan 2024 16:26:51 +0100 Subject: [PATCH] Request background event to generate metadata on non-local files Signed-off-by: Louis Chemineau --- lib/AppInfo/Application.php | 3 +++ lib/Listener/ExifMetadataProvider.php | 8 +++++++- lib/Listener/OriginalDateTimeMetadataProvider.php | 8 +++++++- lib/Listener/SizeMetadataProvider.php | 8 +++++++- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 4bcae701c..36d4c8bc2 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -91,8 +91,11 @@ public function register(IRegistrationContext $context): void { // Metadata $context->registerEventListener(MetadataLiveEvent::class, ExifMetadataProvider::class); + $context->registerEventListener(MetadataBackgroundEvent::class, ExifMetadataProvider::class); $context->registerEventListener(MetadataLiveEvent::class, SizeMetadataProvider::class); + $context->registerEventListener(MetadataBackgroundEvent::class, SizeMetadataProvider::class); $context->registerEventListener(MetadataLiveEvent::class, OriginalDateTimeMetadataProvider::class); + $context->registerEventListener(MetadataBackgroundEvent::class, OriginalDateTimeMetadataProvider::class); $context->registerEventListener(MetadataLiveEvent::class, PlaceMetadataProvider::class); $context->registerEventListener(MetadataBackgroundEvent::class, PlaceMetadataProvider::class); diff --git a/lib/Listener/ExifMetadataProvider.php b/lib/Listener/ExifMetadataProvider.php index 2acfbdfc6..1bab20015 100644 --- a/lib/Listener/ExifMetadataProvider.php +++ b/lib/Listener/ExifMetadataProvider.php @@ -26,6 +26,7 @@ use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; use OCP\Files\File; +use OCP\FilesMetadata\Event\MetadataBackgroundEvent; use OCP\FilesMetadata\Event\MetadataLiveEvent; use Psr\Log\LoggerInterface; @@ -42,7 +43,7 @@ public function __construct( } public function handle(Event $event): void { - if (!($event instanceof MetadataLiveEvent)) { + if (!($event instanceof MetadataLiveEvent) && !($event instanceof MetadataBackgroundEvent)) { return; } @@ -52,6 +53,11 @@ public function handle(Event $event): void { return; } + if ($node->getStorage()->isLocal() && $event instanceof MetadataLiveEvent) { + $event->requestBackgroundJob(); + return; + } + if (!in_array($node->getMimeType(), Application::IMAGE_MIMES)) { return; } diff --git a/lib/Listener/OriginalDateTimeMetadataProvider.php b/lib/Listener/OriginalDateTimeMetadataProvider.php index fdc8f9485..282a87920 100644 --- a/lib/Listener/OriginalDateTimeMetadataProvider.php +++ b/lib/Listener/OriginalDateTimeMetadataProvider.php @@ -27,6 +27,7 @@ use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; use OCP\Files\File; +use OCP\FilesMetadata\Event\MetadataBackgroundEvent; use OCP\FilesMetadata\Event\MetadataLiveEvent; use Psr\Log\LoggerInterface; @@ -68,7 +69,7 @@ private function dateToTimestamp(string $format, string $date, File $node): int| } public function handle(Event $event): void { - if (!($event instanceof MetadataLiveEvent)) { + if (!($event instanceof MetadataLiveEvent) && !($event instanceof MetadataBackgroundEvent)) { return; } @@ -78,6 +79,11 @@ public function handle(Event $event): void { return; } + if ($node->getStorage()->isLocal() && $event instanceof MetadataLiveEvent) { + $event->requestBackgroundJob(); + return; + } + if (!in_array($node->getMimeType(), Application::IMAGE_MIMES) && !in_array($node->getMimeType(), Application::VIDEO_MIMES)) { return; } diff --git a/lib/Listener/SizeMetadataProvider.php b/lib/Listener/SizeMetadataProvider.php index 0a78b598a..109c1e5ec 100644 --- a/lib/Listener/SizeMetadataProvider.php +++ b/lib/Listener/SizeMetadataProvider.php @@ -26,6 +26,7 @@ use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; use OCP\Files\File; +use OCP\FilesMetadata\Event\MetadataBackgroundEvent; use OCP\FilesMetadata\Event\MetadataLiveEvent; use Psr\Log\LoggerInterface; @@ -39,7 +40,7 @@ public function __construct( } public function handle(Event $event): void { - if (!($event instanceof MetadataLiveEvent)) { + if (!($event instanceof MetadataLiveEvent) && !($event instanceof MetadataBackgroundEvent)) { return; } @@ -49,6 +50,11 @@ public function handle(Event $event): void { return; } + if ($node->getStorage()->isLocal() && $event instanceof MetadataLiveEvent) { + $event->requestBackgroundJob(); + return; + } + if (!in_array($node->getMimeType(), Application::IMAGE_MIMES)) { return; }