magento2 – Issue with Algolia Search

I started using algolia search.

Our root catalog magento is PUB. So path to images in our case is: website.com/media/catalog... but Algolia search generate url to image with pub so

website.com/pub/media/catalog

Image get 404

I found file: image.php

<?php

namespace AlgoliaAlgoliaSearchHelper;

use MagentoCatalogModelProductImageFactory;
use MagentoConfigurableProductModelProductTypeConfigurable as ProductTypeConfigurable;
use MagentoFrameworkAppHelperContext;
use MagentoFrameworkViewAssetRepository;
use MagentoFrameworkViewConfigInterface;

class Image extends MagentoCatalogHelperImage
{
    /**
     * @var ConfigHelper
     */
    protected $configHelper;
    private $logger;

    /**
     * Image constructor.
     *
     * @param Context $context
     * @param ImageFactory $productImageFactory
     * @param Repository $assetRepo
     * @param ConfigInterface $viewConfig
     * @param Logger $logger
     * @param ConfigHelper $configHelper
     */
    public function __construct(
        Context $context,
        ImageFactory $productImageFactory,
        Repository $assetRepo,
        ConfigInterface $viewConfig,
        Logger $logger,
        ConfigHelper $configHelper
    ) {
        parent::__construct($context, $productImageFactory, $assetRepo, $viewConfig);
        $this->logger = $logger;
        $this->configHelper = $configHelper;
    }

    public function getUrl()
    {
        try {
            $this->applyScheduledActions();

            $url = $this->_getModel()->getUrl();
        } catch (Exception $e) {
            $this->logger->log($e->getMessage());
            $this->logger->log($e->getTraceAsString());

            $url = $this->getDefaultPlaceholderUrl();
        }

        $url = $this->removeProtocol($url);
        $url = $this->removeDoubleSlashes($url);

        if ($this->configHelper->shouldRemovePubDirectory()) {
            $url = $this->removePubDirectory($url);
        }

        return $url;
    }

    protected function initBaseFile()
    {
        $model = $this->_getModel();
        $baseFile = $model->getBaseFile();
        if (!$baseFile) {
            if ($this->getImageFile()) {
                $model->setBaseFile($this->getImageFile());
            } else {
                $model->setBaseFile($this->getProductImage($model));
            }
        }

        return $this;
    }

    /**
     * Configurable::setImageFromChildProduct() only pulls 'image' type
     * and not the type set by the imageHelper
     *
     * @param MagentoCatalogModelProductImage $model
     *
     * @return mixed|string|null
     */
    private function getProductImage(MagentoCatalogModelProductImage $model)
    {
        $imageUrl = $this->getProduct()->getData($model->getDestinationSubdir());
        if (($imageUrl === null || $imageUrl == '') && $this->getProduct()->getTypeId() == ProductTypeConfigurable::TYPE_CODE) {
            $imageUrl = $this->getType() !== 'image' && $this->getConfigurableProductImage() ?
                $this->getConfigurableProductImage() : $this->getProduct()->getImage();
        }

        return $imageUrl;
    }

    private function getConfigurableProductImage()
    {
        $childProducts = $this->getProduct()->getTypeInstance()->getUsedProducts($this->getProduct());
        foreach ($childProducts as $childProduct) {
            $childImageUrl = $childProduct->getData($this->getType());
            if ($childImageUrl && $childImageUrl !== 'no_selection') {
                return $childImageUrl;
            }
        }

        return null;
    }

    public function removeProtocol($url)
    {
        return str_replace(('https://', 'http://'), '//', $url);
    }

    public function removeDoubleSlashes($url)
    {
        $url = str_replace('//', "https://magento.stackexchange.com/", $url);
        $url = "https://magento.stackexchange.com/" . $url;

        return $url;
    }

    public function removePubDirectory($url)
    {
        return str_replace('/pub/', "https://magento.stackexchange.com/", $url);
    }
}

At the bottom of this code are the references to the pub folder. How can I rewrite this code so that paths point to /media/catalog without pub?