add ability to print a file with the API!!!
This commit is contained in:
parent
7ec553ca18
commit
f70e145b8a
1 changed files with 52 additions and 5 deletions
57
src/main.rs
57
src/main.rs
|
|
@ -122,9 +122,10 @@ impl Prusa {
|
||||||
fn try_load_file(&self, filepath: &str) -> Result<Uuid, Error> {
|
fn try_load_file(&self, filepath: &str) -> Result<Uuid, Error> {
|
||||||
let data = fs::read(filepath)?;
|
let data = fs::read(filepath)?;
|
||||||
|
|
||||||
|
let uuid = Uuid::new_v4();
|
||||||
// TODO: Allow storage selection
|
// TODO: Allow storage selection
|
||||||
// For now, assume that we're using only USB:
|
// 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))
|
let resp = self.client.put(format!("http://{}{api_target}", self.ip_addr))
|
||||||
.header("X-Api-Key", &self.api_key)
|
.header("X-Api-Key", &self.api_key)
|
||||||
.header("Content-Type", "application/octet-stream")
|
.header("Content-Type", "application/octet-stream")
|
||||||
|
|
@ -136,12 +137,58 @@ impl Prusa {
|
||||||
let text = resp.text()?;
|
let text = resp.text()?;
|
||||||
println!("{text}");
|
println!("{text}");
|
||||||
|
|
||||||
todo!("Implement UUID Handling");
|
// todo!("Implement UUID Handling");
|
||||||
// Ok(Uuid::new_v8())
|
Ok(uuid)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_print_file(&self, _id: &Uuid) -> Result<(), Error> {
|
// /api/v1/files/{storage}/{path}:
|
||||||
todo!("implement try_print_file")
|
//
|
||||||
|
// 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(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue