22
33namespace CodingSocks \ChunkUploader \Helper ;
44
5+ use Illuminate \Contracts \Filesystem \Filesystem ;
56use Illuminate \Http \File ;
67use Illuminate \Http \UploadedFile ;
78use Illuminate \Support \Facades \Storage ;
@@ -45,7 +46,7 @@ public function mergeChunks(StorageConfig $config, array $chunks, string $target
4546 }
4647 }
4748
48- return $ targetPath ;
49+ return $ this -> correctMergedExt ( $ disk , $ mergedDirectory , $ targetFilename ) ;
4950 }
5051
5152 /**
@@ -67,6 +68,7 @@ public function deleteChunkDirectory(StorageConfig $config, string $uuid): void
6768 * @param \CodingSocks\ChunkUploader\Range\Range $range
6869 * @param \Illuminate\Http\UploadedFile $file
6970 * @param string $uuid
71+ *
7072 * @return array
7173 */
7274 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
127129 $ directory = $ config ->getChunkDirectory () . '/ ' . $ uuid ;
128130 $ disk = Storage::disk ($ config ->getDisk ());
129131
130- if (! $ disk ->exists ($ directory )) {
132+ if (!$ disk ->exists ($ directory )) {
131133 return false ;
132134 }
133135
134136 return $ chunkname === null || $ disk ->exists ($ directory . '/ ' . $ chunkname );
135137 }
138+
139+ /**
140+ * @param \Illuminate\Contracts\Filesystem\Filesystem $disk
141+ * @param string $mergedDirectory
142+ * @param string $targetFilename
143+ *
144+ * @return string
145+ */
146+ private function correctMergedExt (Filesystem $ disk , string $ mergedDirectory , string $ targetFilename ): string
147+ {
148+ $ targetPath = $ mergedDirectory . '/ ' . $ targetFilename ;
149+ $ ext = pathinfo ($ targetFilename , PATHINFO_EXTENSION );
150+ if ($ ext === 'bin ' ) {
151+ $ var = $ disk ->path ($ targetPath );
152+ $ uploadedFile = new UploadedFile ($ var , $ targetFilename );
153+ $ filename = pathinfo ($ targetFilename , PATHINFO_FILENAME );
154+ $ fixedTargetPath = $ mergedDirectory . '/ ' . $ filename . '. ' . $ uploadedFile ->guessExtension ();
155+ $ disk ->move ($ targetPath , $ fixedTargetPath );
156+ $ targetPath = $ fixedTargetPath ;
157+ }
158+ return $ targetPath ;
159+ }
136160}
0 commit comments