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:
authorRobin Appelman <robin@icewind.nl>2020-02-16 04:38:58 +0300
committerRobin Appelman <robin@icewind.nl>2021-01-05 18:33:51 +0300
commitef0f376466634510e9b7c8793b443878f45b7f59 (patch)
tree81b98ec449cc2660045e7b93392974151806ba9d
parent97d057825f3e69a125d194d2c19a08e1e5d68203 (diff)
use new batch preview generation
-rw-r--r--lib/Command/Generate.php41
-rw-r--r--lib/Command/PreGenerate.php39
2 files changed, 55 insertions, 25 deletions
diff --git a/lib/Command/Generate.php b/lib/Command/Generate.php
index d66a9cb..1f377cc 100644
--- a/lib/Command/Generate.php
+++ b/lib/Command/Generate.php
@@ -110,7 +110,7 @@ class Generate extends Command {
$inputPath = $input->getOption('path');
if ($inputPath) {
$inputPath = '/' . trim($inputPath, '/');
- list(, $userId,) = explode('/', $inputPath, 3);
+ [, $userId,] = explode('/', $inputPath, 3);
$user = $this->userManager->get($userId);
if ($user !== null) {
$this->generatePathPreviews($user, $inputPath);
@@ -181,18 +181,33 @@ class Generate extends Command {
}
try {
- foreach ($this->sizes['square'] as $size) {
- $this->previewGenerator->getPreview($file, $size, $size, true);
- }
-
- // Height previews
- foreach ($this->sizes['height'] as $height) {
- $this->previewGenerator->getPreview($file, -1, $height, false);
- }
-
- // Width previews
- foreach ($this->sizes['width'] as $width) {
- $this->previewGenerator->getPreview($file, $width, -1, false);
+ if (method_exists(IPreview::class, 'generatePreviews')) {
+ $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);
+ } else {
+ foreach ($this->sizes['square'] as $size) {
+ $this->previewGenerator->getPreview($file, $size, $size, true);
+ }
+
+ // Height previews
+ foreach ($this->sizes['height'] as $height) {
+ $this->previewGenerator->getPreview($file, -1, $height, false);
+ }
+
+ // Width previews
+ foreach ($this->sizes['width'] as $width) {
+ $this->previewGenerator->getPreview($file, $width, -1, false);
+ }
}
} catch (NotFoundException $e) {
// Maybe log that previews could not be generated?
diff --git a/lib/Command/PreGenerate.php b/lib/Command/PreGenerate.php
index 52fbcc1..09f4180 100644
--- a/lib/Command/PreGenerate.php
+++ b/lib/Command/PreGenerate.php
@@ -200,18 +200,33 @@ class PreGenerate extends Command {
}
try {
- foreach ($this->sizes['square'] as $size) {
- $this->previewGenerator->getPreview($file, $size, $size, true);
- }
-
- // Height previews
- foreach ($this->sizes['height'] as $height) {
- $this->previewGenerator->getPreview($file, -1, $height, false);
- }
-
- // Width previews
- foreach ($this->sizes['width'] as $width) {
- $this->previewGenerator->getPreview($file, $width, -1, false);
+ if (method_exists(IPreview::class, 'generatePreviews')) {
+ $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);
+ } else {
+ foreach ($this->sizes['square'] as $size) {
+ $this->previewGenerator->getPreview($file, $size, $size, true);
+ }
+
+ // Height previews
+ foreach ($this->sizes['height'] as $height) {
+ $this->previewGenerator->getPreview($file, -1, $height, false);
+ }
+
+ // Width previews
+ foreach ($this->sizes['width'] as $width) {
+ $this->previewGenerator->getPreview($file, $width, -1, false);
+ }
}
} catch (NotFoundException $e) {
// Maybe log that previews could not be generated?