-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBackblazeB2.php
More file actions
119 lines (111 loc) · 3.89 KB
/
BackblazeB2.php
File metadata and controls
119 lines (111 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
namespace CloudFiles\Adapter;
use ExpressionEngine\Dependency\Aws\S3\S3Client;
use ExpressionEngine\Dependency\League\Flysystem;
use ExpressionEngine\Library\Filesystem\Adapter\AdapterInterface;
use ExpressionEngine\Library\Filesystem\Adapter\AdapterTrait;
use ExpressionEngine\Service\Validation\ValidationAware;
class BackblazeB2 extends Flysystem\AwsS3v3\AwsS3Adapter implements AdapterInterface, ValidationAware
{
use AdapterTrait;
protected $_validation_rules = [
'key' => 'required',
'secret' => 'required',
'region' => 'required',
'bucket' => 'required',
];
public function __construct($settings = [])
{
$this->settings = $settings;
$client = new S3Client([
'credentials' => [
'key' => $settings['key'],
'secret' => $settings['secret']
],
'region' => $settings['region'] ?: 'east-001',
'version' => 'latest',
'endpoint' => "https://s3.{$settings['region']}.backblazeb2.com",
'exception_class' => \ExpressionEngine\Dependency\Aws\S3\Exception\S3Exception::class
]);
parent::__construct($client, $settings['bucket']);
}
public static function getSettingsForm($settings)
{
return [
[
'title' => 'Application Key ID',
'desc' => 'Enter your Backblaze B2 Key ID',
'fields' => [
'adapter_settings[key]' => [
'type' => 'text',
'value' => $settings['key'] ?? '',
'required' => true
]
]
],
[
'title' => 'Application Key',
'desc' => 'Enter your Backblaze B2 Key',
'fields' => [
'adapter_settings[secret]' => [
'type' => 'text',
'value' => $settings['secret'] ?? '',
'required' => true
]
]
],
[
'title' => 'Region',
'desc' => 'Enter the region for your Backblaze B2 Bucket',
'fields' => [
'adapter_settings[region]' => [
'type' => 'text',
'value' => $settings['region'] ?? '',
'required' => true
]
]
],
[
'title' => 'Bucket Name',
'desc' => 'Enter the name of your Backblaze B2 Bucket',
'fields' => [
'adapter_settings[bucket]' => [
'type' => 'text',
'value' => $settings['bucket'] ?? '',
'required' => true
]
]
],
[
'title' => 'Path',
'desc' => 'Enter the path inside your Backblaze B2 Bucket',
'fields' => [
'server_path' => [
'type' => 'text',
'value' => $settings['server_path'] ?? '',
'required' => false
]
]
],
[
'title' => 'Url',
'desc' => 'Enter the url used to access your Backblaze B2 Bucket',
'fields' => [
'url' => [
'type' => 'text',
'value' => $settings['url'] ?? '',
'required' => false
]
]
]
];
}
public function getBaseUrl()
{
return implode('/', array_filter([
'https://s3.'.$this->settings['region'].'.backblazeb2.com',
$this->getBucket(),
$this->getPathPrefix()
]));
}
}