added optional attachment header to response of LargeResponseHandler, changed gcode and timelapse download to use direct URLs
This commit is contained in:
parent
e5f43835f4
commit
c9f97ef50d
2 changed files with 12 additions and 4 deletions
|
|
@ -505,7 +505,7 @@ def getTimelapseData():
|
|||
|
||||
files = octoprint.timelapse.getFinishedTimelapses()
|
||||
for file in files:
|
||||
file["url"] = url_for("downloadTimelapse", filename=file["name"])
|
||||
file["url"] = "/downloads/timelapse/" + file["name"]
|
||||
|
||||
return jsonify({
|
||||
"type": type,
|
||||
|
|
@ -945,6 +945,10 @@ class LargeResponseHandler(StaticFileHandler):
|
|||
|
||||
CHUNK_SIZE = 16 * 1024
|
||||
|
||||
def initialize(self, path, default_filename=None, as_attachment=False):
|
||||
StaticFileHandler.initialize(self, path, default_filename)
|
||||
self._as_attachment = as_attachment
|
||||
|
||||
def get(self, path, include_body=True):
|
||||
path = self.parse_url_path(path)
|
||||
abspath = os.path.abspath(os.path.join(self.root, path))
|
||||
|
|
@ -1005,6 +1009,10 @@ class LargeResponseHandler(StaticFileHandler):
|
|||
self.write(data)
|
||||
self.flush()
|
||||
|
||||
def set_extra_headers(self, path):
|
||||
if self._as_attachment:
|
||||
self.set_header("Content-Disposition", "attachment")
|
||||
|
||||
#~~ startup code
|
||||
class Server():
|
||||
def __init__(self, configfile=None, basedir=None, host="0.0.0.0", port=5000, debug=False, allowRoot=False):
|
||||
|
|
@ -1080,8 +1088,8 @@ class Server():
|
|||
self._router = SockJSRouter(self._createSocketConnection, "/sockjs")
|
||||
|
||||
self._tornado_app = Application(self._router.urls + [
|
||||
(r"/downloads/timelapse/([^/]*\.mpg)", LargeResponseHandler, {"path": settings().getBaseFolder("timelapse")}),
|
||||
(r"/downloads/gcode/([^/]*\.(gco|gcode))", LargeResponseHandler, {"path": settings().getBaseFolder("uploads")}),
|
||||
(r"/downloads/timelapse/([^/]*\.mpg)", LargeResponseHandler, {"path": settings().getBaseFolder("timelapse"), "as_attachment": True}),
|
||||
(r"/downloads/gcode/([^/]*\.(gco|gcode))", LargeResponseHandler, {"path": settings().getBaseFolder("uploads"), "as_attachment": True}),
|
||||
(r".*", FallbackHandler, {"fallback": WSGIContainer(app)})
|
||||
])
|
||||
self._server = HTTPServer(self._tornado_app)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ function GcodeViewModel(loginStateViewModel) {
|
|||
if (self.status == 'idle' && self.errorCount < 3) {
|
||||
self.status = 'request';
|
||||
$.ajax({
|
||||
url: AJAX_BASEURL + "gcodefiles/" + filename,
|
||||
url: "/downloads/gcode/" + filename,
|
||||
data: { "mtime": mtime },
|
||||
type: "GET",
|
||||
success: function(response, rstatus) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue