Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added DO Spaces support #31

Merged
merged 3 commits into from
Feb 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 32 additions & 15 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ This project has been forked from https://github.com/Vinelab/cdn. All credit for

## Highlights

- Amazon Web Services - S3
- Amazon Web Services (AWS) - S3
- DigitalOcean (DO) - Spaces
- Artisan command to upload content to CDN
- Simple Facade to access CDN assets

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

Require `publiux/laravelcdn` in your project:

```bash
```bash
composer require "publiux/laravelcdn:~2.0"
```

Expand All @@ -56,7 +57,7 @@ Laravel 5.4 and below: Add the service provider and facade to `config/app.php`:
```php
'aliases' => array(
//...
'Cdn' => Publiux\laravelcdn\Facades\CdnFacadeAccessor::class
'CDN' => Publiux\laravelcdn\Facades\CdnFacadeAccessor::class
),
```

Expand Down Expand Up @@ -127,7 +128,7 @@ CDN_CloudFrontUrl=
```

##### Default CDN Provider
For now, the only CDN provider available is AwsS3. This option cannot be set in '.env'.
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'.

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

's3' => [

'version' => 'latest',
'region' => '',
'endpoint' => '', // For DO Spaces

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

'my-default-bucket' => '*',

// 'js-bucket' => ['public/js'],
// 'css-bucket' => ['public/css'],
// ...
Expand Down Expand Up @@ -231,32 +233,32 @@ CAUTION: This will erase your entire bucket. This may not be what you want if yo

#### Load Assets

Use the facade `Cdn` to call the `Cdn::asset()` function.
Use the facade `CDN` to call the `CDN::asset()` function.

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

```blade
{{Cdn::asset('assets/js/main.js')}} // example result: https://js-bucket.s3.amazonaws.com/public/assets/js/main.js
{{CDN::asset('assets/js/main.js')}} // example result: https://js-bucket.s3.amazonaws.com/public/assets/js/main.js

{{Cdn::asset('assets/css/style.css')}} // example result: https://css-bucket.s3.amazonaws.com/public/assets/css/style.css
{{CDN::asset('assets/css/style.css')}} // example result: https://css-bucket.s3.amazonaws.com/public/assets/css/style.css
```
*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:*
```blade
{{Cdn::elixir('assets/js/main.js')}} // example result: https://js-bucket.s3.amazonaws.com/public/build/assets/js/main-85cafe36ff.js
{{CDN::elixir('assets/js/main.js')}} // example result: https://js-bucket.s3.amazonaws.com/public/build/assets/js/main-85cafe36ff.js

{{Cdn::elixir('assets/css/style.css')}} // example result: https://css-bucket.s3.amazonaws.com/public/build/assets/css/style-2d558139f2.css
{{CDN::elixir('assets/css/style.css')}} // example result: https://css-bucket.s3.amazonaws.com/public/build/assets/css/style-2d558139f2.css
```
*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:*
```blade
{{Cdn::mix('/js/main.js')}} // example result: https://js-bucket.s3.amazonaws.com/public/js/main-85cafe36ff.js
{{CDN::mix('/js/main.js')}} // example result: https://js-bucket.s3.amazonaws.com/public/js/main-85cafe36ff.js

{{Cdn::mix('/css/style.css')}} // example result: https://css-bucket.s3.amazonaws.com/public/css/style-2d558139f2.css
{{CDN::mix('/css/style.css')}} // example result: https://css-bucket.s3.amazonaws.com/public/css/style-2d558139f2.css
```

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

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


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

## Changelog

#### v2.0.4
- Added API support for DigitalOcean Spaces

#### v2.0.3
- Added support for an upload folder prefix

#### v2.0.2
- Updated readme to detail instructions on Laravel <5.5 usage

#### v2.0.1
- Fixed typo in composer.json

#### v2.0.0
- Support for Laravel 5.5

#### v1.0.3
- Fixed bug where schemeless Urls could not be used for CloudFront. Valid urls now begin with http, https, or simply '//'

Expand Down
3 changes: 3 additions & 0 deletions src/Publiux/laravelcdn/Providers/AwsS3Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class AwsS3Provider extends Provider implements ProviderInterface
's3' => [
'version' => null,
'region' => null,
'endpoint' => null,
'buckets' => null,
'upload_folder' => '',
'http' => null,
Expand Down Expand Up @@ -134,6 +135,7 @@ public function init($configurations)
'threshold' => $this->default['threshold'],
'version' => $this->default['providers']['aws']['s3']['version'],
'region' => $this->default['providers']['aws']['s3']['region'],
'endpoint' => $this->default['providers']['aws']['s3']['endpoint'],
'buckets' => $this->default['providers']['aws']['s3']['buckets'],
'acl' => $this->default['providers']['aws']['s3']['acl'],
'cloudfront' => $this->default['providers']['aws']['s3']['cloudfront']['use'],
Expand Down Expand Up @@ -226,6 +228,7 @@ public function connect()
$this->setS3Client(new S3Client([
'version' => $this->supplier['version'],
'region' => $this->supplier['region'],
'endpoint' => $this->supplier['endpoint'],
'http' => $this->supplier['http']
]
)
Expand Down
20 changes: 18 additions & 2 deletions src/config/cdn.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,27 @@
|--------------------------------------------------------------------------
|
| List of available regions:
| http://docs.aws.amazon.com/general/latest/gr/rande.html#awsconfig_region
| https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
|
*/
'region' => '',

/*
|--------------------------------------------------------------------------
| Endpoint to use
|--------------------------------------------------------------------------
|
| List of available endpoints for regions:
| https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
|
| For DigitalOcean Spaces:
| This can be found in the settings panel on the cloud UI, further info:
| https://www.digitalocean.com/community/tutorials/an-introduction-to-digitalocean-spaces#creating-new-spaces
| https://www.digitalocean.com/community/questions/how-to-use-digitalocean-spaces-with-the-aws-s3-sdks?answer=39594
|
*/
'endpoint' => '',

/*
|--------------------------------------------------------------------------
| CDN Bucket
Expand All @@ -117,7 +133,7 @@
// 'your-js-bucket-name-here' => ['public/js'],
// 'your-css-bucket-name-here' => ['public/css'],
],

/*
|--------------------------------------------------------------------------
| CDN Bucket Upload Folder Prefix
Expand Down