Handle missing attachment with correct response
This commit is contained in:
parent
6b7dfa34e9
commit
77831aaf49
2 changed files with 13 additions and 9 deletions
|
@ -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);
|
||||
|
|
|
@ -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']]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue