interpret result
This commit is contained in:
parent
86b892e614
commit
a22cf15697
42
src/main.rs
42
src/main.rs
@ -58,6 +58,8 @@ enum ReviewError{
|
|||||||
WriteCurrent(std::io::Error),
|
WriteCurrent(std::io::Error),
|
||||||
ActionIO(std::io::Error),
|
ActionIO(std::io::Error),
|
||||||
ReadCurrent(std::io::Error),
|
ReadCurrent(std::io::Error),
|
||||||
|
DeduplicateModified(submissions_api::types::SingleItemError),
|
||||||
|
UploadModified(submissions_api::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ReviewConfig{
|
struct ReviewConfig{
|
||||||
@ -103,6 +105,46 @@ async fn review(config:ReviewConfig)->Result<(),ReviewError>{
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// default to_script_id is from from_script_id (only changed for replace policy)
|
||||||
|
let mut to_script_id=None;
|
||||||
|
// interpret action
|
||||||
|
let reviewed_policy=match script_action{
|
||||||
|
ScriptActionParseResult::Pass=>{
|
||||||
|
//if current.lua was updated, create an allowed and replace file and set script_action to replace(new_id)
|
||||||
|
let modified_source=tokio::fs::read_to_string("current.lua").await.map_err(ReviewError::ReadCurrent)?;
|
||||||
|
if modified_source==source{
|
||||||
|
submissions_api::types::Policy::Allowed
|
||||||
|
}else{
|
||||||
|
// compute hash
|
||||||
|
let mut hasher=siphasher::sip::SipHasher::new();
|
||||||
|
std::hash::Hasher::write(&mut hasher,source.as_bytes());
|
||||||
|
let hash=std::hash::Hasher::finish(&hasher);
|
||||||
|
|
||||||
|
// check if modified script already exists
|
||||||
|
let maybe_script_response=api.get_script_from_hash(submissions_api::types::HashRequest{
|
||||||
|
hash:format!("{:016x}",hash).as_str(),
|
||||||
|
}).await.map_err(ReviewError::DeduplicateModified)?;
|
||||||
|
|
||||||
|
// write to_script_id, uploading modified script if necessary
|
||||||
|
to_script_id=Some(match maybe_script_response{
|
||||||
|
Some(script_response)=>script_response.ID,
|
||||||
|
None=>api.create_script(submissions_api::types::CreateScriptRequest{
|
||||||
|
Name:script_response.Name.as_str(),
|
||||||
|
Source:modified_source.as_str(),
|
||||||
|
SubmissionID:Some(script_response.SubmissionID),
|
||||||
|
}).await.map_err(ReviewError::UploadModified)?.ID
|
||||||
|
});
|
||||||
|
|
||||||
|
// use replace policy
|
||||||
|
submissions_api::types::Policy::Replace
|
||||||
|
}
|
||||||
|
},
|
||||||
|
ScriptActionParseResult::Block=>submissions_api::types::Policy::Blocked,
|
||||||
|
ScriptActionParseResult::Exit=>break,
|
||||||
|
ScriptActionParseResult::Delete=>submissions_api::types::Policy::Delete,
|
||||||
|
};
|
||||||
|
|
||||||
|
// update policy
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
Reference in New Issue
Block a user