Update StoryController, allow video stories

This commit is contained in:
Daniel Supernault 2020-07-14 17:15:18 -06:00
parent af87bf5038
commit b3b220b9b3
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -24,7 +24,7 @@ class StoryController extends Controller
'file' => function() { 'file' => function() {
return [ return [
'required', 'required',
'mimes:image/jpeg,image/png', 'mimes:image/jpeg,image/png,video/mp4',
'max:' . config('pixelfed.max_photo_size'), 'max:' . config('pixelfed.max_photo_size'),
]; ];
}, },
@ -42,7 +42,7 @@ class StoryController extends Controller
$story = new Story(); $story = new Story();
$story->duration = 3; $story->duration = 3;
$story->profile_id = $user->profile_id; $story->profile_id = $user->profile_id;
$story->type = 'photo'; $story->type = Str::endsWith($photo->getMimeType(), 'mp4') ? 'video' :'photo';
$story->mime = $photo->getMimeType(); $story->mime = $photo->getMimeType();
$story->path = $path; $story->path = $path;
$story->local = true; $story->local = true;
@ -65,7 +65,8 @@ class StoryController extends Controller
$mimes = explode(',', config('pixelfed.media_types')); $mimes = explode(',', config('pixelfed.media_types'));
if(in_array($photo->getMimeType(), [ if(in_array($photo->getMimeType(), [
'image/jpeg', 'image/jpeg',
'image/png' 'image/png',
'video/mp4'
]) == false) { ]) == false) {
abort(400, 'Invalid media type'); abort(400, 'Invalid media type');
return; return;
@ -73,11 +74,13 @@ class StoryController extends Controller
$storagePath = "public/_esm.t2/{$monthHash}/{$sid}/{$rid}"; $storagePath = "public/_esm.t2/{$monthHash}/{$sid}/{$rid}";
$path = $photo->store($storagePath); $path = $photo->store($storagePath);
if(in_array($photo->getMimeType(), ['image/jpeg','image/png',])) {
$fpath = storage_path('app/' . $path); $fpath = storage_path('app/' . $path);
$img = Intervention::make($fpath); $img = Intervention::make($fpath);
$img->orientate(); $img->orientate();
$img->save($fpath, config('pixelfed.image_quality')); $img->save($fpath, config('pixelfed.image_quality'));
$img->destroy(); $img->destroy();
}
return $path; return $path;
} }
@ -164,7 +167,7 @@ class StoryController extends Controller
->map(function($s, $k) { ->map(function($s, $k) {
return [ return [
'id' => (string) $s->id, 'id' => (string) $s->id,
'type' => 'photo', 'type' => Str::endsWith($s->path, '.mp4') ? 'video' :'photo',
'length' => 3, 'length' => 3,
'src' => url(Storage::url($s->path)), 'src' => url(Storage::url($s->path)),
'preview' => null, 'preview' => null,
@ -198,7 +201,7 @@ class StoryController extends Controller
$res = [ $res = [
'id' => (string) $story->id, 'id' => (string) $story->id,
'type' => 'photo', 'type' => Str::endsWith($story->path, '.mp4') ? 'video' :'photo',
'length' => 3, 'length' => 3,
'src' => url(Storage::url($story->path)), 'src' => url(Storage::url($story->path)),
'preview' => null, 'preview' => null,
@ -233,7 +236,7 @@ class StoryController extends Controller
->map(function($s, $k) { ->map(function($s, $k) {
return [ return [
'id' => $s->id, 'id' => $s->id,
'type' => 'photo', 'type' => Str::endsWith($s->path, '.mp4') ? 'video' :'photo',
'length' => 3, 'length' => 3,
'src' => url(Storage::url($s->path)), 'src' => url(Storage::url($s->path)),
'preview' => null, 'preview' => null,
@ -315,7 +318,7 @@ class StoryController extends Controller
->map(function($s, $k) { ->map(function($s, $k) {
return [ return [
'id' => $s->id, 'id' => $s->id,
'type' => 'photo', 'type' => Str::endsWith($s->path, '.mp4') ? 'video' :'photo',
'length' => 3, 'length' => 3,
'src' => url(Storage::url($s->path)), 'src' => url(Storage::url($s->path)),
'preview' => null, 'preview' => null,