Merge pull request #553 from jonnybarnes/develop
MTM More Media Endpoint Improvements
This commit is contained in:
commit
e0efd19ef9
3 changed files with 30 additions and 0 deletions
|
@ -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(),
|
||||
];
|
||||
});
|
||||
|
||||
|
|
|
@ -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',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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']);
|
||||
|
|
Loading…
Add table
Reference in a new issue