Skip to content

Commit

Permalink
override listobjects in backblaze
Browse files Browse the repository at this point in the history
  • Loading branch information
lohanidamodar committed Apr 2, 2024
1 parent c03df55 commit 7c0a762
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
36 changes: 36 additions & 0 deletions src/Storage/Device/Backblaze.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Utopia\Storage\Device;

use Exception;
use Utopia\Storage\Storage;

class Backblaze extends S3
Expand Down Expand Up @@ -61,4 +62,39 @@ public function getType(): string
{
return Storage::DEVICE_BACKBLAZE;
}

/**
* Get list of objects in the given path.
*
* @param string $prefix
* @param int $maxKeys
* @param string $continuationToken
* @return array
*
* @throws Exception
*/
protected function listObjects(string $prefix = '', int $maxKeys = self::MAX_PAGE_SIZE, string $continuationToken = ''): array
{
if ($maxKeys > S3::MAX_PAGE_SIZE) {
throw new Exception('Cannot list more than '.S3::MAX_PAGE_SIZE.' objects');
}

$uri = '/';
$prefix = ltrim($prefix, '/'); /** S3 specific requirement that prefix should never contain a leading slash */
$this->headers['content-type'] = 'text/plain';
$this->headers['content-md5'] = \base64_encode(md5('', true));

$parameters = [
'prefix' => $prefix,
'max-keys' => $maxKeys,
];

if (! empty($continuationToken)) {
$parameters['continuation-token'] = $continuationToken;
}

$response = $this->call(S3::METHOD_GET, $uri, '', $parameters);

return $response->body;
}
}
4 changes: 2 additions & 2 deletions src/Storage/Device/S3.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ public function delete(string $path, bool $recursive = false): bool
*
* @throws Exception
*/
private function listObjects(string $prefix = '', int $maxKeys = self::MAX_PAGE_SIZE, string $continuationToken = ''): array
protected function listObjects(string $prefix = '', int $maxKeys = self::MAX_PAGE_SIZE, string $continuationToken = ''): array
{
if ($maxKeys > self::MAX_PAGE_SIZE) {
throw new Exception('Cannot list more than '.self::MAX_PAGE_SIZE.' objects');
Expand Down Expand Up @@ -826,7 +826,7 @@ private function getSignatureV4(string $method, string $uri, array $parameters =
*
* @throws \Exception
*/
private function call(string $method, string $uri, string $data = '', array $parameters = [], bool $decode = true)
protected function call(string $method, string $uri, string $data = '', array $parameters = [], bool $decode = true)
{
$uri = $this->getAbsolutePath($uri);
$url = 'https://'.$this->headers['host'].$uri.'?'.\http_build_query($parameters, '', '&', PHP_QUERY_RFC3986);
Expand Down

0 comments on commit 7c0a762

Please sign in to comment.