From 1a25d4fb3adf0ff12d4513af3fac13de9dc8c16f Mon Sep 17 00:00:00 2001 From: Damien Calesse Date: Wed, 13 Dec 2023 23:46:29 -0500 Subject: [PATCH] Add ZIP download + CSS update --- app/Http/Controllers/ListController.php | 17 ++ composer.json | 3 +- composer.lock | 231 ++++++++++++++++++++++-- resources/views/list/index.blade.php | 22 ++- routes/web.php | 1 + 5 files changed, 257 insertions(+), 17 deletions(-) diff --git a/app/Http/Controllers/ListController.php b/app/Http/Controllers/ListController.php index 1d90ed8..87f3052 100644 --- a/app/Http/Controllers/ListController.php +++ b/app/Http/Controllers/ListController.php @@ -7,8 +7,11 @@ use Illuminate\View\View; use Symfony\Component\HttpFoundation\BinaryFileResponse; +use Zip; + class ListController extends Controller { + public function show(string $path = null) : View|BinaryFileResponse { $folder = $root = env('DIRECTORY_FOLDER'); @@ -31,6 +34,20 @@ public function show(string $path = null) : View|BinaryFileResponse // Download return response()->download($folder); } + } + + public function zip(string $path = null) : View|\STS\ZipStream\ZipStream + { + $folder = $root = env('DIRECTORY_FOLDER'); + + if ($path) { + $folder = sprintf('%s/%s', $folder, $path); + } + + if (!$folder || !file_exists($folder)) return redirect($path); + // ZIP + return Zip::create(basename($folder) . '.zip', [ $folder ]); } + } diff --git a/composer.json b/composer.json index 8a3d72d..6d969c2 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,8 @@ "guzzlehttp/guzzle": "^7.2", "laravel/framework": "^10.10", "laravel/sanctum": "^3.3", - "laravel/tinker": "^2.8" + "laravel/tinker": "^2.8", + "stechstudio/laravel-zipstream": "^4.13" }, "require-dev": { "fakerphp/faker": "^1.9.1", diff --git a/composer.lock b/composer.lock index ceec032..c13c2b0 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9c491b8531eec05ba41a11d9276a5749", + "content-hash": "19c37f6768afad22555f56989f14b6f6", "packages": [ { "name": "brick/math", @@ -1047,16 +1047,16 @@ }, { "name": "laravel/framework", - "version": "v10.35.0", + "version": "v10.37.3", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "91ec2d92d2f6007e9084fe06438b99c91845da69" + "reference": "996375dd61f8c6e4ac262b57ed485655d71fcbdc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/91ec2d92d2f6007e9084fe06438b99c91845da69", - "reference": "91ec2d92d2f6007e9084fe06438b99c91845da69", + "url": "https://api.github.com/repos/laravel/framework/zipball/996375dd61f8c6e4ac262b57ed485655d71fcbdc", + "reference": "996375dd61f8c6e4ac262b57ed485655d71fcbdc", "shasum": "" }, "require": { @@ -1245,7 +1245,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2023-12-05T14:50:33+00:00" + "time": "2023-12-13T20:10:58+00:00" }, { "name": "laravel/prompts", @@ -1893,6 +1893,84 @@ ], "time": "2023-10-17T14:13:20+00:00" }, + { + "name": "maennchen/zipstream-php", + "version": "2.4.0", + "source": { + "type": "git", + "url": "https://github.com/maennchen/ZipStream-PHP.git", + "reference": "3fa72e4c71a43f9e9118752a5c90e476a8dc9eb3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/maennchen/ZipStream-PHP/zipball/3fa72e4c71a43f9e9118752a5c90e476a8dc9eb3", + "reference": "3fa72e4c71a43f9e9118752a5c90e476a8dc9eb3", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "myclabs/php-enum": "^1.5", + "php": "^8.0", + "psr/http-message": "^1.0" + }, + "require-dev": { + "ext-zip": "*", + "friendsofphp/php-cs-fixer": "^3.9", + "guzzlehttp/guzzle": "^6.5.3 || ^7.2.0", + "mikey179/vfsstream": "^1.6", + "php-coveralls/php-coveralls": "^2.4", + "phpunit/phpunit": "^8.5.8 || ^9.4.2", + "vimeo/psalm": "^5.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "ZipStream\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Paul Duncan", + "email": "pabs@pablotron.org" + }, + { + "name": "Jonatan Männchen", + "email": "jonatan@maennchen.ch" + }, + { + "name": "Jesse Donat", + "email": "donatj@gmail.com" + }, + { + "name": "András Kolesár", + "email": "kolesar@kolesar.hu" + } + ], + "description": "ZipStream is a library for dynamically streaming dynamic zip files from PHP without writing to the disk at all on the server.", + "keywords": [ + "stream", + "zip" + ], + "support": { + "issues": "https://github.com/maennchen/ZipStream-PHP/issues", + "source": "https://github.com/maennchen/ZipStream-PHP/tree/2.4.0" + }, + "funding": [ + { + "url": "https://github.com/maennchen", + "type": "github" + }, + { + "url": "https://opencollective.com/zipstream", + "type": "open_collective" + } + ], + "time": "2022-12-08T12:29:14+00:00" + }, { "name": "monolog/monolog", "version": "3.5.0", @@ -1994,6 +2072,69 @@ ], "time": "2023-10-27T15:32:31+00:00" }, + { + "name": "myclabs/php-enum", + "version": "1.8.4", + "source": { + "type": "git", + "url": "https://github.com/myclabs/php-enum.git", + "reference": "a867478eae49c9f59ece437ae7f9506bfaa27483" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/php-enum/zipball/a867478eae49c9f59ece437ae7f9506bfaa27483", + "reference": "a867478eae49c9f59ece437ae7f9506bfaa27483", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": "^7.3 || ^8.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.5", + "squizlabs/php_codesniffer": "1.*", + "vimeo/psalm": "^4.6.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "MyCLabs\\Enum\\": "src/" + }, + "classmap": [ + "stubs/Stringable.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP Enum contributors", + "homepage": "https://github.com/myclabs/php-enum/graphs/contributors" + } + ], + "description": "PHP Enum implementation", + "homepage": "http://github.com/myclabs/php-enum", + "keywords": [ + "enum" + ], + "support": { + "issues": "https://github.com/myclabs/php-enum/issues", + "source": "https://github.com/myclabs/php-enum/tree/1.8.4" + }, + "funding": [ + { + "url": "https://github.com/mnapoli", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/myclabs/php-enum", + "type": "tidelift" + } + ], + "time": "2022-08-04T09:53:51+00:00" + }, { "name": "nesbot/carbon", "version": "2.72.1", @@ -2726,16 +2867,16 @@ }, { "name": "psr/http-message", - "version": "2.0", + "version": "1.1", "source": { "type": "git", "url": "https://github.com/php-fig/http-message.git", - "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71" + "reference": "cb6ce4845ce34a8ad9e68117c10ee90a29919eba" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71", - "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/cb6ce4845ce34a8ad9e68117c10ee90a29919eba", + "reference": "cb6ce4845ce34a8ad9e68117c10ee90a29919eba", "shasum": "" }, "require": { @@ -2744,7 +2885,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "1.1.x-dev" } }, "autoload": { @@ -2759,7 +2900,7 @@ "authors": [ { "name": "PHP-FIG", - "homepage": "https://www.php-fig.org/" + "homepage": "http://www.php-fig.org/" } ], "description": "Common interface for HTTP messages", @@ -2773,9 +2914,9 @@ "response" ], "support": { - "source": "https://github.com/php-fig/http-message/tree/2.0" + "source": "https://github.com/php-fig/http-message/tree/1.1" }, - "time": "2023-04-04T09:54:51+00:00" + "time": "2023-04-04T09:50:52+00:00" }, { "name": "psr/log", @@ -3183,6 +3324,68 @@ ], "time": "2023-11-08T05:53:05+00:00" }, + { + "name": "stechstudio/laravel-zipstream", + "version": "4.13", + "source": { + "type": "git", + "url": "https://github.com/stechstudio/laravel-zipstream.git", + "reference": "c4f511615a9ff63934f21916c4eaedc7c8adb310" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/stechstudio/laravel-zipstream/zipball/c4f511615a9ff63934f21916c4eaedc7c8adb310", + "reference": "c4f511615a9ff63934f21916c4eaedc7c8adb310", + "shasum": "" + }, + "require": { + "guzzlehttp/guzzle": "^6.0|^7.0", + "illuminate/support": "^5.6|^6.0|^7.0|^8.0|^9.0|^10.0", + "maennchen/zipstream-php": "^v2.0", + "php": "^7.1|^8.0" + }, + "require-dev": { + "orchestra/testbench": "^5.0|^6.0|^7.0|^8.0", + "phpunit/phpunit": "^9.0" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "STS\\ZipStream\\ZipStreamServiceProvider" + ], + "aliases": { + "Zip": "STS\\ZipStream\\ZipStreamFacade" + } + } + }, + "autoload": { + "psr-4": { + "STS\\ZipStream\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Joseph Szobody", + "email": "joseph@stechstudio.com" + } + ], + "description": "A fast and simple streaming zip file downloader for Laravel.", + "homepage": "https://github.com/stechstudio/laravel-zipstream", + "keywords": [ + "laravel-zipstream", + "stechstudio" + ], + "support": { + "issues": "https://github.com/stechstudio/laravel-zipstream/issues", + "source": "https://github.com/stechstudio/laravel-zipstream/tree/4.13" + }, + "time": "2023-02-23T20:57:15+00:00" + }, { "name": "symfony/console", "version": "v6.4.1", diff --git a/resources/views/list/index.blade.php b/resources/views/list/index.blade.php index cffa0a3..094c710 100644 --- a/resources/views/list/index.blade.php +++ b/resources/views/list/index.blade.php @@ -32,11 +32,19 @@ } .viewer-controls { + display: flex; + justify-content: space-between; + border-bottom: 1px dashed; margin-bottom: 5px; padding-bottom: 1px; } + .viewer-item { + display: flex; + justify-content: space-between; + } + @@ -56,11 +64,16 @@ + + + + + @endif @foreach ($files as $file) -
- + @endforeach
diff --git a/routes/web.php b/routes/web.php index fd62c03..87638bf 100644 --- a/routes/web.php +++ b/routes/web.php @@ -14,4 +14,5 @@ | */ +Route::get('/zip/{path?}', [ListController::class, 'zip'])->where('path', '(.*)'); Route::get('/{path?}', [ListController::class, 'show'])->where('path', '(.*)');