Add storing media type, so that we can use use right tag, such as img, or video in the view
This commit is contained in:
parent
f9c98108db
commit
8a79204a20
3 changed files with 51 additions and 2 deletions
|
@ -264,7 +264,7 @@ class MicropubController extends Controller
|
|||
if (array_search('post', $scopes) !== false) {
|
||||
//check media valid
|
||||
if ($request->hasFile('file') && $request->file('file')->isValid()) {
|
||||
//save media
|
||||
$type = $this->getFileTypeFromMimeType($request->file('file')->getMimeType());
|
||||
try {
|
||||
$filename = Uuid::uuid4() . '.' . $request->file('file')->extension();
|
||||
} catch (UnsatisfiedDependencyException $e) {
|
||||
|
@ -286,6 +286,7 @@ class MicropubController extends Controller
|
|||
$media = new Media();
|
||||
$media->token = $token;
|
||||
$media->path = $path;
|
||||
$media->type = $type;
|
||||
$media->save();
|
||||
|
||||
return response()->json([
|
||||
|
@ -321,4 +322,48 @@ class MicropubController extends Controller
|
|||
'error_description' => 'There was no token provided with the request',
|
||||
], 400);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file type from the mimetype of the uploaded file.
|
||||
*
|
||||
* @param string The mimetype
|
||||
* @return string The type
|
||||
*/
|
||||
private function getFileTypeFromMimeType($mimetype)
|
||||
{
|
||||
//try known images
|
||||
$imageMimeTypes = [
|
||||
'image/gif',
|
||||
'image/jpeg',
|
||||
'image/png',
|
||||
'image/svg+xml',
|
||||
'image/tiff',
|
||||
'image/webp',
|
||||
];
|
||||
if (in_array($mimetype, $imageMimeTypes)) {
|
||||
return 'image';
|
||||
}
|
||||
//try known video
|
||||
$videoMimeTypes = [
|
||||
'video/mp4',
|
||||
'video/mpeg',
|
||||
'video/quicktime',
|
||||
'video/webm',
|
||||
];
|
||||
if (in_array($mimetype, $videoMimeTypes)) {
|
||||
return 'video';
|
||||
}
|
||||
//try known audio types
|
||||
$audioMimeTypes = [
|
||||
'audio/midi',
|
||||
'audio/mpeg',
|
||||
'audio/ogg',
|
||||
'audio/x-m4a',
|
||||
];
|
||||
if (in_array($mimetype, $audioMimeTypes)) {
|
||||
return 'audio';
|
||||
}
|
||||
|
||||
return 'download';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ class CreateMediaEndpointTable extends Migration
|
|||
$table->increments('id');
|
||||
$table->text('token')->nullable();
|
||||
$table->string('path');
|
||||
$table->string('type');
|
||||
$table->unsignedInteger('note_id')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
|
|
|
@ -9,7 +9,10 @@
|
|||
<div class="e-content p-name">
|
||||
{!! $note->note !!}
|
||||
@foreach($note->media()->get() as $media)
|
||||
<img src="{{ $media->url }}" alt="">
|
||||
@if($media->type == 'image')<img class="u-photo" src="{{ $media->url }}" alt="">@endif
|
||||
@if($media->type == 'audio')<audio class="u-audio" src="{{ $media->url }}" controls>@endif
|
||||
@if($media->type == 'video')<video class="u-video" src="{{ $media->url }}" controls>@endif
|
||||
@if($media->type == 'download')<p><a class="u-attachment" href="{{ $media->url }}">Download the attached media</a></p>@endif
|
||||
@endforeach
|
||||
</div>
|
||||
<div class="note-metadata">
|
||||
|
|
Loading…
Add table
Reference in a new issue