Update StatusController, support multiple uploads

This commit is contained in:
Daniel Supernault 2018-06-13 17:14:10 -06:00
parent 25bf33e64a
commit 3f0ad3ffe2
2 changed files with 30 additions and 23 deletions

View file

@ -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();
$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 = $request->file('photo')->getClientSize();
$media->mime = $request->file('photo')->getClientMimeType();
$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();
NewStatusPipeline::dispatch($status, $media);
ImageOptimize::dispatch($media);
$order++;
}
NewStatusPipeline::dispatch($status);
// TODO: Parse Caption
// TODO: Send to subscribers
return redirect($status->url());

View file

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