Merge pull request #50009 from nextcloud/jtr/preview-thumb-robustness

fix(previews): Make thumbnail generation a bit more robust
pull/50026/head
Joas Schilling 1 year ago committed by GitHub
commit 9e18d3402c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      lib/private/Preview/HEIC.php
  2. 9
      lib/private/Preview/Image.php
  3. 9
      lib/private/Preview/MP3.php
  4. 8
      lib/private/Preview/Movie.php
  5. 8
      lib/private/Preview/Office.php

@ -12,6 +12,7 @@ namespace OC\Preview;
use OCP\Files\File;
use OCP\Files\FileInfo;
use OCP\IImage;
use OCP\Server;
use Psr\Log\LoggerInterface;
/**
@ -44,8 +45,8 @@ class HEIC extends ProviderV2 {
$tmpPath = $this->getLocalFile($file);
if ($tmpPath === false) {
\OC::$server->get(LoggerInterface::class)->error(
'Failed to get thumbnail for: ' . $file->getPath(),
Server::get(LoggerInterface::class)->error(
'Failed to get local file to generate thumbnail for: ' . $file->getPath(),
['app' => 'core']
);
return null;

@ -9,6 +9,8 @@ namespace OC\Preview;
use OCP\Files\File;
use OCP\IImage;
use OCP\Server;
use Psr\Log\LoggerInterface;
abstract class Image extends ProviderV2 {
/**
@ -25,6 +27,13 @@ abstract class Image extends ProviderV2 {
$image = new \OCP\Image();
$fileName = $this->getLocalFile($file);
if ($fileName === false) {
Server::get(LoggerInterface::class)->error(
'Failed to get local file to generate thumbnail for: ' . $file->getPath(),
['app' => 'core']
);
return null;
}
$image->loadFromFile($fileName);
$image->fixOrientation();

@ -9,6 +9,8 @@ namespace OC\Preview;
use OCP\Files\File;
use OCP\IImage;
use OCP\Server;
use Psr\Log\LoggerInterface;
use wapmorgan\Mp3Info\Mp3Info;
use function OCP\Log\logger;
@ -25,6 +27,13 @@ class MP3 extends ProviderV2 {
*/
public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
$tmpPath = $this->getLocalFile($file);
if ($tmpPath === false) {
Server::get(LoggerInterface::class)->error(
'Failed to get local file to generate thumbnail for: ' . $file->getPath(),
['app' => 'core']
);
return null;
}
try {
$audio = new Mp3Info($tmpPath, true);

@ -10,6 +10,7 @@ namespace OC\Preview;
use OCP\Files\File;
use OCP\Files\FileInfo;
use OCP\IImage;
use OCP\Server;
use Psr\Log\LoggerInterface;
class Movie extends ProviderV2 {
@ -75,6 +76,13 @@ class Movie extends ProviderV2 {
foreach ($sizeAttempts as $size) {
$absPath = $this->getLocalFile($file, $size);
if ($absPath === false) {
Server::get(LoggerInterface::class)->error(
'Failed to get local file to generate thumbnail for: ' . $file->getPath(),
['app' => 'core']
);
return null;
}
$result = null;
if (is_string($absPath)) {

@ -12,6 +12,7 @@ use OCP\Files\FileInfo;
use OCP\IImage;
use OCP\ITempManager;
use OCP\Server;
use Psr\Log\LoggerInterface;
abstract class Office extends ProviderV2 {
/**
@ -33,6 +34,13 @@ abstract class Office extends ProviderV2 {
// The file to generate the preview for.
$absPath = $this->getLocalFile($file);
if ($absPath === false) {
Server::get(LoggerInterface::class)->error(
'Failed to get local file to generate thumbnail for: ' . $file->getPath(),
['app' => 'core']
);
return null;
}
// The destination for the LibreOffice user profile.
// LibreOffice can rune once per user profile and therefore instance id and file id are included.

Loading…
Cancel
Save