Merge pull request #4111 from eltonlaw/gh-3505/add-unselect-to-files-api

/api/files: add unselect file command
This commit is contained in:
Gina Häußge authored and GitHub committed 2021-04-28 16:43:43 +02:00
commit 73776c04f4
3 files changed
+31

No files matched your search

+1
View File
@@ -142,6 +142,7 @@ date of first contribution):
* [Scott Lahteine](https://github.com/thinkyhead)
* [Karthikeyan Singaravelan](https://github.com/tirkarthi)
* [Yvan Rodrigues](https://github.com/TwoRedCells)
* [Elton Law](https://github.com/eltonlaw)
OctoPrint started off as a fork of [Cura](https://github.com/daid/Cura) by
[Daid Braam](https://github.com/daid). Parts of its communication layer and
+9
View File
@@ -585,6 +585,15 @@ Issue a file command
Requires the ``FILES_SELECT`` permission.
unselect
Unselects the currently selected file for printing.
Upon success, a status code of :http:statuscode:`204` and an empty body is returned. If no file is selected
or there already is an active print job, a :http:statuscode:`409` is returned. If path isn't ``current```
or the filename of the current selection, a :http:statuscode:`400` is returned
Requires the ``FILES_SELECT`` permission.
slice
Slices an STL file into GCODE. Note that this is an asynchronous operation that will take place in the background
after the response has been sent back to the client. Additional parameters are:
+21
View File
@@ -794,6 +794,7 @@ def gcodeFileCommand(filename, target):
# valid file commands, dict mapping command name to mandatory parameters
valid_commands = {
"select": [],
"unselect": [],
"slice": [],
"analyse": [],
"copy": ["destination"],
@@ -842,6 +843,26 @@ def gcodeFileCommand(filename, target):
filenameToSelect = fileManager.path_on_disk(target, filename)
printer.select_file(filenameToSelect, sd, printAfterLoading, user)
elif command == "unselect":
with Permissions.FILES_SELECT.require(403):
if not printer.is_ready():
return make_response(
"Printer is already printing, cannot unselect current file", 409
)
_, currentFilename = _getCurrentFile()
if currentFilename is None:
return make_response(
"Cannot unselect current file when there is no file selected", 409
)
if filename != currentFilename and filename != "current":
return make_response(
"Only the currently selected file can be unselected", 400
)
printer.unselect_file()
elif command == "slice":
with Permissions.SLICE.require(403):
if not _verifyFileExists(target, filename):