[CORE][GSFile] Ensure files are stored inside the configured storage folder, with a relative filename in the database
This commit is contained in:
parent
51f8f004b3
commit
647e4c03b3
@ -70,8 +70,8 @@ class GSFile
|
|||||||
?string $title = null,
|
?string $title = null,
|
||||||
bool $is_local = true): Attachment
|
bool $is_local = true): Attachment
|
||||||
{
|
{
|
||||||
if (!Formatting::startsWith($dest_dir, INSTALLDIR)) {
|
if (!Formatting::startsWith($dest_dir, Common::config('attachments', 'dir'))) {
|
||||||
throw new \InvalidArgumentException("Attempted to store an attachment to a folder outside the GNU social installation: {$dest_dir}");
|
throw new \InvalidArgumentException("Attempted to store an attachment to a folder outside the GNU social attachment location: {$dest_dir}");
|
||||||
}
|
}
|
||||||
|
|
||||||
$hash = null;
|
$hash = null;
|
||||||
@ -93,7 +93,7 @@ class GSFile
|
|||||||
'gsactor_id' => $actor_id,
|
'gsactor_id' => $actor_id,
|
||||||
'mimetype' => $mimetype,
|
'mimetype' => $mimetype,
|
||||||
'title' => $title,
|
'title' => $title,
|
||||||
'filename' => Formatting::removePrefix($dest_dir, INSTALLDIR . DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $hash,
|
'filename' => Formatting::removePrefix($dest_dir, Common::config('attachments', 'dir')) . $hash,
|
||||||
'is_local' => $is_local,
|
'is_local' => $is_local,
|
||||||
'size' => $file->getSize(),
|
'size' => $file->getSize(),
|
||||||
'width' => $width,
|
'width' => $width,
|
||||||
@ -200,7 +200,7 @@ class GSFile
|
|||||||
$id,
|
$id,
|
||||||
Cache::get("file-info-{$id}",
|
Cache::get("file-info-{$id}",
|
||||||
function () use ($id) {
|
function () use ($id) {
|
||||||
return DB::dql('select at.file_hash, at.mimetype, at.title ' .
|
return DB::dql('select at.filename, at.mimetype, at.title ' .
|
||||||
'from App\\Entity\\Attachment at ' .
|
'from App\\Entity\\Attachment at ' .
|
||||||
'where at.id = :id',
|
'where at.id = :id',
|
||||||
['id' => $id]);
|
['id' => $id]);
|
||||||
@ -217,7 +217,7 @@ class GSFile
|
|||||||
public static function getAttachmentFileInfo(int $id): array
|
public static function getAttachmentFileInfo(int $id): array
|
||||||
{
|
{
|
||||||
$res = self::getFileInfo($id);
|
$res = self::getFileInfo($id);
|
||||||
$res['filepath'] = Common::config('attachments', 'dir') . $res['file_hash'];
|
$res['filepath'] = Common::config('attachments', 'dir') . $res['filename'];
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user