diff --git a/docs/api/connection.rst b/docs/api/connection.rst index 1caefe99..aab57fc4 100644 --- a/docs/api/connection.rst +++ b/docs/api/connection.rst @@ -16,17 +16,14 @@ Get connection settings Retrieve the current connection settings, including information regarding the available baudrates and serial ports and the current connection state. - **Example Request** + **Example** .. sourcecode:: http GET /api/connection HTTP/1.1 Host: example.com - Content-Type: application/json X-Api-Key: abcdef... - **Example Response** - .. sourcecode:: http HTTP/1.1 200 OK @@ -90,6 +87,10 @@ Issue a connection command "autoconnect": true } + .. sourcecode:: http + + HTTP/1.1 204 No Content + **Example Disconnect Request** .. sourcecode:: http @@ -103,6 +104,10 @@ Issue a connection command "command": "disconnect" } + .. sourcecode:: http + + HTTP/1.1 204 No Content + :json string command: The command to issue, either ``connect`` or ``disconnect`` :json string port: ``connect`` command: The port to connect to. If left out either the existing ``portPreference`` will be used, or if that is not available OctoPrint will attempt auto detection. Must be part diff --git a/docs/api/fileops.rst b/docs/api/fileops.rst index e06cdec6..ce8ae277 100644 --- a/docs/api/fileops.rst +++ b/docs/api/fileops.rst @@ -18,14 +18,13 @@ Retrieve all files Returns a :ref:`Retrieve response `. - **Example request**: + **Example**: .. sourcecode:: http GET /api/files HTTP/1.1 Host: example.com - - **Example response**: + X-Api-Key: abcdef... .. sourcecode:: http @@ -84,14 +83,13 @@ Retrieve files from specific location Returns a :ref:`Retrieve response `. - **Example request**: + **Example**: .. sourcecode:: http GET /api/files/local HTTP/1.1 Host: example.com - - **Example response**: + X-Api-Key: abcdef... .. sourcecode:: http @@ -150,7 +148,7 @@ Upload file Returns a :http:statuscode:`201` response with a ``Location`` header set to the management URL of the uploaded file and an :ref:`Upload Response ` as the body upon successful completion. - **Example request** + **Example** .. sourcecode:: http @@ -186,13 +184,11 @@ Upload file true ------WebKitFormBoundaryDeC2E3iWbTv1PwMC-- - **Example response** - .. sourcecode:: http HTTP/1.1 200 OK Content-Type: application/json - Location: + Location: http://example.com/api/files/sdcard/whistle_.gcode { "files": { @@ -247,14 +243,13 @@ Retrieve a specific file's information On success, a :http:statuscode:`200` is returned, with a :ref:`file information item ` as the response body. - **Example Request** + **Example** .. sourcecode:: http GET /api/files/local/whistle_v2.gcode HTTP/1.1 Host: example.com - - **Example Response** + X-Api-Key: abcdef... .. sourcecode:: http @@ -325,6 +320,10 @@ Issue a file command "print": true } + .. sourcecode:: http + + HTTP/1.1 204 No Content + :param target: The target location on which to delete the file, either ``local`` (for OctoPrint's ``uploads`` folder) or ``sdcard`` for the printer's SD card (if available) :param filename: The filename of the file for which to issue the command diff --git a/docs/api/job.rst b/docs/api/job.rst index 4b34df65..04c48b86 100644 --- a/docs/api/job.rst +++ b/docs/api/job.rst @@ -46,6 +46,10 @@ Issue a job command "command": "start" } + .. sourcecode:: http + + HTTP/1.1 204 No Content + **Example Restart Request** .. sourcecode:: http @@ -59,6 +63,10 @@ Issue a job command "command": "restart" } + .. sourcecode:: http + + HTTP/1.1 204 No Content + **Example Pause Request** .. sourcecode:: http @@ -72,6 +80,10 @@ Issue a job command "command": "pause" } + .. sourcecode:: http + + HTTP/1.1 204 No Content + **Example Cancel Request** .. sourcecode:: http @@ -85,6 +97,10 @@ Issue a job command "command": "cancel" } + .. sourcecode:: http + + HTTP/1.1 204 No Content + :json string command: The command to issue, either ``start``, ``restart``, ``pause`` or ``cancel`` :statuscode 204: No error :statuscode 409: If the printer is not operational or the current print job state does not match the preconditions @@ -101,14 +117,13 @@ Retrieve information about the current job Returns a :http:statuscode:`200` with a :ref:`sec-api-job-datamodel-response` in the body. - **Example Request** + **Example** .. sourcecode:: http GET /api/job HTTP/1.1 Host: example.com - - **Example Response** + X-Api-Key: abcdef... .. sourcecode:: http diff --git a/docs/api/logs.rst b/docs/api/logs.rst index abdb9ceb..b2759aad 100644 --- a/docs/api/logs.rst +++ b/docs/api/logs.rst @@ -22,7 +22,7 @@ Retrieve a list of available log files Returns a :ref:`Logfile Retrieve response `. - **Example Request** + **Example** .. sourcecode:: http @@ -30,8 +30,6 @@ Retrieve a list of available log files Host: example.com X-Api-Key: abcdef... - **Example response**: - .. sourcecode:: http HTTP/1.1 200 OK diff --git a/docs/api/printer.rst b/docs/api/printer.rst index 7e7e6c56..66b61f06 100644 --- a/docs/api/printer.rst +++ b/docs/api/printer.rst @@ -65,6 +65,7 @@ Retrieve the current printer state GET /api/printer?history=true&limit=2 HTTP/1.1 Host: example.com + X-Api-Key: abcdef... .. sourcecode:: http @@ -146,6 +147,7 @@ Retrieve the current printer state GET /api/printer?exclude=temperature,sd HTTP/1.1 Host: example.com + X-Api-Key: abcdef... .. sourcecode:: http @@ -436,6 +438,7 @@ Retrieve the current tool state GET /api/printer/tool?history=true&limit=2 HTTP/1.1 Host: example.com + X-Api-Key: abcdef... .. sourcecode:: http @@ -585,6 +588,7 @@ Retrieve the current bed state GET /api/printer/bed?history=true&limit=2 HTTP/1.1 Host: example.com + X-Api-Key: abcdef... .. sourcecode:: http @@ -737,6 +741,7 @@ Retrieve the current SD state GET /api/printer/sd HTTP/1.1 Host: example.com + X-Api-Key: abcdef... .. sourcecode:: http diff --git a/src/octoprint/server/api/files.py b/src/octoprint/server/api/files.py index bba7b260..a46123a7 100644 --- a/src/octoprint/server/api/files.py +++ b/src/octoprint/server/api/files.py @@ -161,30 +161,33 @@ def uploadGcodeFile(target): eventManager.fire(Events.UPLOAD, {"file": filename, "target": target}) files = {} - if done: + location = url_for(".readGcodeFile", target=FileDestinations.LOCAL, filename=filename, _external=True) + files.update({ + FileDestinations.LOCAL: { + "name": filename, + "origin": FileDestinations.LOCAL, + "refs": { + "resource": location, + "download": url_for("index", _external=True) + "downloads/files/" + FileDestinations.LOCAL + "/" + filename + } + } + }) + + if sd and sdFilename: + location = url_for(".readGcodeFile", target=FileDestinations.SDCARD, filename=sdFilename, _external=True) files.update({ - FileDestinations.LOCAL: { - "name": filename, - "origin": FileDestinations.LOCAL, + FileDestinations.SDCARD: { + "name": sdFilename, + "origin": FileDestinations.SDCARD, "refs": { - "resource": url_for(".readGcodeFile", target=FileDestinations.LOCAL, filename=filename, _external=True), - "download": url_for("index", _external=True) + "downloads/files/" + FileDestinations.LOCAL + "/" + filename + "resource": location } } }) - if sd and sdFilename: - files.update({ - FileDestinations.SDCARD: { - "name": sdFilename, - "origin": FileDestinations.SDCARD, - "refs": { - "resource": url_for(".readGcodeFile", target=FileDestinations.SDCARD, filename=sdFilename, _external=True) - } - } - }) - - return make_response(jsonify(files=files, done=done), 201) + r = make_response(jsonify(files=files, done=done), 201) + r.headers["Location"] = location + return r @api.route("/files//", methods=["GET"])