[CORE] Fixed bug where the http connection was using the wrong size for thumbnails, and returning the wrong one
This commit is contained in:
parent
f746866b65
commit
3e5ce46e98
|
@ -204,7 +204,7 @@ class AttachmentAction extends ManagedAction
|
||||||
/**
|
/**
|
||||||
* Include $filepath in the response, for viewing and downloading
|
* Include $filepath in the response, for viewing and downloading
|
||||||
*/
|
*/
|
||||||
static function sendFile(string $filepath, int $filesize) {
|
static function sendFile(string $filepath, $filesize) {
|
||||||
if (common_config('site', 'use_x_sendfile')) {
|
if (common_config('site', 'use_x_sendfile')) {
|
||||||
header('X-Sendfile: ' . $filepath);
|
header('X-Sendfile: ' . $filepath);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -17,7 +17,7 @@ class Attachment_downloadAction extends AttachmentAction
|
||||||
{
|
{
|
||||||
// Checks file exists or throws FileNotFoundException
|
// Checks file exists or throws FileNotFoundException
|
||||||
$filepath = $this->attachment->getFileOrThumbnailPath();
|
$filepath = $this->attachment->getFileOrThumbnailPath();
|
||||||
$filesize = $this->attachment->size ?: 0;
|
$filesize = $this->attachment->getFileOrThumbnailSize();
|
||||||
$mimetype = $this->attachment->getFileOrThumbnailMimetype();
|
$mimetype = $this->attachment->getFileOrThumbnailMimetype();
|
||||||
|
|
||||||
if (empty($filepath)) {
|
if (empty($filepath)) {
|
||||||
|
|
|
@ -55,8 +55,6 @@ class Attachment_thumbnailAction extends AttachmentAction
|
||||||
|
|
||||||
public function showPage()
|
public function showPage()
|
||||||
{
|
{
|
||||||
// Checks file exists or throws FileNotFoundException
|
|
||||||
$size = $this->attachment->size ?: 0;
|
|
||||||
|
|
||||||
// Returns a File_thumbnail object or throws exception if not available
|
// Returns a File_thumbnail object or throws exception if not available
|
||||||
try {
|
try {
|
||||||
|
@ -69,8 +67,10 @@ class Attachment_thumbnailAction extends AttachmentAction
|
||||||
$this->clientError(_('No such attachment'), 404);
|
$this->clientError(_('No such attachment'), 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
$filepath = $file->getFileOrThumbnailPath();
|
// Checks file exists or throws FileNotFoundException
|
||||||
$mimetype = $file->getFileOrThumbnailMimetype();
|
$filepath = $file->getFileOrThumbnailPath($thumbnail);
|
||||||
|
$filesize = $this->attachment->getFileOrThumbnailSize($thumbnail);
|
||||||
|
$mimetype = $file->getFileOrThumbnailMimetype($thumbnail);
|
||||||
$filename = MediaFile::getDisplayName($file);
|
$filename = MediaFile::getDisplayName($file);
|
||||||
|
|
||||||
// Disable errors, to not mess with the file contents (suppress errors in case access to this
|
// Disable errors, to not mess with the file contents (suppress errors in case access to this
|
||||||
|
|
|
@ -15,7 +15,7 @@ class Attachment_viewAction extends AttachmentAction
|
||||||
{
|
{
|
||||||
// Checks file exists or throws FileNotFoundException
|
// Checks file exists or throws FileNotFoundException
|
||||||
$filepath = $this->attachment->getFileOrThumbnailPath();
|
$filepath = $this->attachment->getFileOrThumbnailPath();
|
||||||
$filesize = $this->attachment->size ?: 0;
|
$filesize = $this->attachment->getFileOrThumbnailSize();
|
||||||
$mimetype = $this->attachment->getFileOrThumbnailMimetype();
|
$mimetype = $this->attachment->getFileOrThumbnailMimetype();
|
||||||
|
|
||||||
if (empty($filepath)) {
|
if (empty($filepath)) {
|
||||||
|
|
|
@ -603,8 +603,11 @@ class File extends Managed_DataObject
|
||||||
* @throws InvalidFilenameException
|
* @throws InvalidFilenameException
|
||||||
* @throws ServerException
|
* @throws ServerException
|
||||||
*/
|
*/
|
||||||
public function getFileOrThumbnailPath() : string
|
public function getFileOrThumbnailPath($thumbnail = null) : string
|
||||||
{
|
{
|
||||||
|
if (!empty($thumbnail)) {
|
||||||
|
return $thumbnail->getPath();
|
||||||
|
}
|
||||||
if (!empty($this->filename)) {
|
if (!empty($this->filename)) {
|
||||||
$filepath = self::path($this->filename);
|
$filepath = self::path($this->filename);
|
||||||
if (file_exists($filepath)) {
|
if (file_exists($filepath)) {
|
||||||
|
@ -630,19 +633,40 @@ class File extends Managed_DataObject
|
||||||
* @throws ServerException
|
* @throws ServerException
|
||||||
* @throws UnsupportedMediaException
|
* @throws UnsupportedMediaException
|
||||||
*/
|
*/
|
||||||
public function getFileOrThumbnailMimetype() : string
|
public function getFileOrThumbnailMimetype($thumbnail = null) : string
|
||||||
{
|
{
|
||||||
if (empty($this->filename)) {
|
if (!empty($thumbnail)) {
|
||||||
|
$filepath = $thumbnail->getPath();
|
||||||
|
} elseif (empty($this->filename)) {
|
||||||
$filepath = File_thumbnail::byFile($this)->getPath();
|
$filepath = File_thumbnail::byFile($this)->getPath();
|
||||||
$info = @getimagesize($filepath);
|
|
||||||
if ($info !== false) {
|
|
||||||
return $info['mime'];
|
|
||||||
} else {
|
|
||||||
throw new UnsupportedMediaException(_("Thumbnail is not an image."));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return $this->mimetype;
|
return $this->mimetype;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$info = @getimagesize($filepath);
|
||||||
|
if ($info !== false) {
|
||||||
|
return $info['mime'];
|
||||||
|
} else {
|
||||||
|
throw new UnsupportedMediaException(_("Thumbnail is not an image."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the size of the thumbnail if we have it, or, if not, of the File
|
||||||
|
* @return int
|
||||||
|
* @throws FileNotFoundException
|
||||||
|
* @throws NoResultException
|
||||||
|
* @throws ServerException
|
||||||
|
*/
|
||||||
|
public function getFileOrThumbnailSize($thumbnail = null) : int
|
||||||
|
{
|
||||||
|
if (!empty($thumbnail)) {
|
||||||
|
return filesize($thumbnail->getPath());
|
||||||
|
} elseif (!empty($this->filename)) {
|
||||||
|
return $this->size;
|
||||||
|
} else {
|
||||||
|
return filesize(File_thumbnail::byFile($this)->getPath());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAttachmentUrl()
|
public function getAttachmentUrl()
|
||||||
|
|
|
@ -172,9 +172,9 @@ class File_thumbnail extends Managed_DataObject
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @return string full filesystem path to the locally stored thumbnail file
|
* @return string full filesystem path to the locally stored thumbnail file
|
||||||
* @throws
|
* @throws FileNotFoundException
|
||||||
|
* @throws ServerException
|
||||||
*/
|
*/
|
||||||
public function getPath()
|
public function getPath()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user