Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/api/files: add unselect file command #4111

Merged

Conversation

eltonlaw
Copy link
Contributor

@eltonlaw eltonlaw commented Apr 25, 2021

What are the relevant tickets if any?

#3505

What does this PR do and why is it necessary?

Introduces an endpoint to unselect the selected file. The attached ticket mentions it being necessary "so that file queuing mechanisms, for example, might be written" and "to simply unselect the currently-selected file if you made a mistake"

How was it tested? How can it be tested by the reviewer?

Started the server and then ran the following. Seemed to work as expected

>>> import requests
>>> api_token = ...
>>> my_gcode_file = ...
>>> headers = {"Authorization": "Bearer " + api_token}
>>> base_url = "http://localhost:5000/api/files"

# happy path, select and unselect
>>> print(requests.post(f"{base_url}/local/{my_gcode_file}", json={"command": "select"}, headers=headers).content)
b''
>>> print(requests.post(f"{base_url}/local/{my_gcode_file}", json={"command": "unselect"}, headers=headers).content)
b''

# unselect with no file selected
>>> print(requests.post(f"{base_url}/local/{my_gcode_file}", json={"command": "unselect"}, headers=headers).content)
b'Cannot unselect current file when there is no file selected'

# have selected file and try to unselect invalid filename
>>> print(requests.post(f"{base_url}/local/{my_gcode_file}", json={"command": "select"}, headers=headers).content)
b''
>>> print(requests.post(f"{base_url}/local/foo", json={"command": "unselect"}, headers=headers).content)
b'Only the currently selected file can be unselected'

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
@github-actions github-actions bot added docs Related to documentation approved Issue has been approved by the bot or manually for further processing labels Apr 25, 2021
@foosel foosel added this to To review in PR triage Apr 28, 2021
PR triage automation moved this from To review to To merge Apr 28, 2021
Copy link
Member

@foosel foosel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could have sworn I HAD an unselect command already 😅 Thank you for fixing this oversight! 👍

@foosel foosel added this to the 1.7.0 milestone Apr 28, 2021
@foosel foosel merged commit 73776c0 into OctoPrint:maintenance Apr 28, 2021
PR triage automation moved this from To merge to Done Apr 28, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Issue has been approved by the bot or manually for further processing docs Related to documentation
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants