abort if single media not found

This commit is contained in:
philipp lang 2023-03-07 23:30:05 +01:00
parent 278bf58551
commit f5e9aff0be
2 changed files with 11 additions and 0 deletions

View File

@ -78,6 +78,8 @@ class MediaController
$model = $model::find($parentId);
$isSingle = 1 === $model->getMediaCollection($collection)->collectionSizeLimit;
abort_if($isSingle && !$model->getFirstMedia($collection), 404);
return $isSingle
? MediaData::from($model->getFirstMedia($collection))
: MediaData::collection($model->getMedia($collection));

View File

@ -27,3 +27,12 @@ test('it gets media for single', function () {
$response->assertJsonPath('id', $media->id);
$response->assertJsonPath('properties.test', 'old');
});
test('it returns 404 when media not found', function () {
$this->auth()->registerModel();
$post = $this->newPost();
$response = $this->getJson("/mediaupload/post/{$post->id}/defaultSingleFile");
$response->assertStatus(404);
});