diff --git a/files/helpers/assetcache.py b/files/helpers/assetcache.py index fa85ba8aa..a623a3947 100644 --- a/files/helpers/assetcache.py +++ b/files/helpers/assetcache.py @@ -3,6 +3,7 @@ import zlib from collections import defaultdict ASSET_DIR = 'files/assets' +ASSET_URL = '/assets/' ASSET_CACHE = defaultdict(lambda: None) def assetcache_build(asset_dir): @@ -14,7 +15,16 @@ def assetcache_build(asset_dir): fhash = zlib.crc32(f.read()) ASSET_CACHE[relpath] = '%x' % fhash -def assetcache_get(path): - return ASSET_CACHE[path] +def assetcache_hash(asset_path): + return ASSET_CACHE[asset_path] + +def assetcache_path(asset_path): + cachehash = assetcache_hash(asset_path) + + url = ASSET_URL + asset_path + if cachehash: + url += '?v=' + cachehash + + return url assetcache_build(ASSET_DIR) diff --git a/files/helpers/jinja2.py b/files/helpers/jinja2.py index 0d9df2a58..092a5f256 100644 --- a/files/helpers/jinja2.py +++ b/files/helpers/jinja2.py @@ -3,7 +3,7 @@ from .get import * from os import listdir, environ from .const import * import time -from files.helpers.assetcache import assetcache_get +from files.helpers.assetcache import assetcache_path @app.template_filter("post_embed") def post_embed(id, v): @@ -49,13 +49,7 @@ def timestamp(timestamp): @app.template_filter("asset") def template_asset(asset_path): - outpath = '/assets/' + asset_path - - cachehash = assetcache_get(asset_path) - if cachehash: - outpath += '?v=' + cachehash - - return outpath + return assetcache_path(asset_path) @app.context_processor def inject_constants():