parent
90841e28cb
commit
b1c8be9029
@ -3,7 +3,6 @@ use futures::StreamExt;
|
||||
mod message_handler;
|
||||
mod nats_types;
|
||||
mod types;
|
||||
mod uploader;
|
||||
mod upload_mapfix;
|
||||
mod upload_submission;
|
||||
mod validator;
|
||||
@ -84,7 +83,7 @@ async fn main()->Result<(),StartupError>{
|
||||
Err(e)=>println!("[Validation] There was an error, oopsie! {e}"),
|
||||
}
|
||||
// explicitly call drop to make the move semantics and permit release more obvious
|
||||
core::mem::drop(permit);
|
||||
drop(permit);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -24,10 +24,9 @@ fn from_slice<'a,T:serde::de::Deserialize<'a>>(slice:&'a [u8])->Result<T,HandleM
|
||||
}
|
||||
|
||||
pub struct MessageHandler{
|
||||
upload_mapfix:crate::upload_mapfix::Uploader,
|
||||
upload_submission:crate::upload_submission::Uploader,
|
||||
validate_mapfix:crate::validate_mapfix::Validator,
|
||||
validate_submission:crate::validate_submission::Validator,
|
||||
pub(crate) cookie_context:rbx_asset::cookie::CookieContext,
|
||||
pub(crate) group_id:Option<u64>,
|
||||
pub(crate) api:submissions_api::internal::Context,
|
||||
}
|
||||
|
||||
impl MessageHandler{
|
||||
@ -37,20 +36,19 @@ impl MessageHandler{
|
||||
api:submissions_api::internal::Context,
|
||||
)->Self{
|
||||
Self{
|
||||
upload_mapfix:crate::upload_mapfix::Uploader::new(crate::uploader::Uploader::new(cookie_context.clone(),group_id,api.clone())),
|
||||
upload_submission:crate::upload_submission::Uploader::new(crate::uploader::Uploader::new(cookie_context.clone(),group_id,api.clone())),
|
||||
validate_mapfix:crate::validate_mapfix::Validator::new(crate::validator::Validator::new(cookie_context.clone(),api.clone())),
|
||||
validate_submission:crate::validate_submission::Validator::new(crate::validator::Validator::new(cookie_context,api)),
|
||||
cookie_context,
|
||||
group_id,
|
||||
api,
|
||||
}
|
||||
}
|
||||
pub async fn handle_message_result(&self,message_result:MessageResult)->Result<(),HandleMessageError>{
|
||||
let message=message_result.map_err(HandleMessageError::Messages)?;
|
||||
message.double_ack().await.map_err(HandleMessageError::DoubleAck)?;
|
||||
match message.subject.as_str(){
|
||||
"maptest.mapfixes.upload"=>self.upload_mapfix.upload(from_slice(&message.payload)?).await.map_err(HandleMessageError::UploadMapfix),
|
||||
"maptest.submissions.upload"=>self.upload_submission.upload(from_slice(&message.payload)?).await.map_err(HandleMessageError::UploadSubmission),
|
||||
"maptest.mapfixes.validate"=>self.validate_mapfix.validate(from_slice(&message.payload)?).await.map_err(HandleMessageError::ValidateMapfix),
|
||||
"maptest.submissions.validate"=>self.validate_submission.validate(from_slice(&message.payload)?).await.map_err(HandleMessageError::ValidateSubmission),
|
||||
"maptest.mapfixes.upload"=>self.upload_mapfix(from_slice(&message.payload)?).await.map_err(HandleMessageError::UploadMapfix),
|
||||
"maptest.submissions.upload"=>self.upload_submission(from_slice(&message.payload)?).await.map_err(HandleMessageError::UploadSubmission),
|
||||
"maptest.mapfixes.validate"=>self.validate_mapfix(from_slice(&message.payload)?).await.map_err(HandleMessageError::ValidateMapfix),
|
||||
"maptest.submissions.validate"=>self.validate_submission(from_slice(&message.payload)?).await.map_err(HandleMessageError::ValidateSubmission),
|
||||
other=>Err(HandleMessageError::UnknownSubject(other.to_owned()))
|
||||
}
|
||||
}
|
||||
|
@ -15,23 +15,18 @@ impl std::fmt::Display for UploadError{
|
||||
}
|
||||
impl std::error::Error for UploadError{}
|
||||
|
||||
pub struct Uploader(crate::uploader::Uploader);
|
||||
impl Uploader{
|
||||
pub const fn new(inner:crate::uploader::Uploader)->Self{
|
||||
Self(inner)
|
||||
}
|
||||
pub async fn upload(&self,upload_info:UploadMapfixRequest)->Result<(),UploadError>{
|
||||
let Self(uploader)=self;
|
||||
impl crate::message_handler::MessageHandler{
|
||||
pub async fn upload_mapfix(&self,upload_info:UploadMapfixRequest)->Result<(),UploadError>{
|
||||
// download the map model version
|
||||
let model_data=uploader.roblox_cookie.get_asset(rbx_asset::cookie::GetAssetRequest{
|
||||
let model_data=self.cookie_context.get_asset(rbx_asset::cookie::GetAssetRequest{
|
||||
asset_id:upload_info.ModelID,
|
||||
version:Some(upload_info.ModelVersion),
|
||||
}).await.map_err(UploadError::Get)?;
|
||||
|
||||
// upload the map to the strafesnet group
|
||||
let _upload_response=uploader.roblox_cookie.upload(rbx_asset::cookie::UploadRequest{
|
||||
let _upload_response=self.cookie_context.upload(rbx_asset::cookie::UploadRequest{
|
||||
assetid:upload_info.TargetAssetID,
|
||||
groupId:uploader.group_id,
|
||||
groupId:self.group_id,
|
||||
name:None,
|
||||
description:None,
|
||||
ispublic:None,
|
||||
@ -41,7 +36,7 @@ impl Uploader{
|
||||
// that's it, the database entry does not need to be changed.
|
||||
|
||||
// mark mapfix as uploaded, TargetAssetID is unchanged
|
||||
uploader.api.action_mapfix_uploaded(submissions_api::types::ActionMapfixUploadedRequest{
|
||||
self.api.action_mapfix_uploaded(submissions_api::types::ActionMapfixUploadedRequest{
|
||||
MapfixID:upload_info.MapfixID,
|
||||
}).await.map_err(UploadError::ApiActionMapfixUploaded)?;
|
||||
|
||||
|
@ -16,30 +16,25 @@ impl std::fmt::Display for UploadError{
|
||||
}
|
||||
impl std::error::Error for UploadError{}
|
||||
|
||||
pub struct Uploader(crate::uploader::Uploader);
|
||||
impl Uploader{
|
||||
pub const fn new(inner:crate::uploader::Uploader)->Self{
|
||||
Self(inner)
|
||||
}
|
||||
pub async fn upload(&self,upload_info:UploadSubmissionRequest)->Result<(),UploadError>{
|
||||
let Self(uploader)=self;
|
||||
impl crate::message_handler::MessageHandler{
|
||||
pub async fn upload_submission(&self,upload_info:UploadSubmissionRequest)->Result<(),UploadError>{
|
||||
// download the map model version
|
||||
let model_data=uploader.roblox_cookie.get_asset(rbx_asset::cookie::GetAssetRequest{
|
||||
let model_data=self.cookie_context.get_asset(rbx_asset::cookie::GetAssetRequest{
|
||||
asset_id:upload_info.ModelID,
|
||||
version:Some(upload_info.ModelVersion),
|
||||
}).await.map_err(UploadError::Get)?;
|
||||
|
||||
// upload the map to the strafesnet group
|
||||
let upload_response=uploader.roblox_cookie.create(rbx_asset::cookie::CreateRequest{
|
||||
let upload_response=self.cookie_context.create(rbx_asset::cookie::CreateRequest{
|
||||
name:upload_info.ModelName.clone(),
|
||||
description:"".to_owned(),
|
||||
ispublic:false,
|
||||
allowComments:false,
|
||||
groupId:uploader.group_id,
|
||||
groupId:self.group_id,
|
||||
},model_data).await.map_err(UploadError::Create)?;
|
||||
|
||||
// note the asset id of the created model for later release, and mark the submission as uploaded
|
||||
uploader.api.action_submission_uploaded(submissions_api::types::ActionSubmissionUploadedRequest{
|
||||
self.api.action_submission_uploaded(submissions_api::types::ActionSubmissionUploadedRequest{
|
||||
SubmissionID:upload_info.SubmissionID,
|
||||
UploadedAssetID:upload_response.AssetId,
|
||||
}).await.map_err(UploadError::ApiActionSubmissionUploaded)?;
|
||||
|
@ -1,18 +0,0 @@
|
||||
pub struct Uploader{
|
||||
pub(crate) roblox_cookie:rbx_asset::cookie::CookieContext,
|
||||
pub(crate) group_id:Option<u64>,
|
||||
pub(crate) api:submissions_api::internal::Context,
|
||||
}
|
||||
impl Uploader{
|
||||
pub const fn new(
|
||||
roblox_cookie:rbx_asset::cookie::CookieContext,
|
||||
group_id:Option<u64>,
|
||||
api:submissions_api::internal::Context,
|
||||
)->Self{
|
||||
Self{
|
||||
roblox_cookie,
|
||||
group_id,
|
||||
api,
|
||||
}
|
||||
}
|
||||
}
|
@ -12,28 +12,22 @@ impl std::fmt::Display for ValidateMapfixError{
|
||||
}
|
||||
impl std::error::Error for ValidateMapfixError{}
|
||||
|
||||
pub struct Validator(crate::validator::Validator);
|
||||
impl Validator{
|
||||
pub const fn new(inner:crate::validator::Validator)->Self{
|
||||
Self(inner)
|
||||
}
|
||||
pub async fn validate(&self,validate_info:ValidateMapfixRequest)->Result<(),ValidateMapfixError>{
|
||||
let Self(validator)=self;
|
||||
|
||||
impl crate::message_handler::MessageHandler{
|
||||
pub async fn validate_mapfix(&self,validate_info:ValidateMapfixRequest)->Result<(),ValidateMapfixError>{
|
||||
let mapfix_id=validate_info.MapfixID;
|
||||
let validate_result=validator.validate(validate_info.into()).await;
|
||||
let validate_result=self.validate_inner(validate_info.into()).await;
|
||||
|
||||
// update the mapfix depending on the result
|
||||
match &validate_result{
|
||||
Ok(())=>{
|
||||
// update the mapfix model status to validated
|
||||
validator.api.action_mapfix_validated(
|
||||
self.api.action_mapfix_validated(
|
||||
submissions_api::types::MapfixID(mapfix_id)
|
||||
).await.map_err(ValidateMapfixError::ApiActionMapfixValidate)?;
|
||||
},
|
||||
Err(e)=>{
|
||||
// update the mapfix model status to accepted
|
||||
validator.api.action_mapfix_accepted(submissions_api::types::ActionMapfixAcceptedRequest{
|
||||
self.api.action_mapfix_accepted(submissions_api::types::ActionMapfixAcceptedRequest{
|
||||
MapfixID:mapfix_id,
|
||||
StatusMessage:format!("{e}"),
|
||||
}).await.map_err(ValidateMapfixError::ApiActionMapfixValidate)?;
|
||||
|
@ -12,28 +12,22 @@ impl std::fmt::Display for ValidateSubmissionError{
|
||||
}
|
||||
impl std::error::Error for ValidateSubmissionError{}
|
||||
|
||||
pub struct Validator(crate::validator::Validator);
|
||||
impl Validator{
|
||||
pub const fn new(inner:crate::validator::Validator)->Self{
|
||||
Self(inner)
|
||||
}
|
||||
pub async fn validate(&self,validate_info:ValidateSubmissionRequest)->Result<(),ValidateSubmissionError>{
|
||||
let Self(validator)=self;
|
||||
|
||||
impl crate::message_handler::MessageHandler{
|
||||
pub async fn validate_submission(&self,validate_info:ValidateSubmissionRequest)->Result<(),ValidateSubmissionError>{
|
||||
let submission_id=validate_info.SubmissionID;
|
||||
let validate_result=validator.validate(validate_info.into()).await;
|
||||
let validate_result=self.validate_inner(validate_info.into()).await;
|
||||
|
||||
// update the submission depending on the result
|
||||
match &validate_result{
|
||||
Ok(())=>{
|
||||
// update the submission model status to validated
|
||||
validator.api.action_submission_validated(
|
||||
self.api.action_submission_validated(
|
||||
submissions_api::types::SubmissionID(submission_id)
|
||||
).await.map_err(ValidateSubmissionError::ApiActionSubmissionValidate)?;
|
||||
},
|
||||
Err(e)=>{
|
||||
// update the submission model status to accepted
|
||||
validator.api.action_submission_accepted(submissions_api::types::ActionSubmissionAcceptedRequest{
|
||||
self.api.action_submission_accepted(submissions_api::types::ActionSubmissionAcceptedRequest{
|
||||
SubmissionID:submission_id,
|
||||
StatusMessage:format!("{e}"),
|
||||
}).await.map_err(ValidateSubmissionError::ApiActionSubmissionValidate)?;
|
||||
|
@ -86,24 +86,10 @@ impl From<crate::nats_types::ValidateSubmissionRequest> for ValidateRequest{
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Validator{
|
||||
pub(crate) roblox_cookie:rbx_asset::cookie::CookieContext,
|
||||
pub(crate) api:submissions_api::internal::Context,
|
||||
}
|
||||
|
||||
impl Validator{
|
||||
pub const fn new(
|
||||
roblox_cookie:rbx_asset::cookie::CookieContext,
|
||||
api:submissions_api::internal::Context,
|
||||
)->Self{
|
||||
Self{
|
||||
roblox_cookie,
|
||||
api,
|
||||
}
|
||||
}
|
||||
pub async fn validate(&self,validate_info:ValidateRequest)->Result<(),ValidateError>{
|
||||
impl crate::message_handler::MessageHandler{
|
||||
pub async fn validate_inner(&self,validate_info:ValidateRequest)->Result<(),ValidateError>{
|
||||
// download map
|
||||
let data=self.roblox_cookie.get_asset(rbx_asset::cookie::GetAssetRequest{
|
||||
let data=self.cookie_context.get_asset(rbx_asset::cookie::GetAssetRequest{
|
||||
asset_id:validate_info.ModelID,
|
||||
version:Some(validate_info.ModelVersion),
|
||||
}).await.map_err(ValidateError::ModelFileDownload)?;
|
||||
@ -238,7 +224,7 @@ impl Validator{
|
||||
// upload a model lol
|
||||
let model_id=if let Some(model_id)=validate_info.ValidatedModelID{
|
||||
// upload to existing id
|
||||
let response=self.roblox_cookie.upload(rbx_asset::cookie::UploadRequest{
|
||||
let response=self.cookie_context.upload(rbx_asset::cookie::UploadRequest{
|
||||
assetid:model_id,
|
||||
name:None,
|
||||
description:None,
|
||||
@ -254,7 +240,7 @@ impl Validator{
|
||||
return Err(ValidateError::ModelFileChildRefIsNil);
|
||||
};
|
||||
// create new model
|
||||
let response=self.roblox_cookie.create(rbx_asset::cookie::CreateRequest{
|
||||
let response=self.cookie_context.create(rbx_asset::cookie::CreateRequest{
|
||||
name:map_instance.name.clone(),
|
||||
description:"".to_owned(),
|
||||
ispublic:true,
|
||||
|
Loading…
x
Reference in New Issue
Block a user