Add preview generator check to write

old-stable24
Varun Patil 2022-10-24 17:47:25 -07:00
parent 69184e0bb0
commit 506ea05d8b
5 changed files with 35 additions and 13 deletions

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace OCA\Memories\Command; namespace OCA\Memories\Command;
use OCA\Files_External\Service\GlobalStoragesService; use OCA\Files_External\Service\GlobalStoragesService;
use OCA\Memories\AppInfo\Application;
use OCA\Memories\Db\TimelineWrite; use OCA\Memories\Db\TimelineWrite;
use OCP\Encryption\IManager; use OCP\Encryption\IManager;
use OCP\Files\File; use OCP\Files\File;
@ -52,7 +53,7 @@ class Index extends Command
protected IUserManager $userManager; protected IUserManager $userManager;
protected IRootFolder $rootFolder; protected IRootFolder $rootFolder;
protected IPreview $previewGenerator; protected IPreview $preview;
protected IConfig $config; protected IConfig $config;
protected OutputInterface $output; protected OutputInterface $output;
protected IManager $encryptionManager; protected IManager $encryptionManager;
@ -67,7 +68,7 @@ class Index extends Command
public function __construct( public function __construct(
IRootFolder $rootFolder, IRootFolder $rootFolder,
IUserManager $userManager, IUserManager $userManager,
IPreview $previewGenerator, IPreview $preview,
IConfig $config, IConfig $config,
IManager $encryptionManager, IManager $encryptionManager,
IDBConnection $connection, IDBConnection $connection,
@ -77,11 +78,11 @@ class Index extends Command
$this->userManager = $userManager; $this->userManager = $userManager;
$this->rootFolder = $rootFolder; $this->rootFolder = $rootFolder;
$this->previewGenerator = $previewGenerator; $this->preview = $preview;
$this->config = $config; $this->config = $config;
$this->encryptionManager = $encryptionManager; $this->encryptionManager = $encryptionManager;
$this->connection = $connection; $this->connection = $connection;
$this->timelineWrite = new TimelineWrite($this->connection); $this->timelineWrite = new TimelineWrite($connection, $preview);
try { try {
$this->globalService = $container->get(GlobalStoragesService::class); $this->globalService = $container->get(GlobalStoragesService::class);
@ -112,6 +113,16 @@ class Index extends Command
protected function execute(InputInterface $input, OutputInterface $output): int 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}: <error>not supported by preview generator</error>");
}
}
// Get options and arguments // Get options and arguments
$refresh = $input->getOption('refresh') ? true : false; $refresh = $input->getOption('refresh') ? true : false;
$clear = $input->getOption('clear') ? true : false; $clear = $input->getOption('clear') ? true : false;

View File

@ -53,7 +53,7 @@ class ApiController extends Controller
private IAppManager $appManager; private IAppManager $appManager;
private TimelineQuery $timelineQuery; private TimelineQuery $timelineQuery;
private TimelineWrite $timelineWrite; private TimelineWrite $timelineWrite;
private IPreview $previewManager; private IPreview $preview;
public function __construct( public function __construct(
IRequest $request, IRequest $request,
@ -62,7 +62,7 @@ class ApiController extends Controller
IDBConnection $connection, IDBConnection $connection,
IRootFolder $rootFolder, IRootFolder $rootFolder,
IAppManager $appManager, IAppManager $appManager,
IPreview $previewManager IPreview $preview
) { ) {
parent::__construct(Application::APPNAME, $request); parent::__construct(Application::APPNAME, $request);
@ -71,9 +71,9 @@ class ApiController extends Controller
$this->connection = $connection; $this->connection = $connection;
$this->rootFolder = $rootFolder; $this->rootFolder = $rootFolder;
$this->appManager = $appManager; $this->appManager = $appManager;
$this->previewManager = $previewManager; $this->previewManager = $preview;
$this->timelineQuery = new TimelineQuery($this->connection); $this->timelineQuery = new TimelineQuery($this->connection);
$this->timelineWrite = new TimelineWrite($connection); $this->timelineWrite = new TimelineWrite($connection, $preview);
} }
/** /**

View File

@ -9,14 +9,17 @@ use OCA\Memories\Exif;
use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Files\File; use OCP\Files\File;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\IPreview;
class TimelineWrite class TimelineWrite
{ {
protected IDBConnection $connection; protected IDBConnection $connection;
protected IPreview $preview;
public function __construct(IDBConnection $connection) public function __construct(IDBConnection $connection, IPreview &$preview)
{ {
$this->connection = $connection; $this->connection = $connection;
$this->preview = $preview;
} }
/** /**
@ -58,6 +61,11 @@ class TimelineWrite
return 0; return 0;
} }
// Make sure preview generator supports the mime type
if (!$this->preview->isMimeSupported($file->getMimeType())) {
return 0;
}
// Get parameters // Get parameters
$mtime = $file->getMtime(); $mtime = $file->getMtime();
$fileId = $file->getId(); $fileId = $file->getId();

View File

@ -27,14 +27,15 @@ use OCP\EventDispatcher\IEventListener;
use OCP\Files\Events\Node\NodeDeletedEvent; use OCP\Files\Events\Node\NodeDeletedEvent;
use OCP\Files\Folder; use OCP\Files\Folder;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\IPreview;
class PostDeleteListener implements IEventListener class PostDeleteListener implements IEventListener
{ {
private TimelineWrite $util; 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 public function handle(Event $event): void

View File

@ -28,6 +28,7 @@ use OCP\Files\Events\Node\NodeTouchedEvent;
use OCP\Files\Events\Node\NodeWrittenEvent; use OCP\Files\Events\Node\NodeWrittenEvent;
use OCP\Files\Folder; use OCP\Files\Folder;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\IPreview;
use OCP\IUserManager; use OCP\IUserManager;
class PostWriteListener implements IEventListener class PostWriteListener implements IEventListener
@ -36,10 +37,11 @@ class PostWriteListener implements IEventListener
public function __construct( public function __construct(
IDBConnection $connection, IDBConnection $connection,
IUserManager $userManager IUserManager $userManager,
IPreview $preview
) { ) {
$this->userManager = $userManager; $this->userManager = $userManager;
$this->timelineWrite = new TimelineWrite($connection); $this->timelineWrite = new TimelineWrite($connection, $preview);
} }
public function handle(Event $event): void public function handle(Event $event): void