Skip to content

Commit 7dd0953

Browse files
authored
Merge pull request #31 from othyn/master
Added DO (DigitalOcean) Spaces support by allowing the setting of 'endpoint' per DO's docs on S3 library interchangeability.
2 parents 1b1d6bf + 295935b commit 7dd0953

File tree

3 files changed

+53
-17
lines changed

3 files changed

+53
-17
lines changed

readme.md

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ This project has been forked from https://github.com/Vinelab/cdn. All credit for
2121

2222
## Highlights
2323

24-
- Amazon Web Services - S3
24+
- Amazon Web Services (AWS) - S3
25+
- DigitalOcean (DO) - Spaces
2526
- Artisan command to upload content to CDN
2627
- Simple Facade to access CDN assets
2728

@@ -38,7 +39,7 @@ This project has been forked from https://github.com/Vinelab/cdn. All credit for
3839

3940
Require `publiux/laravelcdn` in your project:
4041

41-
```bash
42+
```bash
4243
composer require "publiux/laravelcdn:~2.0"
4344
```
4445

@@ -56,7 +57,7 @@ Laravel 5.4 and below: Add the service provider and facade to `config/app.php`:
5657
```php
5758
'aliases' => array(
5859
//...
59-
'Cdn' => Publiux\laravelcdn\Facades\CdnFacadeAccessor::class
60+
'CDN' => Publiux\laravelcdn\Facades\CdnFacadeAccessor::class
6061
),
6162
```
6263

@@ -127,7 +128,7 @@ CDN_CloudFrontUrl=
127128
```
128129

129130
##### Default CDN Provider
130-
For now, the only CDN provider available is AwsS3. This option cannot be set in '.env'.
131+
For now, the only CDN provider available is AwsS3. Although, as DO natively support the AWS API, you can utilise it by also providing the endpoint, please see the cdn.php config for more info. This option cannot be set in '.env'.
131132

132133
```php
133134
'default' => 'AwsS3',
@@ -139,9 +140,10 @@ For now, the only CDN provider available is AwsS3. This option cannot be set in
139140
'aws' => [
140141

141142
's3' => [
142-
143+
143144
'version' => 'latest',
144145
'region' => '',
146+
'endpoint' => '', // For DO Spaces
145147

146148
'buckets' => [
147149
'my-backup-bucket' => '*',
@@ -156,7 +158,7 @@ For now, the only CDN provider available is AwsS3. This option cannot be set in
156158
'buckets' => [
157159

158160
'my-default-bucket' => '*',
159-
161+
160162
// 'js-bucket' => ['public/js'],
161163
// 'css-bucket' => ['public/css'],
162164
// ...
@@ -231,32 +233,32 @@ CAUTION: This will erase your entire bucket. This may not be what you want if yo
231233

232234
#### Load Assets
233235

234-
Use the facade `Cdn` to call the `Cdn::asset()` function.
236+
Use the facade `CDN` to call the `CDN::asset()` function.
235237

236238
*Note: the `asset` works the same as the Laravel `asset` it start looking for assets in the `public/` directory:*
237239

238240
```blade
239-
{{Cdn::asset('assets/js/main.js')}} // example result: https://js-bucket.s3.amazonaws.com/public/assets/js/main.js
241+
{{CDN::asset('assets/js/main.js')}} // example result: https://js-bucket.s3.amazonaws.com/public/assets/js/main.js
240242
241-
{{Cdn::asset('assets/css/style.css')}} // example result: https://css-bucket.s3.amazonaws.com/public/assets/css/style.css
243+
{{CDN::asset('assets/css/style.css')}} // example result: https://css-bucket.s3.amazonaws.com/public/assets/css/style.css
242244
```
243245
*Note: the `elixir` works the same as the Laravel `elixir` it loads the manifest.json file from build folder and choose the correct file revision generated by gulp:*
244246
```blade
245-
{{Cdn::elixir('assets/js/main.js')}} // example result: https://js-bucket.s3.amazonaws.com/public/build/assets/js/main-85cafe36ff.js
247+
{{CDN::elixir('assets/js/main.js')}} // example result: https://js-bucket.s3.amazonaws.com/public/build/assets/js/main-85cafe36ff.js
246248
247-
{{Cdn::elixir('assets/css/style.css')}} // example result: https://css-bucket.s3.amazonaws.com/public/build/assets/css/style-2d558139f2.css
249+
{{CDN::elixir('assets/css/style.css')}} // example result: https://css-bucket.s3.amazonaws.com/public/build/assets/css/style-2d558139f2.css
248250
```
249251
*Note: the `mix` works the same as the Laravel 5.4 `mix` it loads the mix-manifest.json file from public folder and choose the correct file revision generated by webpack:*
250252
```blade
251-
{{Cdn::mix('/js/main.js')}} // example result: https://js-bucket.s3.amazonaws.com/public/js/main-85cafe36ff.js
253+
{{CDN::mix('/js/main.js')}} // example result: https://js-bucket.s3.amazonaws.com/public/js/main-85cafe36ff.js
252254
253-
{{Cdn::mix('/css/style.css')}} // example result: https://css-bucket.s3.amazonaws.com/public/css/style-2d558139f2.css
255+
{{CDN::mix('/css/style.css')}} // example result: https://css-bucket.s3.amazonaws.com/public/css/style-2d558139f2.css
254256
```
255257

256-
To use a file from outside the `public/` directory, anywhere in `app/` use the `Cdn::path()` function:
258+
To use a file from outside the `public/` directory, anywhere in `app/` use the `CDN::path()` function:
257259

258260
```blade
259-
{{Cdn::path('private/something/file.txt')}} // example result: https://css-bucket.s3.amazonaws.com/private/something/file.txt
261+
{{CDN::path('private/something/file.txt')}} // example result: https://css-bucket.s3.amazonaws.com/private/something/file.txt
260262
```
261263

262264

@@ -295,6 +297,21 @@ The MIT License (MIT). Please see [License File](https://github.com/publiux/lara
295297

296298
## Changelog
297299

300+
#### v2.0.4
301+
- Added API support for DigitalOcean Spaces
302+
303+
#### v2.0.3
304+
- Added support for an upload folder prefix
305+
306+
#### v2.0.2
307+
- Updated readme to detail instructions on Laravel <5.5 usage
308+
309+
#### v2.0.1
310+
- Fixed typo in composer.json
311+
312+
#### v2.0.0
313+
- Support for Laravel 5.5
314+
298315
#### v1.0.3
299316
- Fixed bug where schemeless Urls could not be used for CloudFront. Valid urls now begin with http, https, or simply '//'
300317

src/Publiux/laravelcdn/Providers/AwsS3Provider.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class AwsS3Provider extends Provider implements ProviderInterface
4848
's3' => [
4949
'version' => null,
5050
'region' => null,
51+
'endpoint' => null,
5152
'buckets' => null,
5253
'upload_folder' => '',
5354
'http' => null,
@@ -134,6 +135,7 @@ public function init($configurations)
134135
'threshold' => $this->default['threshold'],
135136
'version' => $this->default['providers']['aws']['s3']['version'],
136137
'region' => $this->default['providers']['aws']['s3']['region'],
138+
'endpoint' => $this->default['providers']['aws']['s3']['endpoint'],
137139
'buckets' => $this->default['providers']['aws']['s3']['buckets'],
138140
'acl' => $this->default['providers']['aws']['s3']['acl'],
139141
'cloudfront' => $this->default['providers']['aws']['s3']['cloudfront']['use'],
@@ -226,6 +228,7 @@ public function connect()
226228
$this->setS3Client(new S3Client([
227229
'version' => $this->supplier['version'],
228230
'region' => $this->supplier['region'],
231+
'endpoint' => $this->supplier['endpoint'],
229232
'http' => $this->supplier['http']
230233
]
231234
)

src/config/cdn.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,27 @@
9191
|--------------------------------------------------------------------------
9292
|
9393
| List of available regions:
94-
| http://docs.aws.amazon.com/general/latest/gr/rande.html#awsconfig_region
94+
| https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
9595
|
9696
*/
9797
'region' => '',
9898

99+
/*
100+
|--------------------------------------------------------------------------
101+
| Endpoint to use
102+
|--------------------------------------------------------------------------
103+
|
104+
| List of available endpoints for regions:
105+
| https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
106+
|
107+
| For DigitalOcean Spaces:
108+
| This can be found in the settings panel on the cloud UI, further info:
109+
| https://www.digitalocean.com/community/tutorials/an-introduction-to-digitalocean-spaces#creating-new-spaces
110+
| https://www.digitalocean.com/community/questions/how-to-use-digitalocean-spaces-with-the-aws-s3-sdks?answer=39594
111+
|
112+
*/
113+
'endpoint' => '',
114+
99115
/*
100116
|--------------------------------------------------------------------------
101117
| CDN Bucket
@@ -117,7 +133,7 @@
117133
// 'your-js-bucket-name-here' => ['public/js'],
118134
// 'your-css-bucket-name-here' => ['public/css'],
119135
],
120-
136+
121137
/*
122138
|--------------------------------------------------------------------------
123139
| CDN Bucket Upload Folder Prefix

0 commit comments

Comments
 (0)