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();