Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(previews): Make thumbnail generation a bit more robust #50009

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading