[ImageEncoder][VideoEncoder] Properly decide when to take action
This commit is contained in:
parent
bccafd0d7b
commit
56ba7bd845
@ -55,9 +55,13 @@ class ImageEncoder extends Plugin
|
|||||||
return '3.0.0';
|
return '3.0.0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function shouldHandle (string $mimetype): bool {
|
||||||
|
return GSFile::mimetypeMajor($mimetype) === 'image';
|
||||||
|
}
|
||||||
|
|
||||||
public function onFileMetaAvailable(array &$event_map, string $mimetype): bool
|
public function onFileMetaAvailable(array &$event_map, string $mimetype): bool
|
||||||
{
|
{
|
||||||
if (GSFile::mimetypeMajor($mimetype) !== 'image') {
|
if (!self::shouldHandle($mimetype)) {
|
||||||
return Event::next;
|
return Event::next;
|
||||||
}
|
}
|
||||||
$event_map['image'][] = [$this, 'fileMeta'];
|
$event_map['image'][] = [$this, 'fileMeta'];
|
||||||
@ -66,7 +70,7 @@ class ImageEncoder extends Plugin
|
|||||||
|
|
||||||
public function onFileSanitizerAvailable(array &$event_map, string $mimetype): bool
|
public function onFileSanitizerAvailable(array &$event_map, string $mimetype): bool
|
||||||
{
|
{
|
||||||
if (GSFile::mimetypeMajor($mimetype) !== 'image') {
|
if (!self::shouldHandle($mimetype)) {
|
||||||
return Event::next;
|
return Event::next;
|
||||||
}
|
}
|
||||||
$event_map['image'][] = [$this, 'fileSanitize'];
|
$event_map['image'][] = [$this, 'fileSanitize'];
|
||||||
@ -75,7 +79,7 @@ class ImageEncoder extends Plugin
|
|||||||
|
|
||||||
public function onFileResizerAvailable(array &$event_map, string $mimetype): bool
|
public function onFileResizerAvailable(array &$event_map, string $mimetype): bool
|
||||||
{
|
{
|
||||||
if (GSFile::mimetypeMajor($mimetype) !== 'image') {
|
if (!self::shouldHandle($mimetype)) {
|
||||||
return Event::next;
|
return Event::next;
|
||||||
}
|
}
|
||||||
$event_map['image'][] = [$this, 'resizeImagePath'];
|
$event_map['image'][] = [$this, 'resizeImagePath'];
|
||||||
@ -177,9 +181,10 @@ class ImageEncoder extends Plugin
|
|||||||
*/
|
*/
|
||||||
public function onViewAttachment(array $vars, array &$res): bool
|
public function onViewAttachment(array $vars, array &$res): bool
|
||||||
{
|
{
|
||||||
if ($vars['attachment']->getMimetypeMajor() !== 'image') {
|
if (!self::shouldHandle($vars['attachment']->getMimetype())) {
|
||||||
return Event::next;
|
return Event::next;
|
||||||
}
|
}
|
||||||
|
|
||||||
$res[] = Formatting::twigRenderFile(
|
$res[] = Formatting::twigRenderFile(
|
||||||
'imageEncoder/imageEncoderView.html.twig',
|
'imageEncoder/imageEncoderView.html.twig',
|
||||||
[
|
[
|
||||||
|
@ -54,9 +54,13 @@ class VideoEncoder extends Plugin
|
|||||||
return '1.0.0';
|
return '1.0.0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function shouldHandle (string $mimetype): bool {
|
||||||
|
return GSFile::mimetypeMajor($mimetype) === 'video' || $mimetype === 'image/gif';
|
||||||
|
}
|
||||||
|
|
||||||
public function onFileMetaAvailable(array &$event_map, string $mimetype): bool
|
public function onFileMetaAvailable(array &$event_map, string $mimetype): bool
|
||||||
{
|
{
|
||||||
if (GSFile::mimetypeMajor($mimetype) !== 'video' && $mimetype !== 'image/gif') {
|
if (!self::shouldHandle($mimetype)) {
|
||||||
return Event::next;
|
return Event::next;
|
||||||
}
|
}
|
||||||
$event_map['video'][] = [$this, 'fileMeta'];
|
$event_map['video'][] = [$this, 'fileMeta'];
|
||||||
@ -66,7 +70,7 @@ class VideoEncoder extends Plugin
|
|||||||
|
|
||||||
public function onFileSanitizerAvailable(array &$event_map, string $mimetype): bool
|
public function onFileSanitizerAvailable(array &$event_map, string $mimetype): bool
|
||||||
{
|
{
|
||||||
if (GSFile::mimetypeMajor($mimetype) !== 'video' && $mimetype !== 'image/gif') {
|
if ($mimetype !== 'image/gif') {
|
||||||
return Event::next;
|
return Event::next;
|
||||||
}
|
}
|
||||||
$event_map['video'][] = [$this, 'fileMeta'];
|
$event_map['video'][] = [$this, 'fileMeta'];
|
||||||
@ -76,7 +80,7 @@ class VideoEncoder extends Plugin
|
|||||||
|
|
||||||
public function onFileResizerAvailable(array &$event_map, string $mimetype): bool
|
public function onFileResizerAvailable(array &$event_map, string $mimetype): bool
|
||||||
{
|
{
|
||||||
if (GSFile::mimetypeMajor($mimetype) !== 'video' && $mimetype !== 'image/gif') {
|
if ($mimetype !== 'image/gif') {
|
||||||
return Event::next;
|
return Event::next;
|
||||||
}
|
}
|
||||||
$event_map['video'][] = [$this, 'resizeVideoPath'];
|
$event_map['video'][] = [$this, 'resizeVideoPath'];
|
||||||
@ -91,15 +95,10 @@ class VideoEncoder extends Plugin
|
|||||||
* @param null|int $width out
|
* @param null|int $width out
|
||||||
* @param null|int $height out
|
* @param null|int $height out
|
||||||
*
|
*
|
||||||
* @return bool true if sanitized
|
* @return bool true if metadata filled
|
||||||
*/
|
*/
|
||||||
public function fileMeta(SplFileInfo &$file, ?string &$mimetype, ?int &$width, ?int &$height): bool
|
public function fileMeta(SplFileInfo &$file, ?string &$mimetype, ?int &$width, ?int &$height): bool
|
||||||
{
|
{
|
||||||
if (//GSFile::mimetypeMajor($mimetype) !== 'video' &&
|
|
||||||
$mimetype !== 'image/gif') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create FFProbe instance
|
// Create FFProbe instance
|
||||||
// Need to explicitly tell the drivers' location, or it won't find them
|
// Need to explicitly tell the drivers' location, or it won't find them
|
||||||
$ffprobe = ffprobe::create([
|
$ffprobe = ffprobe::create([
|
||||||
@ -113,8 +112,6 @@ class VideoEncoder extends Plugin
|
|||||||
$width = $metadata->get('width');
|
$width = $metadata->get('width');
|
||||||
$height = $metadata->get('height');
|
$height = $metadata->get('height');
|
||||||
|
|
||||||
// Only one plugin can handle sanitization
|
|
||||||
$mimetype = 'image/gif';
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,6 +138,10 @@ class VideoEncoder extends Plugin
|
|||||||
*/
|
*/
|
||||||
public function onViewAttachment(array $vars, array &$res): bool
|
public function onViewAttachment(array $vars, array &$res): bool
|
||||||
{
|
{
|
||||||
|
if ($vars['attachment']->getMimetypeMajor() !== 'video') {
|
||||||
|
return Event::next;
|
||||||
|
}
|
||||||
|
|
||||||
$res[] = Formatting::twigRenderFile(
|
$res[] = Formatting::twigRenderFile(
|
||||||
'videoEncoder/videoEncoderView.html.twig',
|
'videoEncoder/videoEncoderView.html.twig',
|
||||||
[
|
[
|
||||||
|
Loading…
Reference in New Issue
Block a user