Return proper http status codes in case of problems
parent
c6e15a7d32
commit
e17fa031c8
|
@ -358,38 +358,35 @@ def refreshFiles():
|
||||||
|
|
||||||
#-- very simple api routines
|
#-- very simple api routines
|
||||||
@app.route(APIBASEURL + "load", methods=["POST"])
|
@app.route(APIBASEURL + "load", methods=["POST"])
|
||||||
@login_required
|
|
||||||
def apiLoad():
|
def apiLoad():
|
||||||
filename = None
|
logger = logging.getLogger(__name__)
|
||||||
s = settings()
|
|
||||||
if not s.get(["api", "allow"]):
|
if not settings().get(["api", "allow"]):
|
||||||
return jsonify(success=False, message="API calls not enabled")
|
abort(401)
|
||||||
|
|
||||||
if not "apikey" in request.values.keys():
|
if not "apikey" in request.values.keys():
|
||||||
return jsonify(success=False, message="apikey not present")
|
abort(401)
|
||||||
|
|
||||||
if request.values["apikey"] <> s.get(["api", "key"]):
|
if request.values["apikey"] != settings().get(["api", "key"]):
|
||||||
return jsonify(success=False, message="apikey incorrect" + s.get(["api","key"]) + " " + request.values["apikey"])
|
abort(403)
|
||||||
|
|
||||||
|
if not "file" in request.files.keys():
|
||||||
|
abort(400)
|
||||||
|
|
||||||
if "file" in request.files.keys():
|
|
||||||
# Perform an upload
|
# Perform an upload
|
||||||
file = request.files["file"]
|
file = request.files["file"]
|
||||||
filename = gcodeManager.addFile(file)
|
filename = gcodeManager.addFile(file)
|
||||||
if filename is None:
|
if filename is None:
|
||||||
return jsonify(success=False, message="failure loading gcode")
|
logger.warn("Upload via API failed")
|
||||||
else:
|
abort(500)
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
logger.info("loaded " + filename)
|
# Immediately perform a file select and possibly print too
|
||||||
# Immediately perform a loadGcode and possibly print too
|
printAfterSelect = False
|
||||||
printAfterLoading = False
|
|
||||||
if "print" in request.values.keys() and request.values["print"] in valid_boolean_trues:
|
if "print" in request.values.keys() and request.values["print"] in valid_boolean_trues:
|
||||||
printAfterLoading = True
|
printAfterSelect = True
|
||||||
filepath = gcodeManager.getAbsolutePath(filename)
|
filepath = gcodeManager.getAbsolutePath(filename)
|
||||||
if filepath is not None:
|
if filepath is not None:
|
||||||
printer.loadGcode(filepath, printAfterLoading)
|
printer.selectFile(filepath, False, printAfterSelect)
|
||||||
else:
|
|
||||||
return jsonify(success=False, message="gcode file not present")
|
|
||||||
|
|
||||||
return jsonify(SUCCESS)
|
return jsonify(SUCCESS)
|
||||||
|
|
||||||
#~~ timelapse handling
|
#~~ timelapse handling
|
||||||
|
|
Loading…
Reference in New Issue