first successful file push to prusa
This commit is contained in:
parent
4e09e5e4ab
commit
7ec553ca18
1 changed files with 44 additions and 4 deletions
48
src/main.rs
48
src/main.rs
|
|
@ -66,7 +66,7 @@ impl Prusa {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO return this into a specific type
|
// TODO return this into a specific type
|
||||||
fn get_storage_info(&self) -> Result<(StorageInfo), Error> {
|
fn get_storage_info(&self) -> Result<StorageInfo, Error> {
|
||||||
let api_target = "/api/v1/storage";
|
let api_target = "/api/v1/storage";
|
||||||
let resp = self.client.get(format!("http://{}{api_target}", self.ip_addr))
|
let resp = self.client.get(format!("http://{}{api_target}", self.ip_addr))
|
||||||
.header("X-Api-Key", &self.api_key)
|
.header("X-Api-Key", &self.api_key)
|
||||||
|
|
@ -85,18 +85,59 @@ impl Prusa {
|
||||||
// type: string
|
// type: string
|
||||||
// format: binary
|
// format: binary
|
||||||
|
|
||||||
|
|
||||||
|
// Need parameters
|
||||||
|
/*
|
||||||
|
parameters:
|
||||||
|
- in: header
|
||||||
|
name: Content-Length
|
||||||
|
description: Length of file to upload
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
example: 101342
|
||||||
|
- in: header
|
||||||
|
name: Content-Type
|
||||||
|
description: Type of uploaded media
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
default: application/octet-stream
|
||||||
|
- in: header
|
||||||
|
name: Print-After-Upload
|
||||||
|
description: Whether to start printing the file after upload
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
description: ?0=False, ?1=True, according RFC8941/3.3.6
|
||||||
|
enum: [ "?0", "?1" ]
|
||||||
|
default: "?0"
|
||||||
|
- in: header
|
||||||
|
name: Overwrite
|
||||||
|
description: Whether to overwrite already existing files
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
description: ?0=False, ?1=True, according RFC8941/3.3.6
|
||||||
|
enum: ["?0", "?1"]
|
||||||
|
default: "?0"
|
||||||
|
*/
|
||||||
|
|
||||||
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)?;
|
||||||
|
|
||||||
// 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/{path}";
|
let api_target = "/api/v1/files/usb/test.gcode";
|
||||||
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-Length", data.len())
|
||||||
|
.header("Print-After-Upload", "0")
|
||||||
|
.header("Overwrite", "0")
|
||||||
|
.body(data)
|
||||||
.send()?;
|
.send()?;
|
||||||
let text = resp.text()?;
|
let text = resp.text()?;
|
||||||
println!("{text}");
|
println!("{text}");
|
||||||
todo!("implement try_load_file")
|
|
||||||
|
todo!("Implement UUID Handling");
|
||||||
|
// Ok(Uuid::new_v8())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_print_file(&self, _id: &Uuid) -> Result<(), Error> {
|
fn try_print_file(&self, _id: &Uuid) -> Result<(), Error> {
|
||||||
|
|
@ -141,7 +182,6 @@ struct Cli {
|
||||||
enum Command {
|
enum Command {
|
||||||
Info,
|
Info,
|
||||||
Load {
|
Load {
|
||||||
#[arg(short, long)]
|
|
||||||
filepath: String,
|
filepath: String,
|
||||||
},
|
},
|
||||||
Print {
|
Print {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue