Skip to content

Commit

Permalink
chore(Previews): make thumbnail generation more robust
Browse files Browse the repository at this point in the history
Signed-off-by: Josh <[email protected]>
  • Loading branch information
joshtrichards authored and kesselb committed Jan 2, 2025
1 parent 371b18a commit ef00e96
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/private/Preview/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

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

abstract class Image extends ProviderV2 {
/**
Expand All @@ -25,6 +26,13 @@ public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
$image = new \OCP\Image();

$fileName = $this->getLocalFile($file);
if ($fileName === false) {
\OCP\Server::get(LoggerInterface::class)->error(
'Failed to get thumbnail for: ' . $file->getPath(),
['app' => 'core']
);
return null;
}

$image->loadFromFile($fileName);
$image->fixOrientation();
Expand Down
8 changes: 8 additions & 0 deletions lib/private/Preview/MP3.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

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

Expand All @@ -25,6 +26,13 @@ public function getMimeType(): string {
*/
public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
$tmpPath = $this->getLocalFile($file);
if ($tmpPath === false) {
\OCP\Server::get(LoggerInterface::class)->error(
'Failed to get thumbnail for: ' . $file->getPath(),
['app' => 'core']
);
return null;
}

try {
$audio = new Mp3Info($tmpPath, true);
Expand Down
7 changes: 7 additions & 0 deletions lib/private/Preview/Movie.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {

foreach ($sizeAttempts as $size) {
$absPath = $this->getLocalFile($file, $size);
if ($absPath === false) {
\OCP\Server::get(LoggerInterface::class)->error(
'Failed to get 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) {
\OCP\Server::get(LoggerInterface::class)->error(
'Failed to get 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 ef00e96

Please sign in to comment.