KeepDirectoryUploadRequest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace App\Http\Requests\API\File;
  3. use App\Models\Enums\FileObjectType;
  4. use Illuminate\Foundation\Http\FormRequest;
  5. use Illuminate\Validation\Rules\Enum;
  6. use Illuminate\Validation\Rules\File;
  7. class KeepDirectoryUploadRequest extends FormRequest
  8. {
  9. /**
  10. * Determine if the user is authorized to make this request.
  11. */
  12. public function authorize(): bool
  13. {
  14. return true;
  15. }
  16. /**
  17. * Get the validation rules that apply to the request.
  18. *
  19. * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
  20. */
  21. public function rules(): array
  22. {
  23. $rules = [
  24. "files" => "required|array",
  25. "folders" => "required|array",
  26. "object_type" => [
  27. "required",
  28. new Enum(FileObjectType::class),
  29. ],
  30. "object_id" => "min:0",
  31. "names" => "array",
  32. "folder_id" => "min:0",
  33. "uuid" => "max:40"
  34. ];
  35. if (! $this->request->has("object_id")) {
  36. $rules['uuid'] = "required|max:40";
  37. }
  38. $extensions = ['txt', 'jpeg', 'png', 'gif', 'pdf', 'xls', 'xlsx', 'zip', 'wps', 'docx', 'doc'];
  39. if ($this->request->get("object_type") == FileObjectType::CONTAINER->value) {
  40. $extensions = [...$extensions, ...config("bim.extensions")];
  41. }
  42. //$rules['files.*'][] = File::types($extensions)->max("2gb"); // 临时关闭,无法校验rvt文件后缀
  43. return $rules;
  44. }
  45. }