mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-10 00:34:50 +00:00
Update BaseApiController
This commit is contained in:
parent
0fba6e16a7
commit
31b34570c0
1 changed files with 43 additions and 0 deletions
|
@ -6,8 +6,11 @@ use App\Avatar;
|
||||||
use App\Http\Controllers\AvatarController;
|
use App\Http\Controllers\AvatarController;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Jobs\AvatarPipeline\AvatarOptimize;
|
use App\Jobs\AvatarPipeline\AvatarOptimize;
|
||||||
|
use App\Jobs\ImageOptimizePipeline\ImageOptimize;
|
||||||
|
use App\Media;
|
||||||
use App\Profile;
|
use App\Profile;
|
||||||
use App\Transformer\Api\AccountTransformer;
|
use App\Transformer\Api\AccountTransformer;
|
||||||
|
use App\Transformer\Api\MediaTransformer;
|
||||||
use App\Transformer\Api\StatusTransformer;
|
use App\Transformer\Api\StatusTransformer;
|
||||||
use Auth;
|
use Auth;
|
||||||
use Cache;
|
use Cache;
|
||||||
|
@ -115,4 +118,44 @@ class BaseApiController extends Controller
|
||||||
'msg' => 'Avatar successfully updated',
|
'msg' => 'Avatar successfully updated',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function uploadMedia(Request $request)
|
||||||
|
{
|
||||||
|
$this->validate($request, [
|
||||||
|
'file.*' => function() {
|
||||||
|
return [
|
||||||
|
'required',
|
||||||
|
'mimes:' . config('pixelfed.media_types'),
|
||||||
|
'max:' . config('pixelfed.max_photo_size'),
|
||||||
|
];
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
$user = Auth::user();
|
||||||
|
$profile = $user->profile;
|
||||||
|
$monthHash = hash('sha1', date('Y').date('m'));
|
||||||
|
$userHash = hash('sha1', $user->id.(string) $user->created_at);
|
||||||
|
$photo = $request->file('file');
|
||||||
|
|
||||||
|
$storagePath = "public/m/{$monthHash}/{$userHash}";
|
||||||
|
$path = $photo->store($storagePath);
|
||||||
|
$hash = \hash_file('sha256', $photo);
|
||||||
|
|
||||||
|
$media = new Media();
|
||||||
|
$media->status_id = null;
|
||||||
|
$media->profile_id = $profile->id;
|
||||||
|
$media->user_id = $user->id;
|
||||||
|
$media->media_path = $path;
|
||||||
|
$media->original_sha256 = $hash;
|
||||||
|
$media->size = $photo->getClientSize();
|
||||||
|
$media->mime = $photo->getClientMimeType();
|
||||||
|
$media->filter_class = null;
|
||||||
|
$media->filter_name = null;
|
||||||
|
$media->save();
|
||||||
|
|
||||||
|
ImageOptimize::dispatch($media);
|
||||||
|
$resource = new Fractal\Resource\Item($media, new MediaTransformer());
|
||||||
|
$res = $this->fractal->createData($resource)->toArray();
|
||||||
|
|
||||||
|
return response()->json($res);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue