Beispiel #1
0
    def apply_cdn_to_url(self, image_url):
        """
        Applies a new CDN/base URL to the given URLs if CDN configuration is
        enabled.

        If CDN does not exist or is disabled, just returns the original. The
        URL that we store in CourseOverviewImageSet is already top level path,
        so we don't need to go through the /static remapping magic that happens
        with other course assets. We just need to add the CDN server if appropriate.
        """
        cdn_config = AssetBaseUrlConfig.current()
        if not cdn_config.enabled:
            return image_url

        return self._apply_cdn_to_url(image_url, cdn_config.base_url)
Beispiel #2
0
    def apply_cdn_to_urls(self, image_urls):
        """
        Given a dict of resolutions -> urls, return a copy with CDN applied.

        If CDN does not exist or is disabled, just returns the original. The
        URLs that we store in CourseOverviewImageSet are all already top level
        paths, so we don't need to go through the /static remapping magic that
        happens with other course assets. We just need to add the CDN server if
        appropriate.
        """
        cdn_config = AssetBaseUrlConfig.current()
        if not cdn_config.enabled:
            return image_urls

        base_url = cdn_config.base_url

        return {
            resolution: self._apply_cdn_to_url(url, base_url)
            for resolution, url in image_urls.items()
        }