From 242e552f4dab1e315f43f0f750ab8f4bf1fb1f4c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?=
Date: Mon, 9 Sep 2013 20:57:09 +0200
Subject: [PATCH] Bugfix: Do not allow STL file upload if Cura support is not
enabled
---
octoprint/gcodefiles.py | 25 +++++++++++++------------
octoprint/server.py | 2 +-
octoprint/static/js/app/main.js | 2 +-
3 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/octoprint/gcodefiles.py b/octoprint/gcodefiles.py
index e34ae0a5..472a6ba1 100644
--- a/octoprint/gcodefiles.py
+++ b/octoprint/gcodefiles.py
@@ -129,23 +129,24 @@ class GcodeManager:
if not file or not destination:
return None, True
- local = True if destination == FileDestinations.LOCAL else False
+ curaEnabled = self._settings.getBoolean(["cura", "enabled"])
+ filename = file.filename
- absolutePath = self.getAbsolutePath(file.filename, mustExist=False)
+ absolutePath = self.getAbsolutePath(filename, mustExist=False)
+ gcode = isGcodeFileName(filename)
- if absolutePath is None:
+ if absolutePath is None or (not curaEnabled and not gcode):
return None, True
file.save(absolutePath)
- filename = file.filename
- if isGcodeFileName(filename):
+ if gcode:
return self.processGcode(absolutePath), True
-
- curaEnabled = self._settings.get(["cura", "enabled"])
- if curaEnabled and isSTLFileName(filename) and local:
- self.processStl(absolutePath)
- return filename, False
+ else:
+ local = (destination == FileDestinations.LOCAL)
+ if curaEnabled and isSTLFileName(filename) and local:
+ self.processStl(absolutePath)
+ return filename, False
def getFutureFileName(self, file):
@@ -214,7 +215,7 @@ class GcodeManager:
if absolutePath is None:
return
-
+
os.remove(absolutePath)
if os.path.exists(stlPath):
os.remove(stlPath)
@@ -455,7 +456,7 @@ class MetadataAnalyzer:
def _analyzeGcode(self, filename):
path = self._getPathCallback(filename)
- if path is None:
+ if path is None or not os.path.exists(path):
return
self._currentFile = filename
diff --git a/octoprint/server.py b/octoprint/server.py
index 539696a6..82d34cf0 100644
--- a/octoprint/server.py
+++ b/octoprint/server.py
@@ -406,7 +406,7 @@ def uploadGcodeFile():
currentSd = currentJob["sd"]
futureFilename = gcodeManager.getFutureFilename(file)
- if futureFilename is None:
+ if futureFilename is None or (not settings().getBoolean(["cura", "enabled"]) and not util.isGcodeFileName(futureFilename)):
return make_response("Can not upload file %s, wrong format?" % file.filename, 400)
if futureFilename == currentFilename and sd == currentSd and printer.isPrinting() or printer.isPaused():
diff --git a/octoprint/static/js/app/main.js b/octoprint/static/js/app/main.js
index 40aecf1e..afa168c7 100644
--- a/octoprint/static/js/app/main.js
+++ b/octoprint/static/js/app/main.js
@@ -65,7 +65,7 @@ $(function() {
function gcode_upload_fail(e, data) {
$.pnotify({
title: "Upload failed",
- text: "Could not upload the file. Make sure it is a GCODE file and has one of the following extensions: .gcode, .gco
Server reported:
" + data.jqXHR.responseText + "
",
+ text: "Could not upload the file. Make sure that it is a GCODE file and has the extension \".gcode\" or \".gco\" or that it is an STL file with the extension \".stl\" and Cura support is enabled and configured.
Server reported:
" + data.jqXHR.responseText + "
",
type: "error",
hide: false
});