]> git.mxchange.org Git - friendica.git/commitdiff
Handle missing attachment with correct response
authorArt4 <art4@wlabs.de>
Thu, 6 Mar 2025 09:25:39 +0000 (09:25 +0000)
committerArt4 <art4@wlabs.de>
Thu, 6 Mar 2025 09:25:39 +0000 (09:25 +0000)
src/Factory/Api/Mastodon/Attachment.php
src/Module/Api/Mastodon/Media.php

index 52361284ac2c6b7303f1d77e21d147094c06d074..bd16b61b38a7851fc44ffd8c8906523e679ab70b 100644 (file)
@@ -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);
index 5dbcfc3687bc0eb830a6fc8805aef663f38a7258..f9d61e0db3a0f5a612bb8234c5216e813962e501 100644 (file)
@@ -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']]);