Return a published and mime type data with sourced media uploads
This commit is contained in:
parent
84efc8a3da
commit
42f0fa2238
3 changed files with 30 additions and 0 deletions
|
@ -74,6 +74,8 @@ class MicropubMediaController extends Controller
|
||||||
$media->transform(function ($mediaItem) {
|
$media->transform(function ($mediaItem) {
|
||||||
return [
|
return [
|
||||||
'url' => $mediaItem->url,
|
'url' => $mediaItem->url,
|
||||||
|
'published' => $mediaItem->created_at->toW3cString(),
|
||||||
|
'mime_type' => $mediaItem->getMimeType(),
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -107,4 +107,28 @@ class Media extends Model
|
||||||
|
|
||||||
return array_pop($parts);
|
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' => [[
|
$sourceUploadResponse->assertJson(['items' => [[
|
||||||
'url' => $response->headers->get('Location'),
|
'url' => $response->headers->get('Location'),
|
||||||
|
'published' => carbon()->toW3cString(),
|
||||||
|
'mime_type' => 'image/png',
|
||||||
]]]);
|
]]]);
|
||||||
|
|
||||||
// now remove file
|
// now remove file
|
||||||
|
@ -168,6 +170,8 @@ class MicropubMediaTest extends TestCase
|
||||||
);
|
);
|
||||||
$sourceUploadResponse->assertJson(['items' => [[
|
$sourceUploadResponse->assertJson(['items' => [[
|
||||||
'url' => $response->headers->get('Location'),
|
'url' => $response->headers->get('Location'),
|
||||||
|
'published' => carbon()->toW3cString(),
|
||||||
|
'mime_type' => 'image/png',
|
||||||
]]]);
|
]]]);
|
||||||
// And given our limit of 1 there should only be one result
|
// And given our limit of 1 there should only be one result
|
||||||
$this->assertCount(1, json_decode($sourceUploadResponse->getContent(), true)['items']);
|
$this->assertCount(1, json_decode($sourceUploadResponse->getContent(), true)['items']);
|
||||||
|
|
Loading…
Add table
Reference in a new issue