-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e1d4f22
commit 246fde0
Showing
5 changed files
with
111 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace Utopia\Storage\Device; | ||
|
||
use Utopia\Storage\Storage; | ||
|
||
class CloudflareR2 extends S3 | ||
{ | ||
|
||
/** | ||
* Regions constants | ||
*/ | ||
|
||
/** | ||
* Regions constants | ||
*/ | ||
|
||
const WNAM = 'us-west-1'; | ||
|
||
const ENAM = 'us-east-1'; | ||
|
||
const WEUR = 'eu-west-1'; | ||
|
||
const EEUR = 'eu-east-1'; | ||
|
||
const APAC = 'ap-southeast-1'; | ||
|
||
const AUTO = 'auto'; | ||
|
||
/** | ||
* CloudflareR2 Constructor | ||
* | ||
* @param string $root | ||
* @param string $accessKey | ||
* @param string $secretKey | ||
* @param string $bucket | ||
* @param string $region | ||
* @param string $acl | ||
*/ | ||
|
||
public function __construct(string $root, string $accessKey, string $secretKey, string $bucket, string $region = self::APAC, string $acl = self::ACL_PRIVATE) | ||
{ | ||
parent::__construct($root, $accessKey, $secretKey, $bucket, $region, $acl); | ||
$this->headers['host'] = $bucket.'.'.'s3'.'.'.$region.'.cloudflarestorage.com'; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName(): string | ||
{ | ||
return 'Cloudflare R2 Storage'; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getDescription(): string | ||
{ | ||
return 'Cloudflare R2 Storage'; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getType(): string | ||
{ | ||
return Storage::DEVICE_CLOUDFLARER2; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Utopia\Tests\Storage\Device; | ||
|
||
use Utopia\Storage\Device\CloudflareR2; | ||
use Utopia\Tests\Storage\S3Base; | ||
|
||
class CloudfareR2Test extends S3Base | ||
{ | ||
protected function init(): void | ||
{ | ||
$this->root = '/root'; | ||
$key = $_SERVER['CLOUDFLARE_R2_ACCESS_KEY'] ?? ''; | ||
$secret = $_SERVER['CLOUDFLARE_R2_SECRET'] ?? ''; | ||
$bucket = 'utopia-storage-test'; | ||
|
||
$this->object = new CloudflareR2($this->root, $key, $secret, $bucket, CloudflareR2:: AUTO , CloudflareR2::ACL_PRIVATE); | ||
} | ||
|
||
protected function getAdapterName(): string | ||
{ | ||
return 'Cloudflare R2 Storage'; | ||
} | ||
|
||
protected function getAdapterType(): string | ||
{ | ||
return $this->object->getType(); | ||
} | ||
|
||
protected function getAdapterDescription(): string | ||
{ | ||
return 'Cloudflare R2 Storage'; | ||
} | ||
} |