mirror of
https://github.com/koel/koel
synced 2024-11-10 14:44:13 +00:00
Refactor and fix requests
This commit is contained in:
parent
86cd0fbb4f
commit
453fb76c5d
25 changed files with 59 additions and 317 deletions
|
@ -7,22 +7,7 @@ namespace App\Http\Requests\API;
|
|||
*/
|
||||
class BatchInteractionRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'songs' => 'required|array',
|
||||
|
|
|
@ -6,18 +6,8 @@ use App\Http\Requests\API\Request as BaseRequest;
|
|||
|
||||
class Request extends BaseRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
public function authorize(): bool
|
||||
{
|
||||
return config('koel.download.allow');
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,12 +7,7 @@ namespace App\Http\Requests\API\Download;
|
|||
*/
|
||||
class SongRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'songs' => 'required|array',
|
||||
|
|
9
app/Http/Requests/API/Interaction/Request.php
Normal file
9
app/Http/Requests/API/Interaction/Request.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\API\Interaction;
|
||||
|
||||
use App\Http\Requests\API\Request as BaseRequest;
|
||||
|
||||
class Request extends BaseRequest
|
||||
{
|
||||
}
|
|
@ -2,29 +2,14 @@
|
|||
|
||||
namespace App\Http\Requests\API\Interaction;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use App\Http\Requests\API\Request;
|
||||
|
||||
/**
|
||||
* @property string song
|
||||
*/
|
||||
class StorePlayCountRequest extends FormRequest
|
||||
class StorePlayCountRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'song' => 'required',
|
||||
|
|
|
@ -2,29 +2,12 @@
|
|||
|
||||
namespace App\Http\Requests\API;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
* @property string token
|
||||
*/
|
||||
class LastfmCallbackRequest extends FormRequest
|
||||
class LastfmCallbackRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'token' => 'required',
|
||||
|
|
|
@ -2,29 +2,12 @@
|
|||
|
||||
namespace App\Http\Requests\API;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
* @property string key
|
||||
*/
|
||||
class LastfmSetSessionKeyRequest extends FormRequest
|
||||
class LastfmSetSessionKeyRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'key' => 'required',
|
||||
|
|
|
@ -6,17 +6,7 @@ use App\Http\Requests\API\Request as BaseRequest;
|
|||
|
||||
class Request extends BaseRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules()
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'bucket' => 'required',
|
||||
|
|
|
@ -11,7 +11,7 @@ use App\Http\Requests\API\ObjectStorage\S3\Request as BaseRequest;
|
|||
*/
|
||||
class PutSongRequest extends BaseRequest
|
||||
{
|
||||
public function rules()
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'bucket' => 'required',
|
||||
|
|
|
@ -10,7 +10,7 @@ use App\Http\Requests\API\ObjectStorage\S3\Request as BaseRequest;
|
|||
*/
|
||||
class RemoveSongRequest extends BaseRequest
|
||||
{
|
||||
public function rules()
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'bucket' => 'required',
|
||||
|
|
|
@ -7,22 +7,7 @@ namespace App\Http\Requests\API;
|
|||
*/
|
||||
class PlaylistStoreRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => 'required',
|
||||
|
|
|
@ -2,29 +2,12 @@
|
|||
|
||||
namespace App\Http\Requests\API;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
* @property string songs
|
||||
*/
|
||||
class PlaylistSyncRequest extends FormRequest
|
||||
class PlaylistSyncRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'songs' => 'required',
|
||||
|
|
|
@ -7,22 +7,7 @@ namespace App\Http\Requests\API;
|
|||
*/
|
||||
class ProfileUpdateRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => 'required',
|
||||
|
|
|
@ -2,9 +2,8 @@
|
|||
|
||||
namespace App\Http\Requests\API;
|
||||
|
||||
use App\Http\Requests\Request as BaseRequest;
|
||||
use App\Http\Requests\AbstractRequest;
|
||||
|
||||
class Request extends BaseRequest
|
||||
class Request extends AbstractRequest
|
||||
{
|
||||
//
|
||||
}
|
||||
|
|
|
@ -7,22 +7,12 @@ namespace App\Http\Requests\API;
|
|||
*/
|
||||
class SettingRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth()->user()->is_admin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'media_path' => 'string|required|path.valid',
|
||||
|
|
|
@ -9,25 +9,4 @@ use App\Models\Song;
|
|||
*/
|
||||
class SongLikeRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,31 +2,9 @@
|
|||
|
||||
namespace App\Http\Requests\API;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
* @property float time
|
||||
*/
|
||||
class SongPlayRequest extends FormRequest
|
||||
class SongPlayRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,22 +8,12 @@ namespace App\Http\Requests\API;
|
|||
*/
|
||||
class SongUpdateRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()->is_admin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'data' => 'required|array',
|
||||
|
|
|
@ -4,22 +4,7 @@ namespace App\Http\Requests\API;
|
|||
|
||||
class UserLoginRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'email' => 'required|email',
|
||||
|
|
|
@ -9,22 +9,12 @@ namespace App\Http\Requests\API;
|
|||
*/
|
||||
class UserStoreRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth()->user()->is_admin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => 'required',
|
||||
|
|
|
@ -7,22 +7,12 @@ namespace App\Http\Requests\API;
|
|||
*/
|
||||
class UserUpdateRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth()->user()->is_admin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => 'required',
|
||||
|
|
|
@ -2,29 +2,12 @@
|
|||
|
||||
namespace App\Http\Requests\API;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
* @property string q
|
||||
*/
|
||||
class ViewSongOnITunesRequest extends FormRequest
|
||||
class ViewSongOnITunesRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'q' => 'required',
|
||||
|
|
|
@ -2,32 +2,9 @@
|
|||
|
||||
namespace App\Http\Requests\API;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
* @property string pageToken
|
||||
*/
|
||||
class YouTubeSearchRequest extends FormRequest
|
||||
class YouTubeSearchRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
18
app/Http/Requests/AbstractRequest.php
Normal file
18
app/Http/Requests/AbstractRequest.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
abstract class AbstractRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
abstract class Request extends FormRequest
|
||||
{
|
||||
//
|
||||
}
|
Loading…
Reference in a new issue