forked from GNUsocial/gnu-social
[COMPONENT][Attachment][Posting] Move onHashFile
from Posting to Attachment. Remove onGetAllowedThumbnailSizes
This commit is contained in:
parent
614e02b4c6
commit
e9dfa0f08c
@ -25,6 +25,7 @@ use App\Core\Event;
|
|||||||
use App\Core\Modules\Component;
|
use App\Core\Modules\Component;
|
||||||
use App\Core\Router\RouteLoader;
|
use App\Core\Router\RouteLoader;
|
||||||
use Component\Attachment\Controller as C;
|
use Component\Attachment\Controller as C;
|
||||||
|
use Component\Attachment\Entity as E;
|
||||||
|
|
||||||
class Attachment extends Component
|
class Attachment extends Component
|
||||||
{
|
{
|
||||||
@ -36,4 +37,15 @@ class Attachment extends Component
|
|||||||
$r->connect('attachment_thumbnail', '/object/attachment/{id<\d+>}/thumbnail/{size<big|medium|small>}', [C\Attachment::class, 'attachment_thumbnail']);
|
$r->connect('attachment_thumbnail', '/object/attachment/{id<\d+>}/thumbnail/{size<big|medium|small>}', [C\Attachment::class, 'attachment_thumbnail']);
|
||||||
return Event::next;
|
return Event::next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a unique representation of a file on disk
|
||||||
|
*
|
||||||
|
* This can be used in the future to deduplicate images by visual content
|
||||||
|
*/
|
||||||
|
public function onHashFile(string $filename, ?string &$out_hash): bool
|
||||||
|
{
|
||||||
|
$out_hash = hash_file(E\Attachment::FILEHASH_ALGO, $filename);
|
||||||
|
return Event::stop;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -251,24 +251,4 @@ class Posting extends Component
|
|||||||
return Event::next;
|
return Event::next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a unique representation of a file on disk
|
|
||||||
*
|
|
||||||
* This can be used in the future to deduplicate images by visual content
|
|
||||||
*/
|
|
||||||
public function onHashFile(string $filename, ?string &$out_hash): bool
|
|
||||||
{
|
|
||||||
$out_hash = hash_file(Attachment::FILEHASH_ALGO, $filename);
|
|
||||||
return Event::stop;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fill the list with allowed sizes for an attachment, to prevent potential DoS'ing by requesting thousands of different thumbnail sizes
|
|
||||||
*/
|
|
||||||
public function onGetAllowedThumbnailSizes(?array &$sizes): bool
|
|
||||||
{
|
|
||||||
$sizes[] = ['width' => Common::config('thumbnail', 'width'), 'height' => Common::config('thumbnail', 'height')];
|
|
||||||
return Event::next;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user