diff --git a/app/Extensions/helper/helpers.php b/app/Extensions/helper/helpers.php index 4797e8c04..de8a733a1 100644 --- a/app/Extensions/helper/helpers.php +++ b/app/Extensions/helper/helpers.php @@ -5,7 +5,6 @@ use Blacklight\NZB; use Blacklight\utility\Utility; use Blacklight\XXX; use Colors\Color; -use DariusIII\Zipper\Zipper; use GuzzleHttp\Client; use GuzzleHttp\Cookie\CookieJar; use GuzzleHttp\Cookie\SetCookie; @@ -13,6 +12,7 @@ use GuzzleHttp\Exception\RequestException; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use Symfony\Component\Process\Process; +use Zip as ZipStream; if (! function_exists('getRawHtml')) { @@ -310,42 +310,34 @@ if (! function_exists('is_it_json')) { } } -if (! function_exists('getZipped')) { +/** + * @param array $guids + * @return \STS\ZipStream\ZipStream + * + * @throws \Exception + */ +function getStreamingZip(array $guids = []): \STS\ZipStream\ZipStream +{ + $nzb = new NZB(); + $zipped = ZipStream::create(now()->format('Ymdhis').'.zip'); + foreach ($guids as $guid) { + $nzbPath = $nzb->NZBPath($guid); - /** - * @param array $guids - * @return string - * - * @throws \Exception - */ - function getZipped(array $guids = []): string - { - $nzb = new NZB(); - $zipped = new Zipper(); - $zippedFileName = now()->format('Ymdhis').'.nzb.zip'; - $zippedFilePath = resource_path().'/tmp/'.$zippedFileName; - $archive = $zipped->make($zippedFilePath); - foreach ($guids as $guid) { - $nzbPath = $nzb->NZBPath($guid); + if ($nzbPath) { + $nzbContents = Utility::unzipGzipFile($nzbPath); - if ($nzbPath !== false) { - $nzbContents = Utility::unzipGzipFile($nzbPath); - - if ($nzbContents !== false) { - $filename = $guid; - $r = Release::getByGuid($guid); - if ($r) { - $filename = $r['searchname']; - } - $archive->addString($filename.'.nzb', $nzbContents); + if ($nzbContents) { + $filename = $guid; + $r = Release::getByGuid($guid); + if ($r) { + $filename = $r['searchname']; } + $zipped->addRaw($nzbContents, $filename.'.nzb'); } } - - $archive->close(); - - return File::isFile($zippedFilePath) ? $zippedFilePath : ''; } + + return $zipped; } if (! function_exists('release_flag')) { diff --git a/app/Http/Controllers/GetNzbController.php b/app/Http/Controllers/GetNzbController.php index e0251454a..9d4269b0c 100644 --- a/app/Http/Controllers/GetNzbController.php +++ b/app/Http/Controllers/GetNzbController.php @@ -73,7 +73,7 @@ class GetNzbController extends BasePageController Utility::showApiError(501); } - $zip = getZipped($guids); + $zip = getStreamingZip($guids); if ($zip !== '') { User::incrementGrabs($uid, \count($guids)); foreach ($guids as $guid) { @@ -85,7 +85,7 @@ class GetNzbController extends BasePageController } } - return response()->download($zip, now()->format('Ymdhis').'.nzb.zip', ['Content-type:' => 'application/zip'])->deleteFileAfterSend(true); + return $zip; } return response()->json(['message' => 'Unable to create .zip file'], 404); diff --git a/composer.json b/composer.json index d51301d9f..4b2259276 100755 --- a/composer.json +++ b/composer.json @@ -103,7 +103,6 @@ "dariusiii/rarinfo": "^2.5", "dariusiii/tmdb-laravel": "^4.0", "dariusiii/token": "^3.0", - "dariusiii/zipper": "^2.0", "dborsatto/php-giantbomb": "^2.0", "doctrine/dbal": "^3.0", "fakerphp/faker": "^1.12", @@ -152,6 +151,7 @@ "spatie/laravel-fractal": "^5.3", "spatie/laravel-permission": "^5.0", "sspat/es-query-sanitizer": "^1.0", + "stechstudio/laravel-zipstream": "^4.5", "symfony/process": "^5.4", "vlucas/phpdotenv": "^5.0", "voku/simple_html_dom": "^4.3", diff --git a/composer.lock b/composer.lock index 227beb9ee..826a2c03d 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": "5bff8379c8b232d59cfcb59d54bbb361", + "content-hash": "20289fbb94368419150e62e6fce171fb", "packages": [ { "name": "aharen/omdbapi", @@ -1294,70 +1294,6 @@ }, "time": "2020-09-24T07:05:41+00:00" }, - { - "name": "dariusiii/zipper", - "version": "v2.2.0", - "source": { - "type": "git", - "url": "https://github.com/DariusIII/Zipper.git", - "reference": "22638c72514bf4f53bceca5169ab92049ecdd3c1" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/DariusIII/Zipper/zipball/22638c72514bf4f53bceca5169ab92049ecdd3c1", - "reference": "22638c72514bf4f53bceca5169ab92049ecdd3c1", - "shasum": "" - }, - "require": { - "ext-zip": "*", - "illuminate/filesystem": "^5.8|^6.0|^7.0|^8.0", - "illuminate/support": "^5.8|^6.0|^7.0|^8.0", - "php": ">=7.2.0" - }, - "require-dev": { - "mockery/mockery": "^1.2", - "phpunit/phpunit": "^7.0|^8.0|^9.0" - }, - "type": "library", - "extra": { - "laravel": { - "providers": [ - "DariusIII\\Zipper\\ZipperServiceProvider" - ], - "aliases": { - "Zipper": "DariusIII\\Zipper\\Facades\\Zipper" - } - } - }, - "autoload": { - "psr-4": { - "DariusIII\\Zipper\\": "src/DariusIII/Zipper" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "Apache-2.0" - ], - "authors": [ - { - "name": "Nils Plaschke", - "email": "github@nilsplaschke.de", - "homepage": "http://nilsplaschke.de", - "role": "Developer" - } - ], - "description": "This is a little neat helper for the ZipArchive methods with handy functions", - "homepage": "http://github.com/DariusIII/zipper", - "keywords": [ - "archive", - "laravel", - "zip" - ], - "support": { - "source": "https://github.com/DariusIII/Zipper/tree/v2.2.0" - }, - "time": "2020-09-22T11:38:01+00:00" - }, { "name": "dborsatto/php-giantbomb", "version": "v2.2.0", @@ -4886,6 +4822,77 @@ ], "time": "2021-11-21T11:48:40+00:00" }, + { + "name": "maennchen/zipstream-php", + "version": "2.1.0", + "source": { + "type": "git", + "url": "https://github.com/maennchen/ZipStream-PHP.git", + "reference": "c4c5803cc1f93df3d2448478ef79394a5981cc58" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/maennchen/ZipStream-PHP/zipball/c4c5803cc1f93df3d2448478ef79394a5981cc58", + "reference": "c4c5803cc1f93df3d2448478ef79394a5981cc58", + "shasum": "" + }, + "require": { + "myclabs/php-enum": "^1.5", + "php": ">= 7.1", + "psr/http-message": "^1.0", + "symfony/polyfill-mbstring": "^1.0" + }, + "require-dev": { + "ext-zip": "*", + "guzzlehttp/guzzle": ">= 6.3", + "mikey179/vfsstream": "^1.6", + "phpunit/phpunit": ">= 7.5" + }, + "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/master" + }, + "funding": [ + { + "url": "https://opencollective.com/zipstream", + "type": "open_collective" + } + ], + "time": "2020-05-30T13:11:16+00:00" + }, { "name": "marcreichel/igdb-laravel", "version": "3.5.3", @@ -5317,6 +5324,66 @@ ], "time": "2021-10-01T21:08:31+00:00" }, + { + "name": "myclabs/php-enum", + "version": "1.8.3", + "source": { + "type": "git", + "url": "https://github.com/myclabs/php-enum.git", + "reference": "b942d263c641ddb5190929ff840c68f78713e937" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/php-enum/zipball/b942d263c641ddb5190929ff840c68f78713e937", + "reference": "b942d263c641ddb5190929ff840c68f78713e937", + "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/" + } + }, + "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.3" + }, + "funding": [ + { + "url": "https://github.com/mnapoli", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/myclabs/php-enum", + "type": "tidelift" + } + ], + "time": "2021-07-05T08:18:36+00:00" + }, { "name": "nesbot/carbon", "version": "2.55.2", @@ -8758,6 +8825,68 @@ }, "time": "2018-01-22T19:50:50+00:00" }, + { + "name": "stechstudio/laravel-zipstream", + "version": "4.5", + "source": { + "type": "git", + "url": "https://github.com/stechstudio/laravel-zipstream.git", + "reference": "4c7f521796c4bc2580e7409aceddeb9b2b2eab37" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/stechstudio/laravel-zipstream/zipball/4c7f521796c4bc2580e7409aceddeb9b2b2eab37", + "reference": "4c7f521796c4bc2580e7409aceddeb9b2b2eab37", + "shasum": "" + }, + "require": { + "guzzlehttp/guzzle": "^6.0|^7.0", + "illuminate/support": "^5.6|^6.0|^7.0|^8.0", + "maennchen/zipstream-php": "^v2.0", + "php": "^7.1|^8.0" + }, + "require-dev": { + "orchestra/testbench": "^5.0|^6.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": "Build", + "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.5" + }, + "time": "2021-10-06T00:40:59+00:00" + }, { "name": "swiftmailer/swiftmailer", "version": "v6.3.0", @@ -12540,12 +12669,12 @@ "source": { "type": "git", "url": "https://github.com/composer/composer.git", - "reference": "cd34886e9d9a4c7391762877200c503dbaa6aaee" + "reference": "3ae111140facdba8ae82adcd1085e4adfc7d715c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/composer/zipball/cd34886e9d9a4c7391762877200c503dbaa6aaee", - "reference": "cd34886e9d9a4c7391762877200c503dbaa6aaee", + "url": "https://api.github.com/repos/composer/composer/zipball/3ae111140facdba8ae82adcd1085e4adfc7d715c", + "reference": "3ae111140facdba8ae82adcd1085e4adfc7d715c", "shasum": "" }, "require": { @@ -12567,7 +12696,7 @@ "symfony/process": "^5.4 || ^6.0" }, "require-dev": { - "phpstan/phpstan": "^1.4.0", + "phpstan/phpstan": "^1.4.1", "phpstan/phpstan-deprecation-rules": "^1", "phpstan/phpstan-phpunit": "^1.0", "phpstan/phpstan-strict-rules": "^1", @@ -12635,7 +12764,7 @@ "type": "tidelift" } ], - "time": "2022-01-17T14:18:33+00:00" + "time": "2022-01-21T16:39:57+00:00" }, { "name": "composer/metadata-minifier", @@ -13745,16 +13874,16 @@ }, { "name": "mockery/mockery", - "version": "1.4.4", + "version": "1.5.0", "source": { "type": "git", "url": "https://github.com/mockery/mockery.git", - "reference": "e01123a0e847d52d186c5eb4b9bf58b0c6d00346" + "reference": "c10a5f6e06fc2470ab1822fa13fa2a7380f8fbac" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/mockery/mockery/zipball/e01123a0e847d52d186c5eb4b9bf58b0c6d00346", - "reference": "e01123a0e847d52d186c5eb4b9bf58b0c6d00346", + "url": "https://api.github.com/repos/mockery/mockery/zipball/c10a5f6e06fc2470ab1822fa13fa2a7380f8fbac", + "reference": "c10a5f6e06fc2470ab1822fa13fa2a7380f8fbac", "shasum": "" }, "require": { @@ -13811,9 +13940,9 @@ ], "support": { "issues": "https://github.com/mockery/mockery/issues", - "source": "https://github.com/mockery/mockery/tree/1.4.4" + "source": "https://github.com/mockery/mockery/tree/1.5.0" }, - "time": "2021-09-13T15:28:59+00:00" + "time": "2022-01-20T13:18:17+00:00" }, { "name": "myclabs/deep-copy", @@ -14912,16 +15041,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.5.11", + "version": "9.5.12", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "2406855036db1102126125537adb1406f7242fdd" + "reference": "93d4bf4c37aec6384bb9e5d390d9049a463a7256" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/2406855036db1102126125537adb1406f7242fdd", - "reference": "2406855036db1102126125537adb1406f7242fdd", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/93d4bf4c37aec6384bb9e5d390d9049a463a7256", + "reference": "93d4bf4c37aec6384bb9e5d390d9049a463a7256", "shasum": "" }, "require": { @@ -14999,7 +15128,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.11" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.12" }, "funding": [ { @@ -15011,7 +15140,7 @@ "type": "github" } ], - "time": "2021-12-25T07:07:57+00:00" + "time": "2022-01-21T05:54:47+00:00" }, { "name": "sebastian/cli-parser",