Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/Helper/ChunkHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace CodingSocks\ChunkUploader\Helper;

use Illuminate\Contracts\Filesystem\Filesystem;
use Illuminate\Http\File;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
Expand Down Expand Up @@ -45,7 +46,7 @@ public function mergeChunks(StorageConfig $config, array $chunks, string $target
}
}

return $targetPath;
return $this->correctMergedExt($disk, $mergedDirectory, $targetFilename);
}

/**
Expand All @@ -67,6 +68,7 @@ public function deleteChunkDirectory(StorageConfig $config, string $uuid): void
* @param \CodingSocks\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
Expand Down Expand Up @@ -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
{
$targetPath = $mergedDirectory . '/' . $targetFilename;
$ext = pathinfo($targetFilename, PATHINFO_EXTENSION);
if ($ext === 'bin') {
$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;
}
}