From 3f0ad3ffe2c3e192091a026644fe60a3ab46fa69 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 13 Jun 2018 17:14:10 -0600 Subject: [PATCH] Update StatusController, support multiple uploads --- app/Http/Controllers/StatusController.php | 42 ++++++++++++------- app/Jobs/StatusPipeline/NewStatusPipeline.php | 11 ++--- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/app/Http/Controllers/StatusController.php b/app/Http/Controllers/StatusController.php index 4e5c2e8d4..1ce080245 100644 --- a/app/Http/Controllers/StatusController.php +++ b/app/Http/Controllers/StatusController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers; use Auth, Cache; use App\Jobs\StatusPipeline\{NewStatusPipeline, StatusDelete}; +use App\Jobs\ImageOptimizePipeline\ImageOptimize; use Illuminate\Http\Request; use App\{Media, Profile, Status, User}; use Vinkla\Hashids\Facades\Hashids; @@ -14,7 +15,7 @@ class StatusController extends Controller { $user = Profile::whereUsername($username)->firstOrFail(); $status = Status::whereProfileId($user->id) - ->withCount(['likes', 'comments']) + ->withCount(['likes', 'comments', 'media']) ->findOrFail($id); if(!$status->media_path && $status->in_reply_to_id) { return redirect($status->url()); @@ -32,16 +33,16 @@ class StatusController extends Controller $user = Auth::user(); $this->validate($request, [ - 'photo' => 'required|mimes:jpeg,png,bmp,gif|max:' . config('pixelfed.max_photo_size'), + 'photo.*' => 'required|mimes:jpeg,png,bmp,gif|max:' . config('pixelfed.max_photo_size'), 'caption' => 'string|max:' . config('pixelfed.max_caption_length'), - 'cw' => 'nullable|string' + 'cw' => 'nullable|string', + 'filter_class' => 'nullable|string', + 'filter_name' => 'nullable|string', ]); $cw = $request->filled('cw') && $request->cw == 'on' ? true : false; $monthHash = hash('sha1', date('Y') . date('m')); $userHash = hash('sha1', $user->id . (string) $user->created_at); - $storagePath = "public/m/{$monthHash}/{$userHash}"; - $path = $request->photo->store($storagePath); $profile = $user->profile; $status = new Status; @@ -51,17 +52,28 @@ class StatusController extends Controller $status->save(); - $media = new Media; - $media->status_id = $status->id; - $media->profile_id = $profile->id; - $media->user_id = $user->id; - $media->media_path = $path; - $media->size = $request->file('photo')->getClientSize(); - $media->mime = $request->file('photo')->getClientMimeType(); - $media->save(); - NewStatusPipeline::dispatch($status, $media); + $photos = $request->file('photo'); + $order = 1; + foreach ($photos as $k => $v) { + $storagePath = "public/m/{$monthHash}/{$userHash}"; + $path = $v->store($storagePath); + $media = new Media; + $media->status_id = $status->id; + $media->profile_id = $profile->id; + $media->user_id = $user->id; + $media->media_path = $path; + $media->size = $v->getClientSize(); + $media->mime = $v->getClientMimeType(); + $media->filter_class = $request->input('filter_class'); + $media->filter_name = $request->input('filter_name'); + $media->order = $order; + $media->save(); + ImageOptimize::dispatch($media); + $order++; + } + + NewStatusPipeline::dispatch($status); - // TODO: Parse Caption // TODO: Send to subscribers return redirect($status->url()); diff --git a/app/Jobs/StatusPipeline/NewStatusPipeline.php b/app/Jobs/StatusPipeline/NewStatusPipeline.php index 01392aa47..8939dd9ad 100644 --- a/app/Jobs/StatusPipeline/NewStatusPipeline.php +++ b/app/Jobs/StatusPipeline/NewStatusPipeline.php @@ -16,17 +16,15 @@ class NewStatusPipeline implements ShouldQueue use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; protected $status; - protected $media; /** * Create a new job instance. * * @return void */ - public function __construct(Status $status, $media = false) + public function __construct(Status $status) { $this->status = $status; - $this->media = $media; } /** @@ -37,13 +35,10 @@ class NewStatusPipeline implements ShouldQueue public function handle() { $status = $this->status; - $media = $this->media; StatusEntityLexer::dispatch($status); - StatusActivityPubDeliver::dispatch($status); - if($media) { - ImageOptimize::dispatch($media); - } + //StatusActivityPubDeliver::dispatch($status); + Cache::forever('post.' . $status->id, $status); $redis = Redis::connection();