From 6fd628144475b4e4fa398630a9784d5fb1c542e5 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Mon, 7 Sep 2020 16:43:40 -0400 Subject: [PATCH 1/3] Make glide routes for every subdirectory based site --- routes/web.php | 18 +++++++++++++----- src/Http/Controllers/GlideController.php | 5 ++++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/routes/web.php b/routes/web.php index b18cb266cb..a253a5a8ad 100755 --- a/routes/web.php +++ b/routes/web.php @@ -2,6 +2,8 @@ use Illuminate\Support\Facades\Route; use Statamic\Facades\OAuth; +use Statamic\Facades\Site; +use Statamic\Facades\URL; use Statamic\Statamic; Route::name('statamic.')->group(function () { @@ -9,11 +11,17 @@ * Glide * On-the-fly URL-based image transforms. */ - Route::group(['prefix' => Config::get('statamic.assets.image_manipulation.route')], function () { - Route::get('/asset/{container}/{path?}', 'GlideController@generateByAsset')->where('path', '.*'); - Route::get('/http/{url}/{filename?}', 'GlideController@generateByUrl'); - Route::get('{path}', 'GlideController@generateByPath')->where('path', '.*'); - }); + if (!config('statamic.assets.image_manipulation.cache')) { + Site::all()->map(function ($site) { + return URL::makeRelative($site->url()); + })->unique()->each(function ($sitePrefix) { + Route::group(['prefix' => $sitePrefix.'/'.config('statamic.assets.image_manipulation.route')], function () { + Route::get('/asset/{container}/{path?}', 'GlideController@generateByAsset')->where('path', '.*'); + Route::get('/http/{url}/{filename?}', 'GlideController@generateByUrl'); + Route::get('{path}', 'GlideController@generateByPath')->where('path', '.*'); + }); + }); + } Route::group(['prefix' => config('statamic.routes.action')], function () { Route::post('forms/{form}', 'FormController@submit')->name('forms.submit'); diff --git a/src/Http/Controllers/GlideController.php b/src/Http/Controllers/GlideController.php index 7dd88d8873..9e38d07711 100644 --- a/src/Http/Controllers/GlideController.php +++ b/src/Http/Controllers/GlideController.php @@ -10,6 +10,7 @@ use Statamic\Facades\Asset; use Statamic\Facades\AssetContainer; use Statamic\Facades\Config; +use Statamic\Facades\Site; use Statamic\Imaging\ImageGenerator; use Statamic\Support\Str; @@ -141,8 +142,10 @@ private function validateSignature() return; } + $path = Str::after($this->request->url(), Site::current()->absoluteUrl()); + try { - SignatureFactory::create(Config::getAppKey())->validateRequest($this->request->path(), $_GET); + SignatureFactory::create(Config::getAppKey())->validateRequest($path, $_GET); } catch (SignatureException $e) { abort(400, $e->getMessage()); } From 99c6b5e47e0e58811aeaed2bdce57e8685b35d84 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Mon, 7 Sep 2020 16:44:03 -0400 Subject: [PATCH 2/3] Static glide url builder shouldn't include subdirectories --- src/Providers/GlideServiceProvider.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Providers/GlideServiceProvider.php b/src/Providers/GlideServiceProvider.php index 12ada28771..14618aeeb0 100644 --- a/src/Providers/GlideServiceProvider.php +++ b/src/Providers/GlideServiceProvider.php @@ -14,6 +14,7 @@ use Statamic\Imaging\ImageGenerator; use Statamic\Imaging\PresetGenerator; use Statamic\Imaging\StaticUrlBuilder; +use Statamic\Support\Str; class GlideServiceProvider extends ServiceProvider { @@ -49,7 +50,7 @@ private function getBuilder() if (Config::get('statamic.assets.image_manipulation.cache')) { return new StaticUrlBuilder($this->app->make(ImageGenerator::class), [ - 'route' => URL::prependSiteUrl($route), + 'route' => Str::start($route, '/'), ]); } From 1ae09267cecd8241ce8e7a3b65a883f0b61e74cd Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Mon, 7 Sep 2020 16:59:12 -0400 Subject: [PATCH 3/3] tidy --- routes/web.php | 2 +- src/Providers/GlideServiceProvider.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/routes/web.php b/routes/web.php index a253a5a8ad..71569e6987 100755 --- a/routes/web.php +++ b/routes/web.php @@ -11,7 +11,7 @@ * Glide * On-the-fly URL-based image transforms. */ - if (!config('statamic.assets.image_manipulation.cache')) { + if (! config('statamic.assets.image_manipulation.cache')) { Site::all()->map(function ($site) { return URL::makeRelative($site->url()); })->unique()->each(function ($sitePrefix) { diff --git a/src/Providers/GlideServiceProvider.php b/src/Providers/GlideServiceProvider.php index 14618aeeb0..66b69bc567 100644 --- a/src/Providers/GlideServiceProvider.php +++ b/src/Providers/GlideServiceProvider.php @@ -8,7 +8,6 @@ use Statamic\Contracts\Imaging\ImageManipulator; use Statamic\Contracts\Imaging\UrlBuilder; use Statamic\Facades\Config; -use Statamic\Facades\URL; use Statamic\Imaging\GlideImageManipulator; use Statamic\Imaging\GlideUrlBuilder; use Statamic\Imaging\ImageGenerator;