Skip to content

Commit

Permalink
fix: simplify abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
nerg4l committed Apr 1, 2024
1 parent 69a6380 commit 78914f8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
16 changes: 4 additions & 12 deletions src/Http/Controller/S3MultipartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,13 @@ public function create(Request $request)
$key = implode('-', [Str::random(), $data['filename']]);

$params = [
'Bucket' => $this->adapter->getConfig()['bucket'],
'Key' => $this->adapter->path($key),
'ContentType' => $data['type'],
'Metadata' => $this->encodeMetadata($data['metadata']),
];

// TODO: read optional ACL from config

$result = $this->adapter->createMultipartUpload($params);
$result = $this->adapter->createMultipartUpload($key, $params);

return Response::json([
'key' => $result['Key'],
Expand Down Expand Up @@ -133,9 +131,7 @@ public function uploadedParts(Request $request)
$parts = Collection::make();
$partIndex = 0;
do {
$result = $this->adapter->listParts([
'Bucket' => $this->adapter->getConfig()['bucket'],
'Key' => $this->adapter->path($key),
$result = $this->adapter->listParts($key, [
'UploadId' => $uploadId,
'PartNumberMarker' => $partIndex,
]);
Expand Down Expand Up @@ -229,9 +225,7 @@ public function abort(Request $request)
$data = Validator::make($request->query(), ['key' => ['required', 'string']])->validate();
$key = $data['key'];

$this->adapter->abortMultipartUpload([
'Bucket' => $this->adapter->getConfig()['bucket'],
'Key' => $this->adapter->path($key),
$this->adapter->abortMultipartUpload($key, [
'UploadId' => $uploadId,
]);

Expand Down Expand Up @@ -262,9 +256,7 @@ public function complete(Request $request)
'parts.*.ETag' => ['required', 'string'],
]);

$result = $this->adapter->completeMultipartUpload([
'Bucket' => $this->adapter->getConfig()['bucket'],
'Key' => $this->adapter->path($key),
$result = $this->adapter->completeMultipartUpload($key, [
'UploadId' => $uploadId,
'MultipartUpload' => [
'Parts' => $data['parts'],
Expand Down
28 changes: 20 additions & 8 deletions src/MultipartOfMadness.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,35 @@ public function temporaryUploadPartUrl($path, $uploadId, $partNumber, $expiratio
];
}

public function listParts(array $args = [])
public function listParts($path, array $args = [])
{
return $this->client->listParts($args);
return $this->client->listParts(array_merge([
'Bucket' => $this->config['bucket'],
'Key' => $this->prefixer->prefixPath($path),
], $args));
}

public function createMultipartUpload(array $args = [])
public function createMultipartUpload($path, array $args = [])
{
return $this->client->createMultipartUpload($args);
return $this->client->createMultipartUpload(array_merge([
'Bucket' => $this->config['bucket'],
'Key' => $this->prefixer->prefixPath($path),
], $args));
}

public function completeMultipartUpload(array $args = [])
public function completeMultipartUpload($path, array $args = [])
{
return $this->client->completeMultipartUpload($args);
return $this->client->completeMultipartUpload(array_merge([
'Bucket' => $this->config['bucket'],
'Key' => $this->prefixer->prefixPath($path),
], $args));
}

public function abortMultipartUpload(array $args = [])
public function abortMultipartUpload($path, array $args = [])
{
return $this->client->abortMultipartUpload($args);
return $this->client->abortMultipartUpload(array_merge([
'Bucket' => $this->config['bucket'],
'Key' => $this->prefixer->prefixPath($path),
], $args));
}
}

0 comments on commit 78914f8

Please sign in to comment.