From 506ea05d8b186ace4f5a72c107898465b01258c4 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Mon, 24 Oct 2022 17:47:25 -0700 Subject: [PATCH] Add preview generator check to write --- lib/Command/Index.php | 19 +++++++++++++++---- lib/Controller/ApiController.php | 8 ++++---- lib/Db/TimelineWrite.php | 10 +++++++++- lib/Listeners/PostDeleteListener.php | 5 +++-- lib/Listeners/PostWriteListener.php | 6 ++++-- 5 files changed, 35 insertions(+), 13 deletions(-) diff --git a/lib/Command/Index.php b/lib/Command/Index.php index fe659413..d391855b 100644 --- a/lib/Command/Index.php +++ b/lib/Command/Index.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace OCA\Memories\Command; use OCA\Files_External\Service\GlobalStoragesService; +use OCA\Memories\AppInfo\Application; use OCA\Memories\Db\TimelineWrite; use OCP\Encryption\IManager; use OCP\Files\File; @@ -52,7 +53,7 @@ class Index extends Command protected IUserManager $userManager; protected IRootFolder $rootFolder; - protected IPreview $previewGenerator; + protected IPreview $preview; protected IConfig $config; protected OutputInterface $output; protected IManager $encryptionManager; @@ -67,7 +68,7 @@ class Index extends Command public function __construct( IRootFolder $rootFolder, IUserManager $userManager, - IPreview $previewGenerator, + IPreview $preview, IConfig $config, IManager $encryptionManager, IDBConnection $connection, @@ -77,11 +78,11 @@ class Index extends Command $this->userManager = $userManager; $this->rootFolder = $rootFolder; - $this->previewGenerator = $previewGenerator; + $this->preview = $preview; $this->config = $config; $this->encryptionManager = $encryptionManager; $this->connection = $connection; - $this->timelineWrite = new TimelineWrite($this->connection); + $this->timelineWrite = new TimelineWrite($connection, $preview); try { $this->globalService = $container->get(GlobalStoragesService::class); @@ -112,6 +113,16 @@ class Index extends Command protected function execute(InputInterface $input, OutputInterface $output): int { + // Print mime type support information + $output->writeln('MIME Type support:'); + foreach (Application::IMAGE_MIMES as $mimeType) { + if ($this->preview->isMimeSupported($mimeType)) { + $output->writeln(" {$mimeType}: supported"); + } else { + $output->writeln(" {$mimeType}: not supported by preview generator"); + } + } + // Get options and arguments $refresh = $input->getOption('refresh') ? true : false; $clear = $input->getOption('clear') ? true : false; diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index 0bdbd28d..9d9513e4 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -53,7 +53,7 @@ class ApiController extends Controller private IAppManager $appManager; private TimelineQuery $timelineQuery; private TimelineWrite $timelineWrite; - private IPreview $previewManager; + private IPreview $preview; public function __construct( IRequest $request, @@ -62,7 +62,7 @@ class ApiController extends Controller IDBConnection $connection, IRootFolder $rootFolder, IAppManager $appManager, - IPreview $previewManager + IPreview $preview ) { parent::__construct(Application::APPNAME, $request); @@ -71,9 +71,9 @@ class ApiController extends Controller $this->connection = $connection; $this->rootFolder = $rootFolder; $this->appManager = $appManager; - $this->previewManager = $previewManager; + $this->previewManager = $preview; $this->timelineQuery = new TimelineQuery($this->connection); - $this->timelineWrite = new TimelineWrite($connection); + $this->timelineWrite = new TimelineWrite($connection, $preview); } /** diff --git a/lib/Db/TimelineWrite.php b/lib/Db/TimelineWrite.php index d6b050f7..5377ecdd 100644 --- a/lib/Db/TimelineWrite.php +++ b/lib/Db/TimelineWrite.php @@ -9,14 +9,17 @@ use OCA\Memories\Exif; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\Files\File; use OCP\IDBConnection; +use OCP\IPreview; class TimelineWrite { protected IDBConnection $connection; + protected IPreview $preview; - public function __construct(IDBConnection $connection) + public function __construct(IDBConnection $connection, IPreview &$preview) { $this->connection = $connection; + $this->preview = $preview; } /** @@ -58,6 +61,11 @@ class TimelineWrite return 0; } + // Make sure preview generator supports the mime type + if (!$this->preview->isMimeSupported($file->getMimeType())) { + return 0; + } + // Get parameters $mtime = $file->getMtime(); $fileId = $file->getId(); diff --git a/lib/Listeners/PostDeleteListener.php b/lib/Listeners/PostDeleteListener.php index 065682da..dd223214 100644 --- a/lib/Listeners/PostDeleteListener.php +++ b/lib/Listeners/PostDeleteListener.php @@ -27,14 +27,15 @@ use OCP\EventDispatcher\IEventListener; use OCP\Files\Events\Node\NodeDeletedEvent; use OCP\Files\Folder; use OCP\IDBConnection; +use OCP\IPreview; class PostDeleteListener implements IEventListener { private TimelineWrite $util; - public function __construct(IDBConnection $connection) + public function __construct(IDBConnection $connection, IPreview $preview) { - $this->util = new TimelineWrite($connection); + $this->util = new TimelineWrite($connection, $preview); } public function handle(Event $event): void diff --git a/lib/Listeners/PostWriteListener.php b/lib/Listeners/PostWriteListener.php index 30c69564..a4e24f31 100644 --- a/lib/Listeners/PostWriteListener.php +++ b/lib/Listeners/PostWriteListener.php @@ -28,6 +28,7 @@ use OCP\Files\Events\Node\NodeTouchedEvent; use OCP\Files\Events\Node\NodeWrittenEvent; use OCP\Files\Folder; use OCP\IDBConnection; +use OCP\IPreview; use OCP\IUserManager; class PostWriteListener implements IEventListener @@ -36,10 +37,11 @@ class PostWriteListener implements IEventListener public function __construct( IDBConnection $connection, - IUserManager $userManager + IUserManager $userManager, + IPreview $preview ) { $this->userManager = $userManager; - $this->timelineWrite = new TimelineWrite($connection); + $this->timelineWrite = new TimelineWrite($connection, $preview); } public function handle(Event $event): void