diff --git a/.gitignore b/.gitignore index 678f1e98a..980665405 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .DS_Store .php-cs-fixer.cache +/assets/* /backup/* /cache/* /logs/* diff --git a/formwork/config/routes/routes.php b/formwork/config/routes/routes.php index 13530dbd5..d85454824 100644 --- a/formwork/config/routes/routes.php +++ b/formwork/config/routes/routes.php @@ -24,7 +24,11 @@ 'action' => 'Formwork\Controllers\PageController@load', ], 'assets' => [ - 'path' => '/assets/{id}/{name}/', + /** @todo require the type param in Formwork >= 3.0.0 */ + 'path' => '/assets/{type}?/{id}/{name}/', + 'where' => [ + 'type' => ['images', null], + ], 'action' => 'Formwork\Controllers\AssetsController@asset', ], 'assets.template' => [ diff --git a/formwork/config/system.yaml b/formwork/config/system.yaml index 67eaad7fd..76c0124e1 100644 --- a/formwork/config/system.yaml +++ b/formwork/config/system.yaml @@ -67,7 +67,7 @@ images: webpQuality: 85 avifQuality: 70 gifColors: 256 - processPath: ${%ROOT_PATH%}/cache/images + processPath: ${%ROOT_PATH%}/assets/images preserveColorProfile: true preserveExifData: true clearCacheByDefault: false diff --git a/formwork/src/Controllers/AssetsController.php b/formwork/src/Controllers/AssetsController.php index 94379e1c1..9fea8e21b 100644 --- a/formwork/src/Controllers/AssetsController.php +++ b/formwork/src/Controllers/AssetsController.php @@ -4,6 +4,7 @@ use Formwork\Http\FileResponse; use Formwork\Http\Response; +use Formwork\Http\ResponseStatus; use Formwork\Router\RouteParams; use Formwork\Utils\FileSystem; use Formwork\Utils\Path; @@ -15,6 +16,11 @@ final class AssetsController extends AbstractController */ public function asset(RouteParams $routeParams): Response { + if (!$routeParams->has('type')) { + trigger_error('The "assets" route without a "type" parameter is deprecated and will be removed in a future version', E_USER_DEPRECATED); + return $this->redirect($this->router->rewrite(['type' => 'images']), ResponseStatus::MovedPermanently); + } + $path = FileSystem::joinPaths($this->config->get('system.images.processPath'), $routeParams->get('id'), $routeParams->get('name')); if (FileSystem::isFile($path, assertExists: false)) { diff --git a/formwork/src/Files/FileUriGenerator.php b/formwork/src/Files/FileUriGenerator.php index a556d5606..8d265e6e3 100644 --- a/formwork/src/Files/FileUriGenerator.php +++ b/formwork/src/Files/FileUriGenerator.php @@ -38,7 +38,7 @@ public function generate(File $file): string if (Str::startsWith($path, FileSystem::normalizePath($this->config->get('system.images.processPath')))) { $id = basename(dirname($path)); $name = basename($path); - $uriPath = $this->router->generate('assets', compact('id', 'name')); + $uriPath = $this->router->generate('assets', ['type' => 'images', 'id' => $id, 'name' => $name]); return $this->site->uri($uriPath, includeLanguage: false); }