Files
AndyTranscribe/app/Http/Requests/StoreRecordingRequest.php
T
ben bfcfc12f58 Add Fortify auth, Flux dark mode, demo seed, and Docker hot reload.
Protect recordings per user, seed a demo login on container start, and bind-mount the app with Vite HMR for local Compose development.
2026-08-12 18:38:53 +02:00

83 lines
2.1 KiB
PHP

<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\UploadedFile;
use Illuminate\Validation\Rules\File;
class StoreRecordingRequest extends FormRequest
{
/**
* Popular audio extensions Whisper-compatible providers typically accept.
*
* @var list<string>
*/
public const AUDIO_EXTENSIONS = [
'mp3',
'mpeg',
'mpga',
'wav',
'ogg',
'oga',
'flac',
'm4a',
'mp4',
'aac',
'webm',
'wma',
'aiff',
'aif',
];
/**
* Maximum upload size accepted by validation (2 GiB).
*/
public const MAX_AUDIO_KILOBYTES = 2 * 1024 * 1024;
public function authorize(): bool
{
return $this->user() !== null;
}
/**
* Normalize a single file upload into an array for batch handling.
*/
protected function prepareForValidation(): void
{
if ($this->hasFile('audio') && $this->file('audio') instanceof UploadedFile) {
$this->files->set('audio', [$this->file('audio')]);
}
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'audio' => ['required', 'array', 'min:1', 'max:50'],
'audio.*' => [
'required',
File::types(self::AUDIO_EXTENSIONS)->max('2gb'),
],
'title' => ['nullable', 'string', 'max:255'],
];
}
/**
* @return array<string, string>
*/
public function messages(): array
{
return [
'audio.required' => 'Please choose at least one audio file to upload.',
'audio.min' => 'Please choose at least one audio file to upload.',
'audio.max' => 'You can upload at most 50 files at once.',
'audio.*.required' => 'Please choose an audio file to upload.',
'audio.*' => 'Unsupported audio type. Use MP3, WAV, OGG, FLAC, M4A, AAC, WebM, WMA, or AIFF.',
'audio.*.max' => 'Each audio file may not be larger than 2 GB.',
];
}
}