forked from GNUsocial/gnu-social
		
	[COMPONENT][Attachment][Posting] Move onHashFile from Posting to Attachment. Remove onGetAllowedThumbnailSizes
				
					
				
			This commit is contained in:
		| @@ -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; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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; | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user