Skip to content

Commit

Permalink
Update composer (include breaking) (#2019)
Browse files Browse the repository at this point in the history
* Update composer (include breaking)

* fix phpstan

* fix header
  • Loading branch information
qwerty287 authored Sep 17, 2023
1 parent 2133267 commit cf7b952
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 144 deletions.
21 changes: 6 additions & 15 deletions app/Actions/Album/Archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@
use function Safe\set_time_limit;
use Symfony\Component\HttpFoundation\HeaderUtils;
use Symfony\Component\HttpFoundation\StreamedResponse;
use ZipStream\CompressionMethod as ZipMethod;
use ZipStream\Exception\FileNotFoundException;
use ZipStream\Exception\FileNotReadableException;
use ZipStream\Option\Archive as ZipArchiveOption;
use ZipStream\Option\File as ZipFileOption;
use ZipStream\Option\Method as ZipMethod;
use ZipStream\ZipStream;

class Archive extends Action
Expand Down Expand Up @@ -62,10 +60,10 @@ public function do(Collection $albums): StreamedResponse
$this->deflateLevel = Configs::getValueAsInt('zip_deflate_level');

$responseGenerator = function () use ($albums) {
$options = new ZipArchiveOption();
$options->setEnableZip64(Configs::getValueAsBool('zip64'));
$options->setZeroHeader(true);
$zip = new ZipStream(null, $options);
$zip = new ZipStream(defaultCompressionMethod: $this->deflateLevel === -1 ? ZipMethod::STORE : ZipMethod::DEFLATE,
defaultDeflateLevel: $this->deflateLevel,
enableZip64: Configs::getValueAsBool('zip64'),
defaultEnableZeroHeader: true, sendHttpHeaders: false);

$usedDirNames = [];
foreach ($albums as $album) {
Expand Down Expand Up @@ -216,14 +214,7 @@ private function compressAlbum(AbstractAlbum $album, array &$usedDirNames, ?stri
} catch (InfoException) {
// Silently do nothing, if `set_time_limit` is denied.
}
$zipFileOption = new ZipFileOption();
$zipFileOption->setMethod($this->deflateLevel === -1 ? ZipMethod::STORE() : ZipMethod::DEFLATE());
$zipFileOption->setDeflateLevel($this->deflateLevel);
$zipFileOption->setComment($photo->title);
if ($photo->taken_at !== null) {
$zipFileOption->setTime($photo->taken_at);
}
$zip->addFileFromStream($fileName, $file->read(), $zipFileOption);
$zip->addFileFromStream(fileName: $fileName, stream: $file->read(), comment: $photo->title, lastModificationDateTime: $photo->taken_at);
$file->close();
} catch (\Throwable $e) {
Handler::reportSafely($e);
Expand Down
15 changes: 5 additions & 10 deletions app/Actions/Photo/Archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
use function Safe\stream_copy_to_stream;
use Symfony\Component\HttpFoundation\HeaderUtils;
use Symfony\Component\HttpFoundation\StreamedResponse;
use ZipStream\Option\File as ZipFileOption;
use ZipStream\Option\Method as ZipMethod;
use ZipStream\CompressionMethod as ZipMethod;
use ZipStream\ZipStream;

class Archive
Expand Down Expand Up @@ -142,10 +141,7 @@ protected function zip(Collection $photos, DownloadVariantType $downloadVariant)
$this->deflateLevel = Configs::getValueAsInt('zip_deflate_level');

$responseGenerator = function () use ($downloadVariant, $photos) {
$options = new \ZipStream\Option\Archive();
$options->setEnableZip64(Configs::getValueAsBool('zip64'));
$options->setZeroHeader(true);
$zip = new ZipStream(null, $options);
$zip = new ZipStream(enableZip64: Configs::getValueAsBool('zip64'), defaultEnableZeroHeader: true, sendHttpHeaders: false);

// We first need to scan the whole array of files to avoid
// problems with duplicate file names.
Expand Down Expand Up @@ -236,10 +232,9 @@ protected function zip(Collection $photos, DownloadVariantType $downloadVariant)
);
} while (array_key_exists($filename, $uniqueFilenames));
}
$zipFileOption = new ZipFileOption();
$zipFileOption->setMethod($this->deflateLevel === -1 ? ZipMethod::STORE() : ZipMethod::DEFLATE());
$zipFileOption->setDeflateLevel($this->deflateLevel);
$zip->addFileFromStream($filename, $archiveFileInfo->getFile()->read(), $zipFileOption);
$zip->addFileFromStream(fileName: $filename, stream: $archiveFileInfo->getFile()->read(),
compressionMethod: $this->deflateLevel === -1 ? ZipMethod::STORE : ZipMethod::DEFLATE,
deflateLevel: $this->deflateLevel);
$archiveFileInfo->getFile()->close();
// Reset the execution timeout for every iteration.
try {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"laravel/framework": "^10.0",
"lychee-org/nestedset": "^8.0",
"lychee-org/php-exif": "^1.0.0",
"maennchen/zipstream-php": "^2.1",
"maennchen/zipstream-php": "^3.1",
"opcodesio/log-viewer": "dev-lycheeOrg",
"php-ffmpeg/php-ffmpeg": "^1.0",
"php-http/guzzle7-adapter": "^1.0",
Expand Down
Loading

0 comments on commit cf7b952

Please sign in to comment.