mirror of
https://gh.wpcy.net/https://github.com/aspirepress/AspireCloud.git
synced 2026-07-17 11:37:03 +08:00
* fix: switch redis driver to predis because laravel is hopeless * chore: add spatie/laravel-permission * build: composer update and bump * style: death to captain obvious (zap laravel's banner comments) * feat: initial roles and perms * chore: assign User role on User created * refactor: rename 'aspire_press' config key to 'aspirecloud' * feat: require json content-type on admin api routes * chore: implement BulkImport endpoint * chore: give RepoAdmin users BulkImport permissions * docs: update README
22 lines
778 B
PHP
22 lines
778 B
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Str;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException;
|
|
|
|
class RequireJson
|
|
{
|
|
public function handle(Request $request, Closure $next): Response
|
|
{
|
|
// $request->isJson doesn't accept application/nljson as used by /admin/api/v1/import
|
|
// we'll accept anything with 'json' in it, which should be safe from CSRF in any case
|
|
if ($request->isMethodSafe() || Str::contains($request->headers->get('CONTENT_TYPE') ?? '', 'json')) {
|
|
return $next($request);
|
|
}
|
|
throw new UnsupportedMediaTypeHttpException("Content-Type does not contain 'json'");
|
|
}
|
|
}
|