diff --git a/app/Http/Controllers/CollectionController.php b/app/Http/Controllers/CollectionController.php new file mode 100644 index 0000000..f389947 --- /dev/null +++ b/app/Http/Controllers/CollectionController.php @@ -0,0 +1,36 @@ +all()); + return new CollectionResource($collection); + } + + public function update(Request $request, Collection $collection) + { + $collection->update($request->all()); + return new CollectionResource($collection); + } + + public function destroy(Collection $collection) + { + if ($collection->trashed()) { + return $collection->restore(); + } + return $collection->delete(); + } +} diff --git a/app/Http/Controllers/FileController.php b/app/Http/Controllers/FileController.php new file mode 100644 index 0000000..d5cd5be --- /dev/null +++ b/app/Http/Controllers/FileController.php @@ -0,0 +1,30 @@ +collection = Collection::where('name',$this->collection_name)->get(); + } + + /** + * Determine if the user is authorized to make this request. + * + * @return bool + */ + public function authorize() + { + return true; + } + + private function getExts() + { + return implode(",",$this->collection->exts); + } + + private function getMimeTypes() + { + return implode(",",$this->collection->mimetypes); + } + + // private function getExt() + // { + // return implode(",",$this->collection->ext); + // } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules() + { + return [ + "ext" => ["mimes:" . $this->getExts], + "memetype" => ["mimetypes:" . $this->getMimeTypes], + "width"=> [''], + "height"=> [''], + "file_size"=> [''], + ]; + } +} diff --git a/app/Http/Resources/CollectionResource.php b/app/Http/Resources/CollectionResource.php new file mode 100644 index 0000000..a855bcf --- /dev/null +++ b/app/Http/Resources/CollectionResource.php @@ -0,0 +1,44 @@ + $this->id, + "name" => $this->name, + "public" => $this->public, + "disk" => $this->disk, + "count" => $this->count, + "tmp_support" => $this->tmp_support, + "remove_tmp_time" => $this->remove_tmp_time, + "max_file_size" => $this->max_file_size, + "min_file_size" => $this->min_file_size, + "max_width" => $this->max_width, + "min_width" => $this->min_width, + "max_height" => $this->max_height, + "min_height" => $this->min_height, + "alt_required" => $this->alt_required, + "description_required" => $this->description_required, + "count" => $this->count, + "exts" => $this->exts, + "avalible_exts" => $this->avalible_exts, + "memetypes" => $this->memetypes, + "model" => $this->model, + "expire_date" => $this->expire_date, + "created_at" => $this->created_at, + "updated_at" => $this->updated_at, + "deleted_at" => $this->deleted_at + ]; + } +} diff --git a/app/Http/Resources/FileResource.php b/app/Http/Resources/FileResource.php new file mode 100644 index 0000000..8a3d851 --- /dev/null +++ b/app/Http/Resources/FileResource.php @@ -0,0 +1,37 @@ + $this->uuid, + "original_name" => $this->original_name, + "ext" => $this->ext, + "memetype" => $this->memetype, + "width" => $this->width, + "height" => $this->height, + "file_size" => $this->file_size, + "sort" => $this->sort, + "alts" => $this->alts, + "description" => $this->description, + "user_id" => $this->user_id, + "ip" => $this->ip, + "collection_id" => $this->collection_id, + "published_at" => $this->published_at, + "created_at" => $this->created_at, + "updated_at" => $this->updated_at, + "deleted_at" => $this->deleted_at, + ]; + } +} diff --git a/app/Models/Collection.php b/app/Models/Collection.php new file mode 100644 index 0000000..0f77ea0 --- /dev/null +++ b/app/Models/Collection.php @@ -0,0 +1,62 @@ + 'array', + 'avalible_exts' => 'array', + 'memetypes' => 'array', + ]; + + protected function exts(): Attribute + { + return Attribute::make( + set: fn ($value) => json_encode($value), + ); + } + protected function avalible_exts(): Attribute + { + return Attribute::make( + set: fn ($value) => json_encode($value), + ); + } + protected function memetypes(): Attribute + { + return Attribute::make( + set: fn ($value) => json_encode($value), + ); + } + +} diff --git a/app/Models/File.php b/app/Models/File.php new file mode 100644 index 0000000..e34f328 --- /dev/null +++ b/app/Models/File.php @@ -0,0 +1,55 @@ + 'array', + ]; + + protected function uuid(): Attribute + { + return Attribute::make( + set: fn ($value) => Str::uuid(), + ); + } + + + protected function alts(): Attribute + { + return Attribute::make( + set: fn ($value) => json_encode($value), + ); + } + +} diff --git a/database/factories/CollectionFactory.php b/database/factories/CollectionFactory.php new file mode 100644 index 0000000..80bdf20 --- /dev/null +++ b/database/factories/CollectionFactory.php @@ -0,0 +1,57 @@ + + */ +class CollectionFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition() + { + return [ + "name" => fake()->name(), + "public" => "public", + "disk" => "local", + "count" => rand(3,18), + "tmp_support" => rand(0,1), + "remove_tmp_time" => 132, + "max_file_size" => rand(300,2000), + "min_file_size" => rand(300,2000), + "max_width" => rand(300,2000), + "min_width" => rand(300,2000), + "max_height" => rand(300,2000), + "min_height" => rand(300,2000), + "alt_required" => rand(0,1), + "description_required" => rand(0,1), + "exts" => [ + "jpg", + "jpeg", + "png", + "webp" + ], + "avalible_exts" => [ + "jpg", + "jpeg", + "png", + "webp" + ], + "memetypes" => [ + "jpg", + "jpeg", + "png", + "webp" + ], + "model" => fake()->name(), + "expire_date" => "2022-07-27 09:17:59" + ]; + } +} diff --git a/database/factories/FileFactory.php b/database/factories/FileFactory.php new file mode 100644 index 0000000..22a7549 --- /dev/null +++ b/database/factories/FileFactory.php @@ -0,0 +1,41 @@ + + */ +class FileFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition() + { + return [ + "uuid" => 1, + "original_name" => fake()->name(), + "ext" => ['jpg', 'jpeg', 'png', 'webp'][rand(0, 3)], + "memetype" => 'image', + "width" => rand(300, 2000), + "height" => rand(300, 2000), + "file_size" => rand(300, 2000), + "server_path" => date('y') . '/' . date('m'), + "sort" => rand(0, 23), + "alts" => [ + 'hello wroldswdfouiwref iuwrhgf ow rgfaw ghfawej', + 'jhsf asduyfsadf sadf safsuf isfjsdfsudifsduiyf sdiuf sd' + ], + "description" => 'ajsfoisahjfoaspf asduf safsafjsh lh', + "user_id" => rand(43724, 382348), + "ip" => "127.0. 0.1", + "collection_id" => Collection::factory()->create()->id, + "published_at" => "2022-07-27 09:17:59", + ]; + } +} diff --git a/database/migrations/2022_07_27_073858_create_files_table.php b/database/migrations/2022_07_27_073858_create_files_table.php new file mode 100644 index 0000000..570fb5a --- /dev/null +++ b/database/migrations/2022_07_27_073858_create_files_table.php @@ -0,0 +1,46 @@ +uuid('uuid')->primary(); + $table->string("original_name")->nullable(); + $table->string("ext"); + $table->string("mimetype"); + $table->string("server_path"); + $table->bigInteger("width")->nullable(); + $table->bigInteger("height")->nullable(); + $table->bigInteger("file_size")->nullable(); + $table->bigInteger("sort")->nullable(); + $table->json("alts")->nullable(); + $table->string("description")->nullable(); + $table->unsignedBigInteger("user_id")->nullable(); + $table->string("ip")->nullable(); + $table->unsignedBigInteger("collection_id")->nullable(); + $table->timestamp("published_at")->nullable(); + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('files'); + } +}; diff --git a/database/migrations/2022_07_27_073906_create_collections_table.php b/database/migrations/2022_07_27_073906_create_collections_table.php new file mode 100644 index 0000000..328f0e4 --- /dev/null +++ b/database/migrations/2022_07_27_073906_create_collections_table.php @@ -0,0 +1,52 @@ +id(); + $table->string("name")->nullable()->unique(); + $table->string("path")->nullable(); + $table->string("public")->nullable(); + $table->string("disk")->nullable(); + $table->integer("count")->nullable(); + $table->boolean("tmp_support")->nullable(); + $table->time("remove_tmp_time")->nullable(); + $table->integer("max_file_size")->nullable(); + $table->integer("min_file_size")->nullable(); + $table->integer("max_width")->nullable(); + $table->integer("min_width")->nullable(); + $table->integer("max_height")->nullable(); + $table->integer("min_height")->nullable(); + $table->boolean("alt_required")->nullable(); + $table->boolean("description_required")->nullable(); + $table->json("exts")->nullable(); + $table->json("avalible_exts")->nullable(); + $table->json("mimetypes")->nullable(); + $table->string("model")->unique()->nullable(); + $table->timestamp("expire_date")->nullable(); + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('collections'); + } +}; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index c1c48a0..22e5279 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -20,5 +20,8 @@ class DatabaseSeeder extends Seeder // 'name' => 'Test User', // 'email' => 'test@example.com', // ]); + + \App\Models\Collection::factory(10)->create(); + \App\Models\File::factory(1)->create(); } } diff --git a/public/image-modified.png b/public/image-modified.png index 464d5a0..96e5ca4 100644 Binary files a/public/image-modified.png and b/public/image-modified.png differ diff --git a/public/image-modified.webp b/public/image-modified.webp index fa30048..72b2702 100644 Binary files a/public/image-modified.webp and b/public/image-modified.webp differ diff --git a/resources/views/welcome.blade.php b/resources/views/welcome.blade.php index dd6a45d..c002ac3 100644 --- a/resources/views/welcome.blade.php +++ b/resources/views/welcome.blade.php @@ -21,112 +21,12 @@ -
- @if (Route::has('login')) - - @endif - -
-
- - - - - -
- -
-
-
- - -
-
- Laravel has wonderful, thorough documentation covering every aspect of the framework. Whether you are new to the framework or have previous experience with Laravel, we recommend reading all of the documentation from beginning to end. -
-
-
- -
-
- - -
- -
-
- Laracasts offers thousands of video tutorials on Laravel, PHP, and JavaScript development. Check them out, see for yourself, and massively level up your development skills in the process. -
-
-
- -
-
- - -
- -
-
- Laravel News is a community driven portal and newsletter aggregating all of the latest and most important news in the Laravel ecosystem, including new package releases and tutorials. -
-
-
- -
-
- -
Vibrant Ecosystem
-
- -
-
- Laravel's robust library of first-party tools and libraries, such as Forge, Vapor, Nova, and Envoyer help you take your projects to the next level. Pair them with powerful open source libraries like Cashier, Dusk, Echo, Horizon, Sanctum, Telescope, and more. -
-
-
-
-
- -
-
-
- - - - - - Shop - - - - - - - - Sponsor - -
-
- -
- Laravel v{{ Illuminate\Foundation\Application::VERSION }} (PHP v{{ PHP_VERSION }}) -
-
-
-
+
+ @csrf + +
+ +
diff --git a/routes/api.php b/routes/api.php index eb6fa48..4669c61 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,6 +1,7 @@ get('/user', function (Request $request) { - return $request->user(); -}); +// Route::middleware('auth:sanctum')->get('/user', function (Request $request) { +// return $request->user(); +// }); + + +Route::apiResource('collections',CollectionController::class); +Route::delete('/collections/{collection}',[CollectionController::class,"destroy"])->withTrashed(); +Route::post('{collection_name}/{?model_name}',[FileController::class,'store']); diff --git a/routes/web.php b/routes/web.php index dddd38b..655f21f 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,10 +1,13 @@ dddd = 'tesst'; // dump($request->); @@ -66,7 +69,7 @@ Route::get('/image.{ext}', function (Request $request) { $widthH, $request->w, $request->h, - ['extend' => 'white'] + ['extend' => 'background','background'=>1024] ); } @@ -91,9 +94,17 @@ Route::get('/image.{ext}', function (Request $request) { $image = $image->flipver(); } - $image->writeToFile('image-modified.' . $request->ext, [ + + $image->writeToFile('image-modified.webp', [ 'Q' => isset($request->q) ? $request->q : 100 ]); - return response()->file(public_path("image-modified." . $request->ext)); + return response()->file(public_path("image-modified.webp" . $request->ext)); }); + + +Route::get('/upload',function(){ +return view('welcome'); +}); + +Route::post('/upload',[FileController::class,'store']);