diff --git a/database/factories/ZipFactory.php b/database/factories/ZipFactory.php deleted file mode 100644 index a07ff6a0..00000000 --- a/database/factories/ZipFactory.php +++ /dev/null @@ -1,32 +0,0 @@ - $this->faker->uuid, - 'user_id' => $this->faker->uuid, - 'shared_token' => Str::random(16), - 'basename' => $this->faker->word, - ]; - } -} diff --git a/routes/file.php b/routes/file.php index adabd4fe..e96e58b4 100644 --- a/routes/file.php +++ b/routes/file.php @@ -1,9 +1,7 @@ ['auth:sanctum']], function () { Route::get('/thumbnail/{name}', GetThumbnailController::class)->name('thumbnail'); Route::get('/file/{name}', GetFileController::class)->name('file'); - Route::get('/zip/{id}', GetZipController::class)->name('zip'); }); diff --git a/src/App/Console/Kernel.php b/src/App/Console/Kernel.php index 551c1c6e..0a20a318 100644 --- a/src/App/Console/Kernel.php +++ b/src/App/Console/Kernel.php @@ -1,10 +1,10 @@ call( + fn() => resolve(DeleteFailedFilesAction::class)() + )->everySixHours(); + } + $schedule->call( - fn () => resolve(DeleteExpiredShareLinksAction::class)() + fn() => resolve(DeleteExpiredShareLinksAction::class)() )->everyTenMinutes(); $schedule->call( - fn () => resolve(DeleteUnverifiedUsersAction::class)() + fn() => resolve(DeleteUnverifiedUsersAction::class)() )->daily(); - $schedule->call(function () { - resolve(DeleteOldZipsAction::class)(); - - if (! is_storage_driver(['local'])) { - resolve(DeleteFailedFilesAction::class)(); - } - })->everySixHours(); - // Run queue jobs every minute $schedule->command('queue:work --stop-when-empty') ->everyMinute() diff --git a/src/Domain/Sharing/Controllers/ShareController.php b/src/Domain/Sharing/Controllers/ShareController.php index f645a599..7dbc0075 100644 --- a/src/Domain/Sharing/Controllers/ShareController.php +++ b/src/Domain/Sharing/Controllers/ShareController.php @@ -83,15 +83,6 @@ class ShareController extends Controller ->where('user_id', Auth::id()) ->firstOrFail() ->delete(); - - // Get zip record if exist - $zip = Zip::where('shared_token', $token) - ->where('user_id', Auth::id()) - ->first(); - - if ($zip) { - $zip->delete(); - } } return response('Done!', 204); diff --git a/src/Domain/Zip/Controllers/GetZipController.php b/src/Domain/Zip/Controllers/GetZipController.php deleted file mode 100644 index 1e384acc..00000000 --- a/src/Domain/Zip/Controllers/GetZipController.php +++ /dev/null @@ -1,44 +0,0 @@ -where('user_id', Auth::id()) - ->firstOrFail(); - - // Store user download size - ($this->recordDownload)( - file_size: $disk->size("zip/$zip->basename"), - user_id: $zip->user_id, - ); - - return $disk->download("zip/$zip->basename", $zip->basename, [ - 'Content-Type' => 'application/zip', - 'Content-Length' => $disk->size("zip/$zip->basename"), - 'Accept-Ranges' => 'bytes', - 'Content-Range' => 'bytes 0-600/' . $disk->size("zip/$zip->basename"), - 'Content-Disposition' => "attachment; filename=$zip->basename", - ]); - } -} diff --git a/src/Domain/Zip/Controllers/VisitorGetZipController.php b/src/Domain/Zip/Controllers/VisitorGetZipController.php deleted file mode 100644 index 413f6ee5..00000000 --- a/src/Domain/Zip/Controllers/VisitorGetZipController.php +++ /dev/null @@ -1,44 +0,0 @@ -where('shared_token', $token) - ->first(); - - // Store user download size - ($this->recordDownload)( - file_size: $disk->size("zip/$zip->basename"), - user_id: $zip->user_id, - ); - - return $disk->download("zip/$zip->basename", $zip->basename, [ - 'Content-Type' => 'application/zip', - 'Content-Length' => $disk->size("zip/$zip->basename"), - 'Accept-Ranges' => 'bytes', - 'Content-Range' => 'bytes 0-600/' . $disk->size("zip/$zip->basename"), - 'Content-Disposition' => 'attachment; filename=' . $zip->basename, - ]); - } -} diff --git a/src/Domain/Zip/Models/Zip.php b/src/Domain/Zip/Models/Zip.php deleted file mode 100644 index 1f5f1017..00000000 --- a/src/Domain/Zip/Models/Zip.php +++ /dev/null @@ -1,48 +0,0 @@ -hasOne(User::class, 'id', 'user_id'); - } - - protected static function boot() - { - parent::boot(); - - static::creating(function ($model) { - $model->id = (string) Str::uuid(); - }); - } -} diff --git a/src/Support/Scheduler/Actions/DeleteOldZipsAction.php b/src/Support/Scheduler/Actions/DeleteOldZipsAction.php deleted file mode 100644 index 7eaeac44..00000000 --- a/src/Support/Scheduler/Actions/DeleteOldZipsAction.php +++ /dev/null @@ -1,24 +0,0 @@ -subDay()->toDateTimeString()) - ->get() - ->each(function ($zip) { - // Delete zip file - Storage::disk('local')->delete("zip/$zip->basename"); - - // Delete zip record - $zip->delete(); - }); - } -} diff --git a/tests/Domain/Admin/AdminTest.php b/tests/Domain/Admin/AdminTest.php index 81e10d70..140987d3 100644 --- a/tests/Domain/Admin/AdminTest.php +++ b/tests/Domain/Admin/AdminTest.php @@ -264,11 +264,6 @@ class AdminTest extends TestCase $user->favouriteFolders()->attach($folder->id); }); - // Create zips - Zip::factory(Zip::class) - ->count(2) - ->create(['user_id' => $user->id]); - // Create shares Share::factory(Share::class) ->count(2) @@ -334,10 +329,6 @@ class AdminTest extends TestCase 'user_id' => $user->id, ]); - $this->assertDatabaseMissing('zips', [ - 'user_id' => $user->id, - ]); - $file_ids ->each(function ($id, $index) use ($user) { Storage::disk('local') diff --git a/tests/Domain/Files/ContentAccessTest.php b/tests/Domain/Files/ContentAccessTest.php index 2b3fc686..83b750c8 100644 --- a/tests/Domain/Files/ContentAccessTest.php +++ b/tests/Domain/Files/ContentAccessTest.php @@ -97,30 +97,6 @@ class ContentAccessTest extends TestCase ->assertStatus(200); } - /** - * @test - */ - public function it_get_private_user_zip() - { - $user = User::factory(User::class) - ->create(); - - $file = UploadedFile::fake() - ->create('archive.zip', 2000, 'application/zip'); - - Storage::putFileAs('zip', $file, 'EHWKcuvKzA4Gv29v-archive.zip'); - - $zip = Zip::factory(Zip::class)->create([ - 'basename' => 'EHWKcuvKzA4Gv29v-archive.zip', - 'user_id' => $user->id, - ]); - - $this - ->actingAs($user) - ->get("zip/$zip->id") - ->assertOk(); - } - /** * @test */ @@ -175,29 +151,6 @@ class ContentAccessTest extends TestCase ->assertStatus(404); } - /** - * @test - */ - public function logged_user_try_to_get_another_private_user_zip() - { - $user = User::factory(User::class) - ->create(); - - $file = UploadedFile::fake() - ->create('archive.zip', 2000, 'application/zip'); - - Storage::putFileAs('zip', $file, 'EHWKcuvKzA4Gv29v-archive.zip'); - - $zip = Zip::factory(Zip::class)->create([ - 'basename' => 'EHWKcuvKzA4Gv29v-archive.zip', - ]); - - $this - ->actingAs($user) - ->get("zip/$zip->id") - ->assertNotFound(); - } - /** * @test */ @@ -207,15 +160,6 @@ class ContentAccessTest extends TestCase ->assertRedirect(); } - /** - * @test - */ - public function guest_try_to_get_private_user_zip() - { - $this->get('zip/EHWKcuvKzA4Gv29v-archive.zip') - ->assertRedirect(); - } - /** * @test */ diff --git a/tests/Domain/Sharing/VisitorAccessToItemsTest.php b/tests/Domain/Sharing/VisitorAccessToItemsTest.php index c3bbf86d..d12d9caf 100644 --- a/tests/Domain/Sharing/VisitorAccessToItemsTest.php +++ b/tests/Domain/Sharing/VisitorAccessToItemsTest.php @@ -186,57 +186,4 @@ class VisitorAccessToItemsTest extends TestCase ]); }); } - - /** - * @test - */ - public function it_download_publicly_zipped_files() - { - collect([true, false]) - ->each(function ($is_protected) { - $user = User::factory(User::class) - ->create(); - - $share = Share::factory(Share::class) - ->create([ - 'user_id' => $user->id, - 'type' => 'folder', - 'is_protected' => $is_protected, - ]); - - $zip = Zip::factory(Zip::class)->create([ - 'basename' => 'EHWKcuvKzA4Gv29v-archive.zip', - 'user_id' => $user->id, - 'shared_token' => $share->token, - ]); - - $file = UploadedFile::fake() - ->create($zip->basename, 1000, 'application/zip'); - - Storage::putFileAs('zip', $file, $file->name); - - if ($is_protected) { - $cookie = [ - 'share_session' => json_encode([ - 'token' => $share->token, - 'authenticated' => true, - ]), - ]; - - $this->withCookies($cookie) - ->get("/zip/$zip->id/$share->token") - ->assertStatus(200); - } - - if (! $is_protected) { - $this->get("/zip/$zip->id/$share->token") - ->assertStatus(200); - } - - $this->assertDatabaseMissing('traffic', [ - 'user_id' => $user->id, - 'download' => null, - ]); - }); - } } diff --git a/tests/Domain/Zipping/SharedZippingTest.php b/tests/Domain/Zip/SharedZippingTest.php similarity index 100% rename from tests/Domain/Zipping/SharedZippingTest.php rename to tests/Domain/Zip/SharedZippingTest.php diff --git a/tests/Domain/Zipping/UserZippingTest.php b/tests/Domain/Zip/UserZippingTest.php similarity index 100% rename from tests/Domain/Zipping/UserZippingTest.php rename to tests/Domain/Zip/UserZippingTest.php diff --git a/tests/Support/Scheduler/SchedulerTest.php b/tests/Support/Scheduler/SchedulerTest.php index 08101918..35b06b45 100644 --- a/tests/Support/Scheduler/SchedulerTest.php +++ b/tests/Support/Scheduler/SchedulerTest.php @@ -4,10 +4,8 @@ namespace Tests\Support\Scheduler; use Storage; use Tests\TestCase; use App\Users\Models\User; -use Domain\Zip\Models\Zip; use Domain\Sharing\Models\Share; use Illuminate\Http\UploadedFile; -use Support\Scheduler\Actions\DeleteOldZipsAction; use Support\Scheduler\Actions\DeleteFailedFilesAction; use Support\Scheduler\Actions\DeleteUnverifiedUsersAction; use Support\Scheduler\Actions\DeleteExpiredShareLinksAction; @@ -32,31 +30,6 @@ class SchedulerTest extends TestCase ]); } - /** - * @test - */ - public function it_delete_zips_older_than_one_day() - { - $file = UploadedFile::fake() - ->create('archive.zip', 2000, 'application/zip'); - - Storage::putFileAs('zip', $file, 'EHWKcuvKzA4Gv29v-archive.zip'); - - $zip = Zip::factory(Zip::class)->create([ - 'basename' => 'EHWKcuvKzA4Gv29v-archive.zip', - 'created_at' => now()->subDay(), - ]); - - resolve(DeleteOldZipsAction::class)(); - - $this->assertDatabaseMissing('zips', [ - 'id' => $zip->id, - ]); - - Storage::disk('local') - ->assertMissing('zip/EHWKcuvKzA4Gv29v-archive.zip'); - } - /** * @test */