2018-04-16 01:26:48 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2019-08-30 02:09:10 +00:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Auth, Storage, URL;
|
|
|
|
use App\Media;
|
|
|
|
use Image as Intervention;
|
|
|
|
use App\Jobs\ImageOptimizePipeline\ImageOptimize;
|
|
|
|
|
2018-04-16 01:26:48 +00:00
|
|
|
class MediaController extends Controller
|
|
|
|
{
|
2019-08-30 02:09:10 +00:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->middleware('auth');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function index(Request $request)
|
|
|
|
{
|
|
|
|
//return view('settings.drive.index');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function composeUpdate(Request $request, $id)
|
|
|
|
{
|
|
|
|
$this->validate($request, [
|
|
|
|
'file' => function() {
|
|
|
|
return [
|
|
|
|
'required',
|
|
|
|
'mimes:' . config('pixelfed.media_types'),
|
|
|
|
'max:' . config('pixelfed.max_photo_size'),
|
|
|
|
];
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
$user = Auth::user();
|
|
|
|
|
|
|
|
$photo = $request->file('file');
|
|
|
|
|
|
|
|
$media = Media::whereUserId($user->id)
|
|
|
|
->whereProfileId($user->profile_id)
|
|
|
|
->whereNull('status_id')
|
|
|
|
->findOrFail($id);
|
|
|
|
|
|
|
|
$fragments = explode('/', $media->media_path);
|
|
|
|
$name = last($fragments);
|
|
|
|
array_pop($fragments);
|
|
|
|
$dir = implode('/', $fragments);
|
|
|
|
$path = $photo->storeAs($dir, $name);
|
|
|
|
$res = [];
|
|
|
|
$res['url'] = URL::temporarySignedRoute(
|
2019-10-17 04:09:24 +00:00
|
|
|
'temp-media', now()->addHours(1), ['profileId' => $media->profile_id, 'mediaId' => $media->id, 'timestamp' => time()]
|
2019-08-30 02:09:10 +00:00
|
|
|
);
|
|
|
|
ImageOptimize::dispatch($media);
|
|
|
|
return $res;
|
|
|
|
|
|
|
|
}
|
2018-04-16 01:26:48 +00:00
|
|
|
}
|