add upload action + wait for status code

This commit is contained in:
Quaternions 2023-09-14 14:17:00 -07:00
parent 4c485e76e4
commit 5a4a39ab75

View File

@ -343,6 +343,27 @@ fn replace() -> BoxResult<()>{
}
Ok(())
}
enum UploadAction {
Upload(u64),
Skip,
}
struct ParseUploadActionErr;
impl std::str::FromStr for UploadAction {
type Err=ParseUploadActionErr;
fn from_str(s: &str) -> Result<Self, Self::Err>{
if s=="skip\n"{
Ok(Self::Skip)
}else{
if let Ok(asset_id)=s[..s.len()-1].parse::<u64>(){
Ok(Self::Upload(asset_id))
}else{
Err(ParseUploadActionErr)
}
}
}
}
fn upload() -> BoxResult<()>{
//interactive prompt per upload:
for entry in std::fs::read_dir("maps/passed")? {
@ -357,26 +378,39 @@ fn upload() -> BoxResult<()>{
//id: ["New" for blank because of my double enter key]
print!("Model name: {}\nCreator: {}\nDisplayName: {}\nAsset Id: ",modelname,creator,displayname);
std::io::Write::flush(&mut std::io::stdout())?;
let asset_id;
let upload_action;
loop{
let mut asset_id_string = String::new();
std::io::stdin().read_line(&mut asset_id_string)?;
asset_id_string.pop();//drop newline
if let Ok(parsed_asset_id)=asset_id_string.parse::<u64>(){
asset_id=parsed_asset_id;
let mut upload_action_string = String::new();
std::io::stdin().read_line(&mut upload_action_string)?;
if let Ok(parsed_upload_action)=upload_action_string.parse::<UploadAction>(){
upload_action=parsed_upload_action;
break;
}else{
print!("Asset Id: ");
std::io::Write::flush(&mut std::io::stdout())?;
}
}
std::process::Command::new("../rbxcompiler-linux-amd64")
.arg("--compile=false")
.arg("--group=6980477")
.arg(format!("--asset={}",asset_id))
.arg(format!("--input={}",file_thing.path().into_os_string().into_string().unwrap()))
.spawn()?;
match upload_action {
UploadAction::Upload(asset_id) => {
let status=std::process::Command::new("../rbxcompiler-linux-amd64")
.arg("--compile=false")
.arg("--group=6980477")
.arg(format!("--asset={}",asset_id))
.arg(format!("--input={}",file_thing.path().into_os_string().into_string().unwrap()))
.status()?;
match status.code() {
Some(0)=>{
//move file
let mut dest=std::path::PathBuf::from("maps/uploaded");
dest.push(file_thing.file_name());
std::fs::rename(file_thing.path(), dest)?;
}
Some(code)=>println!("upload failed! code={}",code),
None => println!("no status code!"),
}
}
UploadAction::Skip => continue,
}
}
Ok(())
}