Skip to content

Commit

Permalink
Generate image styles when requested
Browse files Browse the repository at this point in the history
  • Loading branch information
hyrsky committed Oct 10, 2024
1 parent fdea36d commit ba190de
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/Flysystem/Azure.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\File\FileUrlGeneratorInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Url;
use Drupal\flysystem\Plugin\FlysystemPluginInterface;
use Drupal\flysystem\Plugin\FlysystemUrlTrait;
use Drupal\helfi_azure_fs\Flysystem\Adapter\AzureBlobStorageAdapter;
Expand Down Expand Up @@ -149,15 +150,19 @@ public function getExternalUrl($uri): string {
// We use 'responsive_image' module, so each image can generate up to
// four derivatives, each taking several seconds.
// @see https://helsinkisolutionoffice.atlassian.net/browse/UHF-8204
if (str_contains($uri, 'styles/') && !file_exists($uri)) {
if (str_contains($uri, '/styles/') && !file_exists($uri)) {
// Return a 'local' image style URL until the image is generated and
// copied to Azure blob storage. Each derivative is generated when the
// image style URL is called for the first time, allowing the generation
// to be decoupled from main request.
$localUri = str_replace('azure://', 'public://', $uri);

return $this->externalUrls[$uri] = UrlHelper::encodePath(
$this->fileUrlGenerator->generateString($localUri));
//
// Flysystem URLs are intercepted by
// Drupal\flysystem\PathProcessor\FlysystemPathProcessor.
// Image style URL end up to flysystem.image_style route instead.
return $this->externalUrls[$uri] = Url::fromRoute('flysystem.serve', [
'scheme' => 'azure',
'filepath' => $this->getTarget($uri),
])->toString();
}
$target = $this->getTarget($uri);

Expand Down

0 comments on commit ba190de

Please sign in to comment.