[CORE] Refactored attachement actions to remove duplicate code
This commit is contained in:
parent
c7475d78b4
commit
9536f2a909
@ -132,4 +132,25 @@ class AttachmentAction extends ManagedAction
|
|||||||
$ns = new AttachmentNoticeSection($this);
|
$ns = new AttachmentNoticeSection($this);
|
||||||
$ns->show();
|
$ns->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function sendFile(string $filepath) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,19 +30,7 @@ class Attachment_downloadAction extends AttachmentAction
|
|||||||
header("Content-Disposition: attachment; filename=\"{$filename}\"");
|
header("Content-Disposition: attachment; filename=\"{$filename}\"");
|
||||||
header('Expires: 0');
|
header('Expires: 0');
|
||||||
header('Content-Transfer-Encoding: binary'); // FIXME? Can this be different?
|
header('Content-Transfer-Encoding: binary'); // FIXME? Can this be different?
|
||||||
$filesize = $this->attachment->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);
|
$this->sendFile($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.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,13 +3,11 @@
|
|||||||
if (!defined('GNUSOCIAL')) { exit(1); }
|
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Download notice attachment
|
* View notice attachment
|
||||||
*
|
*
|
||||||
* @category Personal
|
|
||||||
* @package GNUsocial
|
* @package GNUsocial
|
||||||
* @author Mikael Nordfeldth <mmn@hethane.se>
|
* @author Miguel Dantas <biodantasgs@gmail.com>
|
||||||
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||||
* @link https:/gnu.io/social
|
|
||||||
*/
|
*/
|
||||||
class Attachment_viewAction extends AttachmentAction
|
class Attachment_viewAction extends AttachmentAction
|
||||||
{
|
{
|
||||||
@ -33,20 +31,8 @@ class Attachment_viewAction extends AttachmentAction
|
|||||||
header("Content-Disposition: attachment; filename=\"{$filename}\"");
|
header("Content-Disposition: attachment; filename=\"{$filename}\"");
|
||||||
}
|
}
|
||||||
header('Expires: 0');
|
header('Expires: 0');
|
||||||
header('Content-Transfer-Encoding: binary'); // FIXME? Can this be different?
|
header('Content-Transfer-Encoding: binary');
|
||||||
$filesize = $this->attachment->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);
|
$this->sendFile($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.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ defined('GNUSOCIAL') || die();
|
|||||||
define('GNUSOCIAL_ENGINE', 'GNU social');
|
define('GNUSOCIAL_ENGINE', 'GNU social');
|
||||||
define('GNUSOCIAL_ENGINE_URL', 'https://www.gnu.org/software/social/');
|
define('GNUSOCIAL_ENGINE_URL', 'https://www.gnu.org/software/social/');
|
||||||
|
|
||||||
define('GNUSOCIAL_BASE_VERSION', '1.24.0');
|
define('GNUSOCIAL_BASE_VERSION', '1.24.1');
|
||||||
define('GNUSOCIAL_LIFECYCLE', 'dev'); // 'dev', 'alpha[0-9]+', 'beta[0-9]+', 'rc[0-9]+', 'release'
|
define('GNUSOCIAL_LIFECYCLE', 'dev'); // 'dev', 'alpha[0-9]+', 'beta[0-9]+', 'rc[0-9]+', 'release'
|
||||||
|
|
||||||
define('GNUSOCIAL_VERSION', GNUSOCIAL_BASE_VERSION . '-' . GNUSOCIAL_LIFECYCLE);
|
define('GNUSOCIAL_VERSION', GNUSOCIAL_BASE_VERSION . '-' . GNUSOCIAL_LIFECYCLE);
|
||||||
|
Loading…
Reference in New Issue
Block a user