Merge pull request #1925 from pixelfed/staging

Update StoryController
This commit is contained in:
daniel 2020-01-10 19:49:56 -07:00 committed by GitHub
commit 2461fe905c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -26,7 +26,7 @@ class StoryController extends Controller
abort_if(!config('instance.stories.enabled') || !$request->user(), 404);
$this->validate($request, [
'file.*' => function() {
'file' => function() {
return [
'required',
'mimes:image/jpeg,image/png',
@ -41,13 +41,8 @@ class StoryController extends Controller
abort(400, 'You have reached your limit for new Stories today.');
}
$story = new Story();
$story->duration = 3;
$story->profile_id = $user->profile_id;
$story->expires_at = now()->addHours(24);
$story->save();
$monthHash = substr(hash('sha1', date('Y').date('m')), 0, 12);
$sid = Str::uuid();
$rid = Str::random(6).'.'.Str::random(9);
$photo = $request->file('file');
@ -61,11 +56,17 @@ class StoryController extends Controller
return;
}
$storagePath = "public/_esm.t1/{$monthHash}/{$story->id}/{$rid}";
$storagePath = "public/_esm.t1/{$monthHash}/{$sid}/{$rid}";
$path = $photo->store($storagePath);
$story = new Story();
$story->duration = 3;
$story->profile_id = $user->profile_id;
$story->type = 'photo';
$story->mime = $photo->getMimeType();
$story->path = $path;
$story->local = true;
$story->size = $photo->getClientSize();
$story->expires_at = now()->addHours(24);
$story->save();