maps-service/validation/src/publish_fix.rs

63 lines
1.8 KiB
Rust
Raw Normal View History

2024-12-12 00:44:56 +00:00
use crate::nats_types::PublishFixRequest;
#[allow(dead_code)]
2024-12-03 06:52:01 +00:00
#[derive(Debug)]
pub enum PublishError{
2024-12-12 00:44:56 +00:00
Get(rbx_asset::cookie::GetError),
Json(serde_json::Error),
Upload(rbx_asset::cookie::UploadError),
2024-12-14 20:44:56 +00:00
ApiActionSubmissionUploaded(submissions_api::Error),
2024-12-03 06:09:01 +00:00
}
2024-12-03 06:52:01 +00:00
impl std::fmt::Display for PublishError{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
write!(f,"{self:?}")
}
}
impl std::error::Error for PublishError{}
2024-12-03 06:09:01 +00:00
pub struct Publisher{
2024-12-03 06:52:01 +00:00
roblox_cookie:rbx_asset::cookie::CookieContext,
group_id:Option<u64>,
api_internal:submissions_api::internal::Context,
2024-12-03 06:09:01 +00:00
}
impl Publisher{
pub const fn new(
2024-12-03 06:52:01 +00:00
roblox_cookie:rbx_asset::cookie::CookieContext,
group_id:Option<u64>,
api_internal:submissions_api::internal::Context,
)->Self{
Self{
2024-12-03 06:52:01 +00:00
roblox_cookie,
group_id,
api_internal,
2024-12-03 06:09:01 +00:00
}
}
2024-12-18 04:30:31 +00:00
pub async fn publish(&self,publish_info:PublishFixRequest)->Result<(),PublishError>{
2024-12-12 00:44:56 +00:00
// download the map model version
let model_data=self.roblox_cookie.get_asset(rbx_asset::cookie::GetAssetRequest{
asset_id:publish_info.ModelID,
version:Some(publish_info.ModelVersion),
}).await.map_err(PublishError::Get)?;
// upload the map to the strafesnet group
let _upload_response=self.roblox_cookie.upload(rbx_asset::cookie::UploadRequest{
assetid:publish_info.TargetAssetID,
groupId:self.group_id,
2024-12-12 00:44:56 +00:00
name:None,
description:None,
ispublic:None,
allowComments:None,
},model_data).await.map_err(PublishError::Upload)?;
// that's it, the database entry does not need to be changed.
2024-12-14 20:44:56 +00:00
// mark submission as uploaded, TargetAssetID is unchanged
2024-12-19 00:00:11 +00:00
self.api_internal.action_submission_uploaded(submissions_api::types::ActionSubmissionUploadedRequest{
2024-12-14 20:44:56 +00:00
SubmissionID:publish_info.SubmissionID,
TargetAssetID:None,
}).await.map_err(PublishError::ApiActionSubmissionUploaded)?;
2024-12-12 00:44:56 +00:00
Ok(())
2024-12-03 06:09:01 +00:00
}
}