Fixed a bug where static files would use the last read filetype as mimetype

We need a prettier way of making namespaces
This commit is contained in:
2017-11-11 13:00:43 +01:00
parent b0e857e21b
commit 902ae45ab3
2 changed files with 18 additions and 13 deletions
+3
View File
@@ -38,6 +38,9 @@ def listify_output(func):#decorator
return list(func(*args, **kwargs))
return new_func
def call(func):#decorator
return func()
class Model:
def __setattr__(self, name, value):
if not hasattr(self, name):
+15 -13
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
import sys, os, airspeed, glob
from sanic import Sanic, response
from common import withTemplate, withResource
from common import withTemplate, withResource, call
import card
import svg
import config
@@ -142,18 +142,20 @@ async def svg_add(request, template={}):
return response.html(template["svg.vm"].merge(locals()))
#add static resources:
for i in glob.iglob(os.path.join(config.resourcedir, "**","*"), recursive=True):
filetype = i.split('.')[-1]
if filetype in ("html", "css", "js"):
i = os.path.relpath(i, config.resourcedir)
print("Adding static resource", repr(i))
if filetype == "js": filetype = "javascript"
@app.get(f"/{i}")
@withResource(i)
async def card_style(request, file={}):
file = tuple(file.values())[0]
return response.text(file, headers={"Content-Type": f"text/{filetype}"})
for j in glob.iglob(os.path.join(config.resourcedir, "**","*"), recursive=True):
@call
def temp():#namespace hack
filetype = j.split('.')[-1]
if filetype in ("html", "css", "js"):
i = os.path.relpath(j, config.resourcedir)
print("Adding static resource", repr(i))
if filetype == "js": filetype = "javascript"
@app.get(f"/{i}")
@withResource(i)
async def card_style(request, file={}):
file = tuple(file.values())[0]
return response.text(file, headers={"Content-Type": f"text/{filetype}"})
#add svgs:
@app.get(f"/svg/<name>.svg")