From e9dfa0f08c390edad3e552149f510e1c5374035c Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Wed, 8 Dec 2021 20:35:59 +0000 Subject: [PATCH] [COMPONENT][Attachment][Posting] Move `onHashFile` from Posting to Attachment. Remove `onGetAllowedThumbnailSizes` --- components/Attachment/Attachment.php | 12 ++++++++++++ components/Posting/Posting.php | 20 -------------------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/components/Attachment/Attachment.php b/components/Attachment/Attachment.php index 2b0d9a0bcc..fa6ba0f34c 100644 --- a/components/Attachment/Attachment.php +++ b/components/Attachment/Attachment.php @@ -25,6 +25,7 @@ use App\Core\Event; use App\Core\Modules\Component; use App\Core\Router\RouteLoader; use Component\Attachment\Controller as C; +use Component\Attachment\Entity as E; class Attachment extends Component { @@ -36,4 +37,15 @@ class Attachment extends Component $r->connect('attachment_thumbnail', '/object/attachment/{id<\d+>}/thumbnail/{size}', [C\Attachment::class, 'attachment_thumbnail']); 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; + } } diff --git a/components/Posting/Posting.php b/components/Posting/Posting.php index 7c2f9be955..0f6fee28e2 100644 --- a/components/Posting/Posting.php +++ b/components/Posting/Posting.php @@ -251,24 +251,4 @@ class Posting extends Component 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; - } }