Skip to content

Commit

Permalink
Merge pull request nextcloud#50009 from nextcloud/jtr/preview-thumb-r…
Browse files Browse the repository at this point in the history
…obustness

fix(previews): Make thumbnail generation a bit more robust
  • Loading branch information
nickvergessen authored Jan 3, 2025
2 parents 5058ec4 + 37a9460 commit 9e18d34
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/private/Preview/HEIC.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use OCP\Files\File;
use OCP\Files\FileInfo;
use OCP\IImage;
use OCP\Server;
use Psr\Log\LoggerInterface;

/**
Expand Down Expand Up @@ -44,8 +45,8 @@ public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {

$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;
Expand Down
9 changes: 9 additions & 0 deletions lib/private/Preview/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

use OCP\Files\File;
use OCP\IImage;
use OCP\Server;
use Psr\Log\LoggerInterface;

abstract class Image extends ProviderV2 {
/**
Expand All @@ -25,6 +27,13 @@ public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
$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();
Expand Down
9 changes: 9 additions & 0 deletions lib/private/Preview/MP3.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

use OCP\Files\File;
use OCP\IImage;
use OCP\Server;
use Psr\Log\LoggerInterface;
use wapmorgan\Mp3Info\Mp3Info;
use function OCP\Log\logger;

Expand All @@ -25,6 +27,13 @@ public function getMimeType(): string {
*/
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);
Expand Down
8 changes: 8 additions & 0 deletions lib/private/Preview/Movie.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use OCP\Files\File;
use OCP\Files\FileInfo;
use OCP\IImage;
use OCP\Server;
use Psr\Log\LoggerInterface;

class Movie extends ProviderV2 {
Expand Down Expand Up @@ -75,6 +76,13 @@ public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {

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)) {
Expand Down
8 changes: 8 additions & 0 deletions lib/private/Preview/Office.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use OCP\IImage;
use OCP\ITempManager;
use OCP\Server;
use Psr\Log\LoggerInterface;

abstract class Office extends ProviderV2 {
/**
Expand All @@ -33,6 +34,13 @@ public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {

// 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.
Expand Down

0 comments on commit 9e18d34

Please sign in to comment.