[COMPONENT][Attachment][Posting] Move onHashFile from Posting to Attachment. Remove onGetAllowedThumbnailSizes

This commit is contained in:
Hugo Sales 2021-12-08 20:35:59 +00:00
parent 614e02b4c6
commit e9dfa0f08c
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
2 changed files with 12 additions and 20 deletions

View File

@ -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<big|medium|small>}', [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;
}
}

View File

@ -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;
}
}