44
55use Closure ;
66use CodingSocks \ChunkUploader \Helper \ChunkHelpers ;
7+ use CodingSocks \ChunkUploader \Identifier \Identifier ;
78use CodingSocks \ChunkUploader \Range \ResumableJsRange ;
89use CodingSocks \ChunkUploader \Response \PercentageJsonResponse ;
910use CodingSocks \ChunkUploader \StorageConfig ;
@@ -24,6 +25,11 @@ class ResumableJsUploadDriver extends UploadDriver
2425 */
2526 private $ fileParam ;
2627
28+ /**
29+ * @var \CodingSocks\ChunkUploader\Identifier\Identifier
30+ */
31+ private $ identifier ;
32+
2733 /**
2834 * @var string
2935 */
@@ -48,10 +54,12 @@ class ResumableJsUploadDriver extends UploadDriver
4854 * ResumableJsUploadDriver constructor.
4955 *
5056 * @param array $config
57+ * @param \CodingSocks\ChunkUploader\Identifier\Identifier $identifier
5158 */
52- public function __construct ($ config )
59+ public function __construct ($ config, Identifier $ identifier )
5360 {
5461 $ this ->fileParam = $ config ['param ' ];
62+ $ this ->identifier = $ identifier ;
5563
5664 $ this ->uploadMethod = $ config ['upload-method ' ];
5765 $ this ->testMethod = $ config ['test-method ' ];
@@ -101,10 +109,10 @@ public function resume(Request $request, StorageConfig $config): Response
101109 throw new BadRequestHttpException ($ e ->getMessage (), $ e );
102110 }
103111
104- $ filename = $ request ->query ($ this ->buildParameterName ('identifier ' ));
112+ $ uid = $ this -> identifier -> generateIdentifier ( $ request ->query ($ this ->buildParameterName ('identifier ' ) ));
105113 $ chunkname = $ this ->buildChunkname ($ range );
106114
107- if (! $ this ->chunkExists ($ config , $ filename , $ chunkname )) {
115+ if (! $ this ->chunkExists ($ config , $ uid , $ chunkname )) {
108116 return new Response ('' , Response::HTTP_NO_CONTENT );
109117 }
110118
@@ -165,9 +173,10 @@ private function saveChunk(UploadedFile $file, Request $request, StorageConfig $
165173 throw new BadRequestHttpException ($ e ->getMessage (), $ e );
166174 }
167175
168- $ uuid = $ request ->post ($ this ->buildParameterName ('identifier ' ));
176+ $ weakId = $ request ->post ($ this ->buildParameterName ('identifier ' ));
177+ $ uid = $ this ->identifier ->generateIdentifier ($ weakId );
169178
170- $ chunks = $ this ->storeChunk ($ config , $ range , $ file , $ uuid );
179+ $ chunks = $ this ->storeChunk ($ config , $ range , $ file , $ uid );
171180
172181 if (!$ range ->isFinished ($ chunks )) {
173182 return new PercentageJsonResponse ($ range ->getPercentage ($ chunks ));
@@ -178,7 +187,7 @@ private function saveChunk(UploadedFile $file, Request $request, StorageConfig $
178187 $ path = $ this ->mergeChunks ($ config , $ chunks , $ targetFilename );
179188
180189 if ($ config ->sweep ()) {
181- $ this ->deleteChunkDirectory ($ config , $ uuid );
190+ $ this ->deleteChunkDirectory ($ config , $ uid );
182191 }
183192
184193 $ this ->triggerFileUploadedEvent ($ config ->getDisk (), $ path , $ fileUploaded );
0 commit comments