mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-24 11:22:34 +00:00
mime-type guessing for /template/render/
This commit is contained in:
parent
276cf262ed
commit
adc9902252
2 changed files with 17 additions and 2 deletions
|
@ -392,8 +392,9 @@ route("/template/static/(.*)", template_static)
|
||||||
|
|
||||||
class template_render:
|
class template_render:
|
||||||
"render anything in /render/ dir"
|
"render anything in /render/ dir"
|
||||||
@deco.deluge_page
|
|
||||||
def GET(self, name):
|
def GET(self, name):
|
||||||
|
web.header("Content-type",utils.guess_mime_type(name))
|
||||||
#security : assumes config.get('template') returns a safe subdir.
|
#security : assumes config.get('template') returns a safe subdir.
|
||||||
basepath = os.path.normpath(os.path.join(os.path.dirname(__file__),
|
basepath = os.path.normpath(os.path.join(os.path.dirname(__file__),
|
||||||
'templates/%s/render' % config.get('template')))
|
'templates/%s/render' % config.get('template')))
|
||||||
|
@ -402,7 +403,7 @@ class template_render:
|
||||||
#hack detected?
|
#hack detected?
|
||||||
raise Exception("File to render is not located in %s" % basepath)
|
raise Exception("File to render is not located in %s" % basepath)
|
||||||
|
|
||||||
return web.template.Template(open(filename).read(), filename=filename)()
|
print web.template.Template(open(filename).read(), filename=filename)()
|
||||||
route("/template/render/(.*)", template_render)
|
route("/template/render/(.*)", template_render)
|
||||||
|
|
||||||
class template_style:
|
class template_style:
|
||||||
|
|
|
@ -297,3 +297,17 @@ class WebUiError(Exception):
|
||||||
class UnknownTorrentError(WebUiError):
|
class UnknownTorrentError(WebUiError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
#mime-type guessing :
|
||||||
|
def guess_mime_type(path):
|
||||||
|
import posixpath
|
||||||
|
from mimetypes import types_map as extensions_map
|
||||||
|
base, ext = posixpath.splitext(path)
|
||||||
|
if ext in extensions_map:
|
||||||
|
return extensions_map[ext]
|
||||||
|
ext = ext.lower()
|
||||||
|
if ext in extensions_map:
|
||||||
|
return extensions_map[ext]
|
||||||
|
else:
|
||||||
|
return 'application/octet-stream'
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue