Merge pull request #553 from jonnybarnes/develop

MTM More Media Endpoint Improvements
This commit is contained in:
Jonny Barnes 2022-11-20 17:30:25 +00:00 committed by GitHub
commit e0efd19ef9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 0 deletions

View file

@ -74,6 +74,8 @@ class MicropubMediaController extends Controller
$media->transform(function ($mediaItem) {
return [
'url' => $mediaItem->url,
'published' => $mediaItem->created_at->toW3cString(),
'mime_type' => $mediaItem->getMimeType(),
];
});

View file

@ -107,4 +107,28 @@ class Media extends Model
return array_pop($parts);
}
/**
* Get the mime type of the media file.
*
* For now we will just use the extension, but this could be improved.
*
* @return string
*/
public function getMimeType(): string
{
$extension = $this->getExtension($this->path);
return match ($extension) {
'gif' => 'image/gif',
'jpeg', 'jpg' => 'image/jpeg',
'png' => 'image/png',
'svg' => 'image/svg+xml',
'tiff' => 'image/tiff',
'webp' => 'image/webp',
'mp4' => 'video/mp4',
'mkv' => 'video/mkv',
default => 'application/octet-stream',
};
}
}

View file

@ -137,6 +137,8 @@ class MicropubMediaTest extends TestCase
);
$sourceUploadResponse->assertJson(['items' => [[
'url' => $response->headers->get('Location'),
'published' => carbon()->toW3cString(),
'mime_type' => 'image/png',
]]]);
// now remove file
@ -168,6 +170,8 @@ class MicropubMediaTest extends TestCase
);
$sourceUploadResponse->assertJson(['items' => [[
'url' => $response->headers->get('Location'),
'published' => carbon()->toW3cString(),
'mime_type' => 'image/png',
]]]);
// And given our limit of 1 there should only be one result
$this->assertCount(1, json_decode($sourceUploadResponse->getContent(), true)['items']);