fix: separate image/video upload limits (10MB/1GB), accept only MP4 video

This commit is contained in:
Paulo Castellano 2026-03-31 22:13:04 -03:00
parent 0cf84e4424
commit 307b496bad

View file

@ -22,12 +22,14 @@ public function authorize(): bool
public function rules(): array
{
$maxSize = $this->isVideoUpload() ? 1048576 : 10240; // Videos: 1GB, Images: 10MB
return [
'media' => [
'required',
'file',
'max:1048576', // 1GB
'mimetypes:image/jpeg,image/png,image/gif,image/webp,video/mp4,video/quicktime,video/webm,application/pdf',
"max:{$maxSize}",
'mimetypes:image/jpeg,image/png,image/gif,image/webp,video/mp4',
],
'model' => [
'required',
@ -50,11 +52,16 @@ public function messages(): array
{
return [
'media.required' => 'The file is required.',
'media.max' => 'The file must be at most 1GB.',
'media.max' => $this->isVideoUpload() ? 'Videos must be at most 1GB.' : 'Images must be at most 10MB.',
'media.mimetypes' => 'File type not supported.',
'model.required' => 'The model is required.',
'model.in' => 'Invalid model type.',
'model_id.required' => 'The model ID is required.',
];
}
private function isVideoUpload(): bool
{
return str_starts_with($this->file('media')?->getMimeType() ?? '', 'video/');
}
}