mirror of
https://github.com/YunoHost-Apps/pixelfed_ynh.git
synced 2024-09-03 20:06:04 +02:00
Update MediaController, add update method
This commit is contained in:
parent
cdb3162661
commit
0416843723
1 changed files with 51 additions and 1 deletions
|
@ -2,7 +2,57 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Auth, Storage, URL;
|
||||||
|
use App\Media;
|
||||||
|
use Image as Intervention;
|
||||||
|
use App\Jobs\ImageOptimizePipeline\ImageOptimize;
|
||||||
|
|
||||||
class MediaController extends Controller
|
class MediaController extends Controller
|
||||||
{
|
{
|
||||||
//
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->middleware('auth');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index(Request $request)
|
||||||
|
{
|
||||||
|
//return view('settings.drive.index');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function composeUpdate(Request $request, $id)
|
||||||
|
{
|
||||||
|
ini_set('memory_limit', '1024M');
|
||||||
|
$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(
|
||||||
|
'temp-media', now()->addHours(1), ['profileId' => $media->profile_id, 'mediaId' => $media->id]
|
||||||
|
);
|
||||||
|
ImageOptimize::dispatch($media);
|
||||||
|
return $res;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue