diff --git a/data/interfaces/default/js/script.js b/data/interfaces/default/js/script.js index d0c023f4..46a73867 100644 --- a/data/interfaces/default/js/script.js +++ b/data/interfaces/default/js/script.js @@ -501,16 +501,19 @@ $('*').on('click', '.refresh_pms_image', function (e) { pms_proxy_url = /^url\((['"]?)(.*)\1\)$/.exec(pms_proxy_url); pms_proxy_url = pms_proxy_url ? pms_proxy_url[2] : ""; // If matched, retrieve url, otherwise "" - if (pms_proxy_url.indexOf('pms_image_proxy') == -1) { + if (pms_proxy_url.indexOf('pms_image_proxy') === -1) { console.log('PMS image proxy url not found.'); } else { - if (pms_proxy_url.indexOf('refresh=true') > -1) { - pms_proxy_url = pms_proxy_url.replace("&refresh=true", ""); - background_div.css('background-image', 'url(' + pms_proxy_url + ')'); - background_div.css('background-image', 'url(' + pms_proxy_url + '&refresh=true)'); - } else { - background_div.css('background-image', 'url(' + pms_proxy_url + '&refresh=true)'); - } + background_div.css('background-image', 'none') + $.ajax({ + url: pms_proxy_url, + headers: { + 'Cache-Control': 'no-cache' + }, + success: function () { + background_div.css('background-image', 'url(' + pms_proxy_url + ')'); + } + }); } }); diff --git a/plexpy/pmsconnect.py b/plexpy/pmsconnect.py index 983a3eef..18e51fe7 100644 --- a/plexpy/pmsconnect.py +++ b/plexpy/pmsconnect.py @@ -2831,8 +2831,9 @@ class PmsConnect(object): if img: web_img = img.startswith('http') + resource_img = img.startswith('/:/resources') - if refresh and not web_img: + if refresh and not web_img and not resource_img: img = '{}/{}'.format(img.rstrip('/'), helpers.timestamp()) if web_img: diff --git a/plexpy/webserve.py b/plexpy/webserve.py index 484cd849..39a7b949 100644 --- a/plexpy/webserve.py +++ b/plexpy/webserve.py @@ -4611,7 +4611,7 @@ class WebInterface(object): """ See real_pms_image_proxy docs string""" refresh = False - if kwargs.get('refresh'): + if kwargs.get('refresh') or 'no-cache' in cherrypy.request.headers.get('Cache-Control', ''): refresh = False if get_session_user_id() else True kwargs['refresh'] = refresh @@ -4645,6 +4645,8 @@ class WebInterface(object): None ``` """ + cherrypy.response.headers['Cache-Control'] = 'max-age=2592000' # 30 days + if isinstance(img, str) and img.startswith('interfaces/default/images'): fp = os.path.join(plexpy.PROG_DIR, 'data', img) return serve_file(path=fp, content_type='image/png') @@ -4727,6 +4729,7 @@ class WebInterface(object): except Exception as e: logger.warn("Failed to get image %s, falling back to %s." % (img, fallback)) + cherrypy.response.headers['Cache-Control'] = "max-age=0,no-cache,no-store" if fallback in common.DEFAULT_IMAGES: fbi = common.DEFAULT_IMAGES[fallback] fp = os.path.join(plexpy.PROG_DIR, 'data', fbi) diff --git a/plexpy/webstart.py b/plexpy/webstart.py index 1818d4f8..ac233526 100644 --- a/plexpy/webstart.py +++ b/plexpy/webstart.py @@ -225,20 +225,19 @@ def initialize(options): 'tools.sessions.on': False, 'tools.auth.on': False }, - #'/pms_image_proxy': { - # 'tools.staticdir.on': True, - # 'tools.staticdir.dir': os.path.join(plexpy.CONFIG.CACHE_DIR, 'images'), - # 'tools.caching.on': True, - # 'tools.caching.force': True, - # 'tools.caching.delay': 0, - # 'tools.expires.on': True, - # 'tools.expires.secs': 60 * 60 * 24 * 30, # 30 days - # 'tools.auth.on': False, - # 'tools.sessions.on': False - #}, + '/pms_image_proxy': { + 'tools.caching.on': True, + 'tools.caching.force': True, + 'tools.caching.delay': 0, + 'tools.expires.on': True, + 'tools.expires.secs': 60 * 60 * 24 * 30, # 30 days + 'tools.auth.on': False, + 'tools.sessions.on': False + }, '/favicon.ico': { 'tools.staticfile.on': True, - 'tools.staticfile.filename': os.path.abspath(os.path.join(plexpy.PROG_DIR, 'data/interfaces/default/images/favicon/favicon.ico')), + 'tools.staticfile.filename': os.path.abspath(os.path.join( + plexpy.PROG_DIR, 'data/interfaces/default/images/favicon/favicon.ico')), 'tools.caching.on': True, 'tools.caching.force': True, 'tools.caching.delay': 0,