forked from GNUsocial/gnu-social
[CORE] Fixed bug where all thumbnails were using the original file
This commit is contained in:
parent
bea06da531
commit
04d1caff78
@ -179,18 +179,17 @@ class AttachmentAction extends ManagedAction
|
||||
}
|
||||
|
||||
/**
|
||||
* Include $this as a file read from $filepath, for viewing and downloading
|
||||
* Include $filepath in the response, for viewing and downloading
|
||||
*/
|
||||
public function sendFile(string $filepath) {
|
||||
static function sendFile(string $filepath, int $size) {
|
||||
if (common_config('site', 'use_x_sendfile')) {
|
||||
header('X-Sendfile: ' . $filepath);
|
||||
} else {
|
||||
$filesize = $this->attachment->size;
|
||||
// 'if available', it says, so ensure we have it
|
||||
if (empty($filesize)) {
|
||||
$filesize = filesize($filepath);
|
||||
// ensure we have a file size
|
||||
if (empty($size)) {
|
||||
$size = filesize($filepath);
|
||||
}
|
||||
header("Content-Length: {$filesize}");
|
||||
header("Content-Length: {$size}");
|
||||
// header('Cache-Control: private, no-transform, no-store, must-revalidate');
|
||||
|
||||
$ret = @readfile($filepath);
|
||||
|
@ -17,7 +17,7 @@ class Attachment_downloadAction extends AttachmentAction
|
||||
{
|
||||
// Checks file exists or throws FileNotStoredLocallyException
|
||||
$filepath = $this->attachment->getPath();
|
||||
|
||||
$filesize = $this->attachment->size;
|
||||
$filename = MediaFile::getDisplayName($this->attachment);
|
||||
|
||||
// Disable errors, to not mess with the file contents (suppress errors in case access to this
|
||||
@ -31,6 +31,6 @@ class Attachment_downloadAction extends AttachmentAction
|
||||
header('Expires: 0');
|
||||
header('Content-Transfer-Encoding: binary'); // FIXME? Can this be different?
|
||||
|
||||
$this->sendFile($filepath);
|
||||
parent::sendFile($filepath, $filesize);
|
||||
}
|
||||
}
|
||||
|
@ -57,13 +57,21 @@ class Attachment_thumbnailAction extends AttachmentAction
|
||||
{
|
||||
// Returns a File_thumbnail object or throws exception if not available
|
||||
try {
|
||||
$file = $this->attachment->getThumbnail($this->thumb_w, $this->thumb_h, $this->thumb_c)->getFile();
|
||||
$thumb = $this->attachment->getThumbnail($this->thumb_w, $this->thumb_h, $this->thumb_c);
|
||||
$file = $thumb->getFile();
|
||||
} catch (UseFileAsThumbnailException $e) {
|
||||
// With this exception, the file exists locally
|
||||
$file = $e->file;
|
||||
}
|
||||
|
||||
$filepath = $this->attachment->getPath();
|
||||
if (!empty($thumb)) {
|
||||
$filepath = $thumb->getPath();
|
||||
$filesize = 0;
|
||||
} else {
|
||||
$filepath = $file->getPath();
|
||||
$filesize = $file->size;
|
||||
}
|
||||
|
||||
$filename = MediaFile::getDisplayName($file);
|
||||
|
||||
// Disable errors, to not mess with the file contents (suppress errors in case access to this
|
||||
@ -76,19 +84,7 @@ class Attachment_thumbnailAction extends AttachmentAction
|
||||
header("Content-Disposition: inline; filename=\"{$filename}\"");
|
||||
header('Expires: 0');
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
$filesize = $this->file->size;
|
||||
// 'if available', it says, so ensure we have it
|
||||
if (empty($filesize)) {
|
||||
$filesize = filesize($this->attachment->filename);
|
||||
}
|
||||
header("Content-Length: {$filesize}");
|
||||
// header('Cache-Control: private, no-transform, no-store, must-revalidate');
|
||||
|
||||
$ret = @readfile($filepath);
|
||||
|
||||
if ($ret === false || $ret !== $filesize) {
|
||||
common_log(LOG_ERR, "The lengths of the file as recorded on the DB (or on disk) for the file " .
|
||||
"{$filepath}, with id={$this->attachment->id} differ from what was sent to the user.");
|
||||
}
|
||||
parent::sendFile($filepath, $filesize);
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ class Attachment_viewAction extends AttachmentAction
|
||||
{
|
||||
// Checks file exists or throws FileNotStoredLocallyException
|
||||
$filepath = $this->attachment->getPath();
|
||||
$filesize = $this->attachment->size;
|
||||
|
||||
$filename = MediaFile::getDisplayName($this->attachment);
|
||||
|
||||
@ -33,6 +34,6 @@ class Attachment_viewAction extends AttachmentAction
|
||||
header('Expires: 0');
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
|
||||
$this->sendFile($filepath);
|
||||
parrent::sendFile($filepath, $filesize);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user