When i noticed images with a new image style where not loaded in, i started to debug the code in "StageFileProxySubscriber.php" There i noticed, when using both hotlink and use_imagecache_root, use_imagecache_root set path is not used, but instead the relative path is still being used.

        if ($config->get('use_imagecache_root') && $unconverted_path === $relative_path) {
          // Config says: Fetch the original.
          $fetch_path = StreamWrapperManager::getTarget($original_path);
        }
     
      ...

      if ($config->get('hotlink')) {
        $relative_path = UrlHelper::encodePath($relative_path);
        $location = Url::fromUri("$server/$remote_file_dir/$relative_path", [
          'query' => $query_parameters,
          'absolute' => TRUE,
        ])->toString();

Proposed solution to remove $fetch_path variable and use $relative_path instead.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

marcellinostroosnijder’s picture

Status: Active » Needs review

Added an MR that removed the variable, let me know if there's any feedback!

marcellinostroosnijder’s picture

Assigned: marcellinostroosnijder » Unassigned
smustgrave’s picture

Once someone who's hitting this problem tests it I can merge.

smustgrave’s picture

Status: Needs review » Needs work

Know this module has been a little lax on tests but possible to get a simple kernel test around this?

lisotton’s picture

I think the solution is not the proper one, as it always deliver the original image, even requesting the URL of an image style.

I think the proper solution is to download the original image and then let Drupal generate the image style locally.

lisotton’s picture

@marcellinostroosnijder I changed your PR to skip the hotlink if the image style is requested, both hotlink and use_imagecache_root is enabled.

Like this we will download the original image and Drupal will be able to generate the image style locally.

lisotton’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

smustgrave’s picture

Version: 3.1.x-dev » 4.0.x-dev
Status: Needs work » Fixed
Issue tags: -Needs tests

Added a test and will include in alpha release for 4.0.x

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.