[MEDIA] Allow thumbnail only entries

This commit is contained in:
2021-02-21 10:35:02 +00:00
parent 4deaaa8dbe
commit 422b82d3be
7 changed files with 69 additions and 39 deletions

View File

@@ -100,11 +100,15 @@ class File_thumbnail extends Managed_DataObject
case 'image/svg+xml':
throw new UseFileAsThumbnailException($file);
}
} else {
throw new ServerException("This remote file has no local thumbnail.");
}
}
$image = ImageFile::fromFileObject($file);
try {
$image = ImageFile::fromFileObject($file);
} catch (InvalidFilenameException $e) {
// Not having an original local file doesn't mean we don't have a thumbnail.
$existing_thumb = File_thumbnail::byFile($file);
$image = new ImageFile($file->getID(), $existing_thumb->getPath(), null, $existing_thumb->url);
}
$imgPath = $image->getPath();
$media = common_get_mime_media($file->mimetype);
if (Event::handle('CreateFileImageThumbnailSource', [$file, &$imgPath, $media])) {
@@ -280,7 +284,7 @@ class File_thumbnail extends Managed_DataObject
public function getUrl()
{
$url = common_local_url('attachment_thumbnail', ['filehash' => $this->getFile()->filehash]);
$url = common_local_url('attachment_thumbnail', ['attachment' => $this->getFile()->getID()]);
if (strpos($url, '?') === false) {
$url .= '?';
}