From 783f231911396e1c548175b34008dfe4e613f46c Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Thu, 16 Mar 2023 15:40:18 -0100 Subject: [PATCH] ignore empty media type Signed-off-by: Maxence Lange --- lib/Model/ActivityPub/Object/Document.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/Model/ActivityPub/Object/Document.php b/lib/Model/ActivityPub/Object/Document.php index 402cde95..4fd494f1 100644 --- a/lib/Model/ActivityPub/Object/Document.php +++ b/lib/Model/ActivityPub/Object/Document.php @@ -371,22 +371,26 @@ class Document extends ACore implements JsonSerializable { */ public function convertToMediaAttachment(?IURLGenerator $urlGenerator = null): MediaAttachment { $media = new MediaAttachment(); + $media->setId((string)$this->getNid()); - [$type, $mime] = explode('/', $this->getMediaType(), 2); - $media->setId((string)$this->getNid()) - ->setType($type); + $mime = ''; + if (strpos($this->getMediaType(), '/')) { + [$type, $mime] = explode('/', $this->getMediaType(), 2); + $media->setType($type); + $mime = (strlen($mime) < 7) ? '.' . $mime : ''; // mime is ignored if too long. + } if (!is_null($urlGenerator)) { $media->setUrl( $urlGenerator->linkToRouteAbsolute( 'social.Api.mediaOpen', - ['uuid' => $this->getLocalCopy() . '.' . $mime] + ['uuid' => $this->getLocalCopy() . $mime] ) ); $media->setPreviewUrl( $urlGenerator->linkToRouteAbsolute( 'social.Api.mediaOpen', - ['uuid' => $this->getResizedCopy() . '.' . $mime] + ['uuid' => $this->getResizedCopy() . $mime] ) ); $media->setRemoteUrl($this->getUrl());