From 1fb525f65b1ebb406f7ed394640dcb5241de1ba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20G=C3=B6r=C3=B6g?= Date: Wed, 10 Jun 2020 17:39:32 +0200 Subject: [PATCH 1/2] Fix extension of merged file --- src/Helper/ChunkHelpers.php | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/Helper/ChunkHelpers.php b/src/Helper/ChunkHelpers.php index 37f6979..01ebc3f 100644 --- a/src/Helper/ChunkHelpers.php +++ b/src/Helper/ChunkHelpers.php @@ -2,6 +2,7 @@ namespace LaraCrafts\ChunkUploader\Helper; +use Illuminate\Contracts\Filesystem\Filesystem; use Illuminate\Http\File; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Storage; @@ -45,7 +46,7 @@ public function mergeChunks(StorageConfig $config, array $chunks, string $target } } - return $targetPath; + return $this->correctMergedExt($disk, $mergedDirectory, $targetFilename); } /** @@ -67,6 +68,7 @@ public function deleteChunkDirectory(StorageConfig $config, string $uuid): void * @param \LaraCrafts\ChunkUploader\Range\Range $range * @param \Illuminate\Http\UploadedFile $file * @param string $uuid + * * @return array */ public function storeChunk(StorageConfig $config, Range $range, UploadedFile $file, string $uuid): array @@ -127,10 +129,32 @@ public function chunkExists(StorageConfig $config, string $uuid, string $chunkna $directory = $config->getChunkDirectory() . '/' . $uuid; $disk = Storage::disk($config->getDisk()); - if (! $disk->exists($directory)) { + if (!$disk->exists($directory)) { return false; } return $chunkname === null || $disk->exists($directory . '/' . $chunkname); } + + /** + * @param \Illuminate\Contracts\Filesystem\Filesystem $disk + * @param string $mergedDirectory + * @param string $targetFilename + * + * @return string + */ + private function correctMergedExt(Filesystem $disk, string $mergedDirectory, string $targetFilename): string + { + $ext = pathinfo($targetFilename, PATHINFO_EXTENSION); + if ($ext === 'bin') { + $targetPath = $mergedDirectory . '/' . $targetFilename; + $var = $disk->path($targetPath); + $uploadedFile = new UploadedFile($var, $targetFilename); + $filename = pathinfo($targetFilename, PATHINFO_FILENAME); + $fixedTargetPath = $mergedDirectory . '/' . $filename . '.' . $uploadedFile->guessExtension(); + $disk->move($targetPath, $fixedTargetPath); + $targetPath = $fixedTargetPath; + } + return $targetPath; + } } From 7436666362cd409dd214e9250f712015a2979c11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20G=C3=B6r=C3=B6g?= Date: Wed, 10 Jun 2020 17:48:05 +0200 Subject: [PATCH 2/2] Fix missing variable --- src/Helper/ChunkHelpers.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Helper/ChunkHelpers.php b/src/Helper/ChunkHelpers.php index 01ebc3f..f000144 100644 --- a/src/Helper/ChunkHelpers.php +++ b/src/Helper/ChunkHelpers.php @@ -145,9 +145,9 @@ public function chunkExists(StorageConfig $config, string $uuid, string $chunkna */ private function correctMergedExt(Filesystem $disk, string $mergedDirectory, string $targetFilename): string { + $targetPath = $mergedDirectory . '/' . $targetFilename; $ext = pathinfo($targetFilename, PATHINFO_EXTENSION); if ($ext === 'bin') { - $targetPath = $mergedDirectory . '/' . $targetFilename; $var = $disk->path($targetPath); $uploadedFile = new UploadedFile($var, $targetFilename); $filename = pathinfo($targetFilename, PATHINFO_FILENAME);