diff options
author | Josh <josh.t.richards@gmail.com> | 2025-01-01 12:29:20 -0500 |
---|---|---|
committer | Daniel Kesselberg <mail@danielkesselberg.de> | 2025-01-02 18:32:44 +0100 |
commit | 37a9460b065b5683ce895a1d4cd819b2749db5d5 (patch) | |
tree | 3ad4fe5170162ca2388e0d0208edba8109cdba04 | |
parent | d4ce30764a7789725371f9978f292c52b3707c66 (diff) | |
download | nextcloud-server-37a9460b065b5683ce895a1d4cd819b2749db5d5.tar.gz nextcloud-server-37a9460b065b5683ce895a1d4cd819b2749db5d5.zip |
chore(Previews): make thumbnail generation more robustjtr/preview-thumb-robustness
Signed-off-by: Josh <josh.t.richards@gmail.com>
-rw-r--r-- | lib/private/Preview/HEIC.php | 5 | ||||
-rw-r--r-- | lib/private/Preview/Image.php | 9 | ||||
-rw-r--r-- | lib/private/Preview/MP3.php | 9 | ||||
-rw-r--r-- | lib/private/Preview/Movie.php | 8 | ||||
-rw-r--r-- | lib/private/Preview/Office.php | 8 |
5 files changed, 37 insertions, 2 deletions
diff --git a/lib/private/Preview/HEIC.php b/lib/private/Preview/HEIC.php index e5d73c943a4..64eb48e58df 100644 --- a/lib/private/Preview/HEIC.php +++ b/lib/private/Preview/HEIC.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; diff --git a/lib/private/Preview/Image.php b/lib/private/Preview/Image.php index 69841f07929..78a402c636a 100644 --- a/lib/private/Preview/Image.php +++ b/lib/private/Preview/Image.php @@ -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(); diff --git a/lib/private/Preview/MP3.php b/lib/private/Preview/MP3.php index 105b182b415..add0028738e 100644 --- a/lib/private/Preview/MP3.php +++ b/lib/private/Preview/MP3.php @@ -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); diff --git a/lib/private/Preview/Movie.php b/lib/private/Preview/Movie.php index 4a6104930d6..ed6a277053b 100644 --- a/lib/private/Preview/Movie.php +++ b/lib/private/Preview/Movie.php @@ -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)) { diff --git a/lib/private/Preview/Office.php b/lib/private/Preview/Office.php index 20fbef6eb23..ffba0211de2 100644 --- a/lib/private/Preview/Office.php +++ b/lib/private/Preview/Office.php @@ -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. |