Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 4 additions & 7 deletions src/Driver/FlowJsUploadDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

namespace CodingSocks\ChunkUploader\Driver;

use CodingSocks\ChunkUploader\Identifier\Identifier;

class FlowJsUploadDriver extends ResumableJsUploadDriver
{
/**
* ResumableJsUploadDriver constructor.
*
* @param array $config
*/
public function __construct($config)
public function __construct($config, Identifier $identifier)
{
$config['parameter-namespace'] = '';
$config['parameter-names'] = [
Expand All @@ -30,6 +27,6 @@ public function __construct($config)
// The name of the current chunk size POST parameter to use for the file chunk.
'current-chunk-size' => 'flowCurrentChunkSize',
];
parent::__construct($config);
parent::__construct($config, $identifier);
}
}
21 changes: 15 additions & 6 deletions src/Driver/ResumableJsUploadDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Closure;
use CodingSocks\ChunkUploader\Helper\ChunkHelpers;
use CodingSocks\ChunkUploader\Identifier\Identifier;
use CodingSocks\ChunkUploader\Range\ResumableJsRange;
use CodingSocks\ChunkUploader\Response\PercentageJsonResponse;
use CodingSocks\ChunkUploader\StorageConfig;
Expand All @@ -24,6 +25,11 @@ class ResumableJsUploadDriver extends UploadDriver
*/
private $fileParam;

/**
* @var \CodingSocks\ChunkUploader\Identifier\Identifier
*/
private $identifier;

/**
* @var string
*/
Expand All @@ -48,10 +54,12 @@ class ResumableJsUploadDriver extends UploadDriver
* ResumableJsUploadDriver constructor.
*
* @param array $config
* @param \CodingSocks\ChunkUploader\Identifier\Identifier $identifier
*/
public function __construct($config)
public function __construct($config, Identifier $identifier)
{
$this->fileParam = $config['param'];
$this->identifier = $identifier;

$this->uploadMethod = $config['upload-method'];
$this->testMethod = $config['test-method'];
Expand Down Expand Up @@ -101,10 +109,10 @@ public function resume(Request $request, StorageConfig $config): Response
throw new BadRequestHttpException($e->getMessage(), $e);
}

$filename = $request->query($this->buildParameterName('identifier'));
$uid = $this->identifier->generateIdentifier($request->query($this->buildParameterName('identifier')));
$chunkname = $this->buildChunkname($range);

if (! $this->chunkExists($config, $filename, $chunkname)) {
if (! $this->chunkExists($config, $uid, $chunkname)) {
return new Response('', Response::HTTP_NO_CONTENT);
}

Expand Down Expand Up @@ -165,9 +173,10 @@ private function saveChunk(UploadedFile $file, Request $request, StorageConfig $
throw new BadRequestHttpException($e->getMessage(), $e);
}

$uuid = $request->post($this->buildParameterName('identifier'));
$weakId = $request->post($this->buildParameterName('identifier'));
$uid = $this->identifier->generateIdentifier($weakId);

$chunks = $this->storeChunk($config, $range, $file, $uuid);
$chunks = $this->storeChunk($config, $range, $file, $uid);

if (!$range->isFinished($chunks)) {
return new PercentageJsonResponse($range->getPercentage($chunks));
Expand All @@ -178,7 +187,7 @@ private function saveChunk(UploadedFile $file, Request $request, StorageConfig $
$path = $this->mergeChunks($config, $chunks, $targetFilename);

if ($config->sweep()) {
$this->deleteChunkDirectory($config, $uuid);
$this->deleteChunkDirectory($config, $uid);
}

$this->triggerFileUploadedEvent($config->getDisk(), $path, $fileUploaded);
Expand Down
6 changes: 4 additions & 2 deletions src/Driver/SimpleUploaderJsUploadDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace CodingSocks\ChunkUploader\Driver;

use CodingSocks\ChunkUploader\Identifier\Identifier;

class SimpleUploaderJsUploadDriver extends ResumableJsUploadDriver
{
public function __construct($config)
public function __construct($config, Identifier $identifier)
{
$config['parameter-namespace'] = '';
$config['parameter-names'] = [
Expand All @@ -25,6 +27,6 @@ public function __construct($config)
// The name of the current chunk size POST parameter to use for the file chunk.
'current-chunk-size' => 'currentChunkSize',
];
parent::__construct($config);
parent::__construct($config, $identifier);
}
}
24 changes: 13 additions & 11 deletions src/UploadManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,33 +34,35 @@ public function createDropzoneDriver()

public function createFlowJsDriver()
{
return new FlowJsUploadDriver($this->app['config']['chunk-uploader.resumable-js']);
return new FlowJsUploadDriver($this->app['config']['chunk-uploader.resumable-js'], $this->identityManager()->driver());
}

public function createNgFileUploadDriver()
{
/** @var \Illuminate\Support\Manager $identityManager */
$identityManager = $this->app['chunk-uploader.identity-manager'];

return new NgFileUploadDriver($identityManager->driver());
return new NgFileUploadDriver($this->identityManager()->driver());
}

public function createPluploadDriver()
{
/** @var \Illuminate\Support\Manager $identityManager */
$identityManager = $this->app['chunk-uploader.identity-manager'];

return new PluploadUploadDriver($identityManager->driver());
return new PluploadUploadDriver($this->identityManager()->driver());
}

public function createResumableJsDriver()
{
return new ResumableJsUploadDriver($this->app['config']['chunk-uploader.resumable-js']);
return new ResumableJsUploadDriver($this->app['config']['chunk-uploader.resumable-js'], $this->identityManager()->driver());
}

public function createSimpleUploaderJsDriver()
{
return new SimpleUploaderJsUploadDriver($this->app['config']['chunk-uploader.simple-uploader-js']);
return new SimpleUploaderJsUploadDriver($this->app['config']['chunk-uploader.simple-uploader-js'], $this->identityManager()->driver());
}

/**
* @return \Illuminate\Support\Manager
*/
protected function identityManager()
{
return $this->app['chunk-uploader.identity-manager'];
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/Driver/FlowJsUploadDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ protected function setUp(): void
{
parent::setUp();

$this->app->make('config')->set('chunk-uploader.identifier', 'nop');
$this->app->make('config')->set('chunk-uploader.uploader', 'flow-js');
$this->app->make('config')->set('chunk-uploader.sweep', false);
$this->handler = $this->app->make(UploadHandler::class);
Expand Down
1 change: 1 addition & 0 deletions tests/Driver/ResumableJsUploadDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ protected function setUp(): void
{
parent::setUp();

$this->app->make('config')->set('chunk-uploader.identifier', 'nop');
$this->app->make('config')->set('chunk-uploader.uploader', 'resumable-js');
$this->app->make('config')->set('chunk-uploader.sweep', false);
$this->handler = $this->app->make(UploadHandler::class);
Expand Down
1 change: 1 addition & 0 deletions tests/Driver/SimpleUploaderUploadDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ protected function setUp(): void
{
parent::setUp();

$this->app->make('config')->set('chunk-uploader.identifier', 'nop');
$this->app->make('config')->set('chunk-uploader.uploader', 'simple-uploader-js');
$this->app->make('config')->set('chunk-uploader.sweep', false);
$this->handler = $this->app->make(UploadHandler::class);
Expand Down