add upload action + wait for status code
This commit is contained in:
parent
4c485e76e4
commit
5a4a39ab75
52
src/main.rs
52
src/main.rs
@ -343,6 +343,27 @@ fn replace() -> BoxResult<()>{
|
|||||||
}
|
}
|
||||||
Ok(())
|
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<()>{
|
fn upload() -> BoxResult<()>{
|
||||||
//interactive prompt per upload:
|
//interactive prompt per upload:
|
||||||
for entry in std::fs::read_dir("maps/passed")? {
|
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]
|
//id: ["New" for blank because of my double enter key]
|
||||||
print!("Model name: {}\nCreator: {}\nDisplayName: {}\nAsset Id: ",modelname,creator,displayname);
|
print!("Model name: {}\nCreator: {}\nDisplayName: {}\nAsset Id: ",modelname,creator,displayname);
|
||||||
std::io::Write::flush(&mut std::io::stdout())?;
|
std::io::Write::flush(&mut std::io::stdout())?;
|
||||||
let asset_id;
|
let upload_action;
|
||||||
loop{
|
loop{
|
||||||
let mut asset_id_string = String::new();
|
let mut upload_action_string = String::new();
|
||||||
std::io::stdin().read_line(&mut asset_id_string)?;
|
std::io::stdin().read_line(&mut upload_action_string)?;
|
||||||
asset_id_string.pop();//drop newline
|
if let Ok(parsed_upload_action)=upload_action_string.parse::<UploadAction>(){
|
||||||
if let Ok(parsed_asset_id)=asset_id_string.parse::<u64>(){
|
upload_action=parsed_upload_action;
|
||||||
asset_id=parsed_asset_id;
|
|
||||||
break;
|
break;
|
||||||
}else{
|
}else{
|
||||||
print!("Asset Id: ");
|
print!("Asset Id: ");
|
||||||
std::io::Write::flush(&mut std::io::stdout())?;
|
std::io::Write::flush(&mut std::io::stdout())?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
match upload_action {
|
||||||
std::process::Command::new("../rbxcompiler-linux-amd64")
|
UploadAction::Upload(asset_id) => {
|
||||||
|
let status=std::process::Command::new("../rbxcompiler-linux-amd64")
|
||||||
.arg("--compile=false")
|
.arg("--compile=false")
|
||||||
.arg("--group=6980477")
|
.arg("--group=6980477")
|
||||||
.arg(format!("--asset={}",asset_id))
|
.arg(format!("--asset={}",asset_id))
|
||||||
.arg(format!("--input={}",file_thing.path().into_os_string().into_string().unwrap()))
|
.arg(format!("--input={}",file_thing.path().into_os_string().into_string().unwrap()))
|
||||||
.spawn()?;
|
.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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user