From bf507df4d5430c83ce195136d5b6529c4d724150 Mon Sep 17 00:00:00 2001 From: Ben Date: Sun, 4 Feb 2018 00:34:22 +0000 Subject: [PATCH 1/3] Added DO Spaces support --- readme.md | 15 +++++++++----- .../laravelcdn/Providers/AwsS3Provider.php | 3 +++ src/config/cdn.php | 20 +++++++++++++++++-- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/readme.md b/readme.md index 312efc2..eb8d5da 100644 --- a/readme.md +++ b/readme.md @@ -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 @@ -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" ``` @@ -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', @@ -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' => '*', @@ -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'], // ... @@ -295,6 +297,9 @@ The MIT License (MIT). Please see [License File](https://github.com/publiux/lara ## Changelog +#### v1.0.4 +- Added DigitalOcean Spaces support + #### v1.0.3 - Fixed bug where schemeless Urls could not be used for CloudFront. Valid urls now begin with http, https, or simply '//' diff --git a/src/Publiux/laravelcdn/Providers/AwsS3Provider.php b/src/Publiux/laravelcdn/Providers/AwsS3Provider.php index 7101a7a..168ef64 100644 --- a/src/Publiux/laravelcdn/Providers/AwsS3Provider.php +++ b/src/Publiux/laravelcdn/Providers/AwsS3Provider.php @@ -48,6 +48,7 @@ class AwsS3Provider extends Provider implements ProviderInterface 's3' => [ 'version' => null, 'region' => null, + 'endpoint' => null, 'buckets' => null, 'upload_folder' => '', 'http' => null, @@ -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'], @@ -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'] ] ) diff --git a/src/config/cdn.php b/src/config/cdn.php index 8de77ee..0ff2a22 100644 --- a/src/config/cdn.php +++ b/src/config/cdn.php @@ -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 @@ -117,7 +133,7 @@ // 'your-js-bucket-name-here' => ['public/js'], // 'your-css-bucket-name-here' => ['public/css'], ], - + /* |-------------------------------------------------------------------------- | CDN Bucket Upload Folder Prefix From dc56a3be3ccc0df7430d325acbecbd247aba0c81 Mon Sep 17 00:00:00 2001 From: Ben Date: Sun, 4 Feb 2018 00:49:41 +0000 Subject: [PATCH 2/3] Update the readme to be inline with releases --- readme.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index eb8d5da..d3a0e6d 100644 --- a/readme.md +++ b/readme.md @@ -297,8 +297,20 @@ The MIT License (MIT). Please see [License File](https://github.com/publiux/lara ## Changelog -#### v1.0.4 -- Added DigitalOcean Spaces support +#### 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 '//' From 295935b96db35bd974f9009c4af2b8e34f458881 Mon Sep 17 00:00:00 2001 From: Ben Date: Sun, 4 Feb 2018 01:58:45 +0000 Subject: [PATCH 3/3] Update Facade references in docs to avoid confusion It gets auto-registered as CDN in 5.5+, so updated docs to be consistent no matter the version. Even if you add the service provider yourself --- readme.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/readme.md b/readme.md index d3a0e6d..621d15c 100644 --- a/readme.md +++ b/readme.md @@ -57,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 ), ``` @@ -233,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 ```