def js(): names = [ 'head.js', 'ut.js', 'notice.js', 'redo.js', 'stream.js', 'super_resolution.js', 'load_image.js', 'plus.js', 'detail.js', 'tag.js', 'thumbnail.js', 'fade.js', 'base.js', ] def gen(): for name in names: yield datetime.fromtimestamp(os.path.getmtime(os.path.join( current_app.root_path, current_app.template_folder, name ))) mtime = max(gen()) if has_timestamp() and not expired_request(mtime): return Response(status=304) content = '\n'.join(render_template(name) for name in names) resp = Response( content, mimetype='text/javascript', ) resp.content_md5 = calcmd5(content.encode('utf-8')) resp.last_modified = mtime if has_timestamp(): if cache_timeout() is not None: resp.cache_control.max_age = cache_timeout() resp.expires = int(time() + cache_timeout()) return resp
def style(): root = os.path.join(app.static_folder, 'scss') sources = scss_sources(root) def gen(): for filename, _ in sources: yield datetime.fromtimestamp(os.path.getmtime(os.path.join( root, filename ))) mtime = max(gen()) if has_timestamp() and not expired_request(mtime): return Response(status=304) c = scss.Scss( scss_vars={}, scss_opts={ 'compress': True, 'debug_info': True, 'load_paths': [root] } ) c._scss_files = OrderedDict(sources) content = c.compile() resp = Response( content, mimetype='text/css', ) resp.content_md5 = calcmd5(content.encode('utf-8')) resp.last_modified = mtime if has_timestamp(): if cache_timeout() is not None: resp.cache_control.max_age = cache_timeout() resp.expires = int(time() + cache_timeout()) return resp
def thumbnail(md5): try: if ( has_timestamp() and not expired_request(core.thumbnail_mtime_bi_md5(md5)) ): return Response(status=304) except: pass width = int(request.args['width']) content = core.thumbnail_bi_md5(md5, width) resp = Response(content, mimetype='image/' + img.kind(data=content)) resp.content_md5 = calcmd5(content) resp.last_modified = core.thumbnail_mtime_bi_md5(md5) if has_timestamp(): cache_timeout = core.thumbnail_cache_timeout_bi_md5(md5) if cache_timeout is not None: resp.cache_control.max_age = cache_timeout resp.expires = int(time() + cache_timeout) return resp