Browse Source

[AttachmentThumbnail] Use other thumbnail when requested isn't available and there's no original file

remotes/upstream/experimental
parent
commit
3268559f9a
Signed by: diogo <mail@diogo.site> GPG Key ID: 18D2D35001FBFAB0
2 changed files with 9 additions and 2 deletions
  1. +1
    -0
      plugins/StoreRemoteMedia/StoreRemoteMedia.php
  2. +8
    -2
      src/Entity/AttachmentThumbnail.php

+ 1
- 0
plugins/StoreRemoteMedia/StoreRemoteMedia.php View File

@@ -160,6 +160,7 @@ class StoreRemoteMedia extends Plugin
$attachment = GSFile::storeFileAsAttachment($temp_file);

// Relate the link with the attachment
// TODO: Create a function that gets the title from content disposition or URL when such header isn't available
DB::persist(AttachmentToLink::create([
'link_id' => $link->getId(),
'attachment_id' => $attachment->getId(),


+ 8
- 2
src/Entity/AttachmentThumbnail.php View File

@@ -152,7 +152,7 @@ class AttachmentThumbnail extends Entity
*
* @return mixed
*/
public static function getOrCreate(Attachment $attachment, ?string $size = null, bool $crop = false)
public static function getOrCreate(Attachment $attachment, ?string $size = null, bool $crop = false): ?self
{
$size = $size ?? Common::config('thumbnail', 'default_size');
$size_int = match ($size) {
@@ -171,7 +171,13 @@ class AttachmentThumbnail extends Entity
}
[$predicted_width, $predicted_height] = self::predictScalingValues($attachment->getWidth(), $attachment->getHeight(), $size, $crop);
if (!file_exists($attachment->getPath())) {
throw new NotStoredLocallyException();
// Before we quit, check if there's any other thumb
$alternative_thumbs = DB::findBy('attachment_thumbnail', ['attachment_id' => $attachment->getId()]);
if ($alternative_thumbs === []) {
throw new NotStoredLocallyException();
} else {
return $alternative_thumbs[0];
}
}
$thumbnail = self::create(['attachment_id' => $attachment->getId()]);
$mimetype = $attachment->getMimetype();


Loading…
Cancel
Save