Skip to content

Commit

Permalink
Improve multisite Glide support #2379
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvarga committed Sep 7, 2020
1 parent b1df359 commit 50dbd51
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
18 changes: 13 additions & 5 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,26 @@

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 () {
/**
* 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');
Expand Down
5 changes: 4 additions & 1 deletion src/Http/Controllers/GlideController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
}
Expand Down
4 changes: 2 additions & 2 deletions src/Providers/GlideServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
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;
use Statamic\Imaging\PresetGenerator;
use Statamic\Imaging\StaticUrlBuilder;
use Statamic\Support\Str;

class GlideServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -49,7 +49,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, '/'),
]);
}

Expand Down

0 comments on commit 50dbd51

Please sign in to comment.