validate($request, [ 'icon' => 'required|image', ]); $icon = $request->file('icon'); $path = $icon instanceof \Illuminate\Http\UploadedFile ? $icon->store('', 'icons') : false; return $path ? response()->json(['filename' => pathinfo($path)['basename']], 201) : response()->json(['message' => __('errors.file_upload_failed')], 500); } /** * Fetch a logo * * @param \Illuminate\Http\Request $request * @param \App\Services\LogoService $logoService * @return \Illuminate\Http\JsonResponse */ public function fetch(Request $request, LogoService $logoService) { $this->validate($request, [ 'service' => 'string|regex:/^[^:]+$/i', ]); $icon = $logoService->getIcon($request->service); return $icon ? response()->json(['filename' => $icon], 201) : response()->json(null, 204); } /** * delete an icon * * @param \Illuminate\Http\Request $request * @param string $icon * @return \Illuminate\Http\JsonResponse */ public function delete(string $icon, Request $request) { // An icon affected to someone else's twofaccount cannot be deleted if ($icon && TwoFAccount::where('icon', $icon)->where('user_id', '<>', $request->user()->id)->count() > 0) { abort(403, 'unauthorized'); } Storage::disk('icons')->delete($icon); return response()->json(null, 204); } }