diff options
author | Richard Steinmetz <richard@steinmetz.cloud> | 2022-11-08 19:44:29 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-08 19:44:29 +0300 |
commit | 0d12f68a0a19896932879e865cfe3e9102311f0c (patch) | |
tree | 2e951d6b209f69c642ac215100204b5abdb010db | |
parent | 002dd7f9d1ed04d81c92e012ff90a4f6e18a5b9c (diff) | |
parent | c422698fbcd0e1c2f3638ef54a9036888a6275f2 (diff) |
Merge pull request #320 from nextcloud/enh/noid/generate-specifications-once
Generate preview specifications once
-rw-r--r-- | lib/Command/Generate.php | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/lib/Command/Generate.php b/lib/Command/Generate.php index f3404c9..e153b87 100644 --- a/lib/Command/Generate.php +++ b/lib/Command/Generate.php @@ -52,8 +52,7 @@ class Generate extends Command { /** @var ?GlobalStoragesService */ protected $globalService; - /** @var int[][] */ - protected array $sizes; + protected array $specifications; protected IUserManager $userManager; protected IRootFolder $rootFolder; @@ -110,7 +109,19 @@ class Generate extends Command { $output->setFormatter($formatter); $this->output = $output; - $this->sizes = SizeHelper::calculateSizes($this->config); + // Generate preview specifications once + $sizes = SizeHelper::calculateSizes($this->config); + $this->specifications = array_merge( + array_map(static function ($squareSize) { + return ['width' => $squareSize, 'height' => $squareSize, 'crop' => true]; + }, $sizes['square']), + array_map(static function ($heightSize) { + return ['width' => -1, 'height' => $heightSize, 'crop' => false]; + }, $sizes['height']), + array_map(static function ($widthSize) { + return ['width' => $widthSize, 'height' => -1, 'crop' => false]; + }, $sizes['width']) + ); $inputPaths = $input->getOption('path'); if ($inputPaths) { @@ -220,18 +231,7 @@ class Generate extends Command { } try { - $specifications = array_merge( - array_map(function ($squareSize) { - return ['width' => $squareSize, 'height' => $squareSize, 'crop' => true]; - }, $this->sizes['square']), - array_map(function ($heightSize) { - return ['width' => -1, 'height' => $heightSize, 'crop' => false]; - }, $this->sizes['height']), - array_map(function ($widthSize) { - return ['width' => $widthSize, 'height' => -1, 'crop' => false]; - }, $this->sizes['width']) - ); - $this->previewGenerator->generatePreviews($file, $specifications); + $this->previewGenerator->generatePreviews($file, $this->specifications); } catch (NotFoundException $e) { // Maybe log that previews could not be generated? } catch (\InvalidArgumentException $e) { |