Skip to content

Commit

Permalink
Merge pull request #320 from nextcloud/enh/noid/generate-specificatio…
Browse files Browse the repository at this point in the history
…ns-once

Generate preview specifications once
  • Loading branch information
st3iny authored Nov 8, 2022
2 parents 002dd7f + c422698 commit 0d12f68
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions lib/Command/Generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -110,7 +109,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$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) {
Expand Down Expand Up @@ -220,18 +231,7 @@ private function parseFile(File $file): void {
}

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) {
Expand Down

0 comments on commit 0d12f68

Please sign in to comment.