Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/previewgenerator.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Steinmetz <richard@steinmetz.cloud>2022-11-08 19:54:23 +0300
committerGitHub <noreply@github.com>2022-11-08 19:54:23 +0300
commitf44be1192418519ebcf77b59d2958d3d0aa59767 (patch)
tree4b1faa4c32df5a89e7eb22ed1fa67a64b5447c3c
parentd5590828cdf767c7e0b5a2133ff6970c618d8080 (diff)
parentebde24cd795b8d1e0caaa1d56f5bd7b11b7b910c (diff)
Merge pull request #321 from nextcloud/backport/320/stable5.1
[stable5.1] Generate preview specifications once
-rw-r--r--lib/Command/Generate.php30
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) {