Mohammad Khazaee
2 years ago
21 changed files with 376 additions and 178 deletions
-
3Dockerfile
-
69app/Http/Controllers/FileController.php
-
9app/Http/Controllers/Traits/FileTrait.php
-
2app/Http/Kernel.php
-
6app/Http/Middleware/BindCollectionModelMiddleware.php
-
14app/Http/Middleware/BindFileModelMiddleware.php
-
73app/Http/Requests/FileStoreRequest.php
-
61app/Image/ImageProcessor.php
-
16app/Models/File.php
-
3app/Models/Traits/Validatable.php
-
2app/Providers/AppServiceProvider.php
-
8config/filesystems.php
-
12database/factories/BaseFactory.php
-
9database/factories/Documents/PolicyDocumentFactory.php
-
1database/factories/FileFactory.php
-
69database/seeders/DatabaseSeeder.php
-
BINpublic/image-modified.webp
-
15routes/api.php
-
17routes/web.php
-
BINstorage/image-modified.webp
-
163tests/Feature/FileStoreTest.php
@ -0,0 +1,73 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Requests; |
|||
|
|||
use App\Models\File; |
|||
use App\Utilities\Polices\BasePolicy; |
|||
use Illuminate\Foundation\Http\FormRequest; |
|||
use Illuminate\Support\Facades\Storage; |
|||
|
|||
class FileStoreRequest extends FormRequest |
|||
{ |
|||
public function isImage($file) |
|||
{ |
|||
if (@is_array(getimagesize($file))) { |
|||
return true; |
|||
} else { |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Determine if the user is authorized to make this request. |
|||
* |
|||
* @return bool |
|||
*/ |
|||
public function authorize() |
|||
{ |
|||
|
|||
if (!app()->collection->tmp_support && !$this->model_id) { |
|||
return false; |
|||
} |
|||
|
|||
if (app()->collection->count !== 1 && (app()->collection->count <= File::where('model_id', auth()->id())->count()) && !app()->collection->tmp_support) { |
|||
|
|||
return false; |
|||
} |
|||
if (!app()->bound('file') && is_null($this->file('file'))) { |
|||
return false; |
|||
} |
|||
|
|||
if (!$this->hasFile('file')) { |
|||
$this->replace([ |
|||
'file' => new \Illuminate\Http\File(Storage::disk(app()->collection->disk)->path(app()->file->server_path . app()->file->uuid . '.' . app()->collection->ext), app()->file->uuid . '.' . app()->collection->ext) |
|||
]); |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
/** |
|||
* Get the validation rules that apply to the request. |
|||
* |
|||
* @return array<string, mixed> |
|||
*/ |
|||
public function rules() |
|||
{ |
|||
return [ |
|||
"file" => [ |
|||
"mimes:" . app()->collection->getExts(), |
|||
"mimetypes:" . app()->collection->getMimeTypes(), |
|||
!$this->isImage(request()->file->path()) ?: "dimensions:min_width=" . app()->collection->min_width . ",min_height=" . app()->collection->min_height . ',max_width=' . app()->collection->max_width . ',max_height=' . app()->collection->max_height, |
|||
"max:" . app()->collection->max_file_size, |
|||
"min:" . app()->collection->min_file_size, |
|||
], |
|||
"alts" => [app()->collection->alt_required ? "required" : "nullable", 'array'], |
|||
"alts.*" => [app()->collection->alt_required ? "required" : "nullable", 'max:1000'], |
|||
"description" => [app()->collection->description_required ? "required" : "nullable", 'max:300'], |
|||
'original_name' => ["string", "nullable", 'max:300'], |
|||
'public' => ['boolean', 'nullable'], |
|||
'published_at' => ['date_format:Y-m-d H:i:s', 'nullable'], |
|||
]; |
|||
} |
|||
} |
Binary file not shown.
Binary file not shown.
Write
Preview
Loading…
Cancel
Save
Reference in new issue