Exemplo n.º 1
0
def get_document(path):
    path = universe.root + "/content/" + path
    # print("[* get_document] Path: " + path)
    if os.path.exists(path):
        data = universe.fread(path)
        if data:
            meta = {
                "ip": return_ip().data.decode("utf-8"),
                "up": ".." if os.path.isdir(path) else "."
            }
            extension = path.split(".")[-1]
            res = make_response("", 200)
            if extension in ["txt"] or os.path.isdir(path):
                html = universe.parse(data.decode("utf-8"), path)
                meta.update({"content": html})
                res.headers["Content-Type"] = "text/html; charset=UTF-8"
                res.set_data(render_template("txt.html.jinja", data=meta))
            elif extension in ["md", "markdown"]:
                html = markdown.markdown(data.decode("utf-8"),
                                         extensions=['extra'])
                meta.update({"content": html})
                res.headers["Content-Type"] = "text/html; charset=UTF-8"
                res.set_data(render_template("txt.html.jinja", data=meta))
            elif extension in ["png", "jpg", "pdf", "mp3", "mp4"]:
                res.headers["Content-Type"] = "%s; charset=UTF-8" % guess_mime(
                    path)[0]
                res.set_data(data)
            elif extension in ["html", "htm"]:
                res.headers["Content-Type"] = "text/html; charset=UTF-8"
                res.set_data(data)
            else:
                res.headers["Content-Type"] = "text/plain; charset=UTF-8"
                res.set_data(data)
            return res
    abort(404)
Exemplo n.º 2
0
def get_resource(path):
    path = universe.root + "/res/" + path
    # print("[* get_resource] Path: " + path)
    if os.path.exists(path) and not os.path.isdir(path):
        data = universe.fread(path)
        if data:
            res = make_response(data, 200)
            res.headers["Content-Type"] = "%s; charset=UTF-8" % guess_mime(
                path)[0]
            return res
    abort(404)