/api/files: add unselect command
Adding the `unselect` right next to where the `select` is implemented.
There are two ways of unselecting, 1) using the selected filename,
2) using special word `current`
POST /api/files/local/whistle_v2.gcode
POST /api/files/local/current
This commit is contained in:
1 parent
9616508bb5
commit
8c4020eac1
3 files changed
+31
No files matched your search
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in new issue
Block a user