Clarify static resource routes code
This commit is contained in:
@@ -155,18 +155,19 @@ async def svg_add(request, template={}):
|
|||||||
svgs = svg.list_all()
|
svgs = svg.list_all()
|
||||||
return response.html(template["svg.vm"].merge(locals()))
|
return response.html(template["svg.vm"].merge(locals()))
|
||||||
|
|
||||||
#add static resources:
|
#add static resources (with caching):
|
||||||
for j in glob.iglob(os.path.join(config.resourcedir, "**","*"), recursive=True):
|
for file in glob.iglob(os.path.join(config.resourcedir, "**","*"), recursive=True):
|
||||||
@call
|
@call
|
||||||
def temp():#namespace hack
|
def temp():#namespace hack to store filetype
|
||||||
filetype = j.split('.')[-1]
|
filetype = file.split('.')[-1]
|
||||||
if filetype in ("html", "css", "js"):
|
if filetype in ("html", "css", "js"):
|
||||||
i = os.path.relpath(j, config.resourcedir)
|
route = os.path.relpath(file, config.resourcedir)
|
||||||
print("Adding static resource", repr(i))
|
|
||||||
if filetype == "js": filetype = "javascript"
|
if filetype == "js": filetype = "javascript"
|
||||||
|
|
||||||
@app.get(f"/{i}")
|
print("Adding static resource", repr(route))
|
||||||
@withResource(i)
|
|
||||||
|
@app.get(f"/{route}")
|
||||||
|
@withResource(route)
|
||||||
async def card_style(request, file={}):
|
async def card_style(request, file={}):
|
||||||
file = tuple(file.values())[0]
|
file = tuple(file.values())[0]
|
||||||
return response.text(file, headers={"Content-Type": f"text/{filetype}"})
|
return response.text(file, headers={"Content-Type": f"text/{filetype}"})
|
||||||
@@ -176,6 +177,7 @@ for j in glob.iglob(os.path.join(config.resourcedir, "**","*"), recursive=True):
|
|||||||
async def get_svg(request, name):
|
async def get_svg(request, name):
|
||||||
color = request.args.get("color")
|
color = request.args.get("color")
|
||||||
return response.text(svg.get(name, color), headers={"Content-Type": "image/svg+xml"})
|
return response.text(svg.get(name, color), headers={"Content-Type": "image/svg+xml"})
|
||||||
|
|
||||||
@app.get(f"/svg/<collection>/<name>.svg")
|
@app.get(f"/svg/<collection>/<name>.svg")
|
||||||
async def get_svg(request, collection, name):
|
async def get_svg(request, collection, name):
|
||||||
color = request.args.get("color")
|
color = request.args.get("color")
|
||||||
|
|||||||
Reference in New Issue
Block a user