From f70e145b8ac1ebfb551b0cd5d670314e0224445f Mon Sep 17 00:00:00 2001 From: sigil-03 Date: Sun, 24 Mar 2024 19:18:22 -0600 Subject: [PATCH] add ability to print a file with the API!!! --- src/main.rs | 57 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8eea3c0..afdd0e7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -122,9 +122,10 @@ impl Prusa { fn try_load_file(&self, filepath: &str) -> Result { let data = fs::read(filepath)?; + let uuid = Uuid::new_v4(); // TODO: Allow storage selection // For now, assume that we're using only USB: - let api_target = "/api/v1/files/usb/test.gcode"; + let api_target = format!("/api/v1/files/usb/{uuid}.bgcode"); let resp = self.client.put(format!("http://{}{api_target}", self.ip_addr)) .header("X-Api-Key", &self.api_key) .header("Content-Type", "application/octet-stream") @@ -136,12 +137,58 @@ impl Prusa { let text = resp.text()?; println!("{text}"); - todo!("Implement UUID Handling"); - // Ok(Uuid::new_v8()) + // todo!("Implement UUID Handling"); + Ok(uuid) } - fn try_print_file(&self, _id: &Uuid) -> Result<(), Error> { - todo!("implement try_print_file") + // /api/v1/files/{storage}/{path}: + // + // post: + /* summary: Start print of file if there's no print job running + description: Body is ignored + requestBody: + required: false + content: {} + responses: + 204: + description: No Content + 401: + $ref: "#/components/responses/Unauthorized" + 404: + $ref: "#/components/responses/NotFound" + 409: + $ref: "#/components/responses/Conflict" + head: + summary: file presence and state check + responses: + 200: + description: OK + headers: + Read-Only: + description: Whether the file or storage is read-only + required: true + schema: + type: boolean + example: true + Currently-Printed: + description: Whether this file is currently being printed + required: true + schema: + type: boolean + example: true + */ + + fn try_print_file(&self, id: &Uuid) -> Result<(), Error> { + // /api/v1/files/{storage}/{path} + let api_target = format!("/api/v1/files/usb/{id}.bgcode"); + let resp = self.client.post(format!("http://{}{api_target}", self.ip_addr)) + .header("X-Api-Key", &self.api_key) + .header("Content-Type", "application/octet-stream") + .send()?; + let text = resp.text()?; + println!("{text}"); + + Ok(()) }