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

Improve multisite Glide support #2379

Closed
wants to merge 3 commits into from
Closed
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
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