mirror of
				https://github.com/pelican-dev/panel.git
				synced 2025-10-31 21:16:51 +01:00 
			
		
		
		
	 e313dff674
			
		
	
	
		e313dff674
		
			
		
	
	
	
	
		
			
			Changes the API internals to use normal Laravel binding which automatically supports nested-models and can determine their relationships. This removes a lot of confusingly complex internal logic and replaces it with standard Laravel code. This also removes a deprecated "getModel" method and fully replaces it with a "parameter" method that does stricter type-checking.
		
			
				
	
	
		
			32 lines
		
	
	
		
			1018 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			32 lines
		
	
	
		
			1018 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace Pterodactyl\Http\Middleware\Api;
 | |
| 
 | |
| use Closure;
 | |
| use JsonException;
 | |
| use Illuminate\Http\Request;
 | |
| use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
 | |
| 
 | |
| class IsValidJson
 | |
| {
 | |
|     /**
 | |
|      * Throw an exception if the request should be valid JSON data but there is an error while
 | |
|      * parsing the data. This avoids confusing validation errors where every field is flagged and
 | |
|      * it is not immediately clear that there is an issue with the JSON being passed.
 | |
|      *
 | |
|      * @return mixed
 | |
|      */
 | |
|     public function handle(Request $request, Closure $next)
 | |
|     {
 | |
|         if ($request->isJson() && !empty($request->getContent())) {
 | |
|             try {
 | |
|                 json_decode($request->getContent(), true, 512, JSON_THROW_ON_ERROR);
 | |
|             } catch (JsonException $exception) {
 | |
|                 throw new BadRequestHttpException('The JSON data passed in the request appears to be malformed: ' . $exception->getMessage());
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         return $next($request);
 | |
|     }
 | |
| }
 |