add ability to print a file with the API!!!

This commit is contained in:
sigil-03 2024-03-24 19:18:22 -06:00
parent 7ec553ca18
commit f70e145b8a

View file

@ -122,9 +122,10 @@ impl Prusa {
fn try_load_file(&self, filepath: &str) -> Result<Uuid, Error> {
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(())
}