diff --git a/src/Factory/Api/Mastodon/Attachment.php b/src/Factory/Api/Mastodon/Attachment.php index 52361284ac..bd16b61b38 100644 --- a/src/Factory/Api/Mastodon/Attachment.php +++ b/src/Factory/Api/Mastodon/Attachment.php @@ -54,14 +54,7 @@ class Attachment extends BaseFactory $attachment = Post\Media::getById($id); if (empty($attachment)) { - $attachment = [ - 'id' => '', - 'description' => '', - 'url' => '', - 'mimetype' => '', - 'blurhash' => '', - 'type' => Post\Media::UNKNOWN, - ]; + throw new InternalServerErrorException(); } return $this->createFromMediaArray($attachment); diff --git a/src/Module/Api/Mastodon/Media.php b/src/Module/Api/Mastodon/Media.php index 5dbcfc3687..f9d61e0db3 100644 --- a/src/Module/Api/Mastodon/Media.php +++ b/src/Module/Api/Mastodon/Media.php @@ -13,6 +13,7 @@ use Friendica\Model\Contact; use Friendica\Model\Photo; use Friendica\Model\Post; use Friendica\Module\BaseApi; +use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Util\Strings; /** @@ -97,14 +98,24 @@ class Media extends BaseApi $photo = Photo::selectFirst(['resource-id'], ['id' => $this->parameters['id'], 'uid' => $uid]); if (empty($photo['resource-id'])) { $media = Post\Media::getById($this->parameters['id']); + if (empty($media['uri-id'])) { $this->logAndJsonError(404, $this->errorFactory->RecordNotFound()); } + if (!Post::exists(['uri-id' => $media['uri-id'], 'uid' => $uid, 'origin' => true])) { $this->logAndJsonError(404, $this->errorFactory->RecordNotFound()); } + Post\Media::updateById(['description' => $request['description']], $this->parameters['id']); - $this->jsonExit(DI::mstdnAttachment()->createFromId($this->parameters['id'])); + + try { + $attachment = DI::mstdnAttachment()->createFromId($this->parameters['id'] . '1'); + } catch (InternalServerErrorException $th) { + $this->logAndJsonError(404, $this->errorFactory->RecordNotFound()); + } + + $this->jsonExit($attachment); } Photo::update(['desc' => $request['description']], ['resource-id' => $photo['resource-id']]);