diff --git a/pkg/model/nats.go b/pkg/model/nats.go index e193d10..1da2918 100644 --- a/pkg/model/nats.go +++ b/pkg/model/nats.go @@ -14,14 +14,14 @@ type ValidateRequest struct { } // Create a new map -type PublishNewRequest struct { +type UploadNewRequest struct { SubmissionID int64 ModelID int64 ModelVersion int64 ModelName string } -type PublishFixRequest struct { +type UploadFixRequest struct { SubmissionID int64 ModelID int64 ModelVersion int64 diff --git a/pkg/service/submissions.go b/pkg/service/submissions.go index 0ae7eeb..e8cf082 100644 --- a/pkg/service/submissions.go +++ b/pkg/service/submissions.go @@ -424,35 +424,35 @@ func (svc *Service) ActionSubmissionTriggerUpload(ctx context.Context, params ap // sentinel value because we are not using rust if submission.TargetAssetID == 0 { // this is a new map - publish_new_request := model.PublishNewRequest{ + upload_new_request := model.UploadNewRequest{ SubmissionID: submission.ID, ModelID: submission.ValidatedAssetID, ModelVersion: submission.ValidatedAssetVersion, - // publish as displayname, whatever + // upload as displayname, whatever ModelName: submission.DisplayName, } - j, err := json.Marshal(publish_new_request) + j, err := json.Marshal(upload_new_request) if err != nil { return err } - svc.Nats.Publish("maptest.submissions.publishnew", []byte(j)) + svc.Nats.Publish("maptest.submissions.uploadnew", []byte(j)) } else { // this is a map fix - publish_fix_request := model.PublishFixRequest{ + upload_fix_request := model.UploadFixRequest{ SubmissionID: submission.ID, ModelID: submission.ValidatedAssetID, ModelVersion: submission.ValidatedAssetVersion, TargetAssetID: submission.TargetAssetID, } - j, err := json.Marshal(publish_fix_request) + j, err := json.Marshal(upload_fix_request) if err != nil { return err } - svc.Nats.Publish("maptest.submissions.publishfix", []byte(j)) + svc.Nats.Publish("maptest.submissions.uploadfix", []byte(j)) } return nil diff --git a/validation/src/message_handler.rs b/validation/src/message_handler.rs index 498b5f6..c0a5dc2 100644 --- a/validation/src/message_handler.rs +++ b/validation/src/message_handler.rs @@ -5,8 +5,8 @@ pub enum HandleMessageError{ DoubleAck(async_nats::Error), Json(serde_json::Error), UnknownSubject(String), - PublishNew(crate::upload_new::PublishError), - PublishFix(crate::upload_fix::PublishError), + UploadNew(crate::upload_new::UploadError), + UploadFix(crate::upload_fix::UploadError), Validation(crate::validator::ValidateError), } impl std::fmt::Display for HandleMessageError{ @@ -23,8 +23,8 @@ fn from_slice<'a,T:serde::de::Deserialize<'a>>(slice:&'a [u8])->Result<T,HandleM } pub struct MessageHandler{ - publish_new:crate::upload_new::Publisher, - publish_fix:crate::upload_fix::Publisher, + upload_new:crate::upload_new::Uploader, + upload_fix:crate::upload_fix::Uploader, validator:crate::validator::Validator, } @@ -35,8 +35,8 @@ impl MessageHandler{ api:submissions_api::internal::Context, )->Self{ Self{ - publish_new:crate::upload_new::Publisher::new(cookie_context.clone(),group_id,api.clone()), - publish_fix:crate::upload_fix::Publisher::new(cookie_context.clone(),group_id,api.clone()), + upload_new:crate::upload_new::Uploader::new(cookie_context.clone(),group_id,api.clone()), + upload_fix:crate::upload_fix::Uploader::new(cookie_context.clone(),group_id,api.clone()), validator:crate::validator::Validator::new(cookie_context,api), } } @@ -44,8 +44,8 @@ impl MessageHandler{ let message=message_result.map_err(HandleMessageError::Messages)?; message.double_ack().await.map_err(HandleMessageError::DoubleAck)?; match message.subject.as_str(){ - "maptest.submissions.publishnew"=>self.publish_new.publish(from_slice(&message.payload)?).await.map_err(HandleMessageError::PublishNew), - "maptest.submissions.publishfix"=>self.publish_fix.publish(from_slice(&message.payload)?).await.map_err(HandleMessageError::PublishFix), + "maptest.submissions.uploadnew"=>self.upload_new.upload(from_slice(&message.payload)?).await.map_err(HandleMessageError::UploadNew), + "maptest.submissions.uploadfix"=>self.upload_fix.upload(from_slice(&message.payload)?).await.map_err(HandleMessageError::UploadFix), "maptest.submissions.validate"=>self.validator.validate(from_slice(&message.payload)?).await.map_err(HandleMessageError::Validation), other=>Err(HandleMessageError::UnknownSubject(other.to_owned())) } diff --git a/validation/src/nats_types.rs b/validation/src/nats_types.rs index 6e2360b..de41e7d 100644 --- a/validation/src/nats_types.rs +++ b/validation/src/nats_types.rs @@ -17,7 +17,7 @@ pub struct ValidateRequest{ // Create a new map #[allow(nonstandard_style)] #[derive(serde::Deserialize)] -pub struct PublishNewRequest{ +pub struct UploadNewRequest{ pub SubmissionID:i64, pub ModelID:u64, pub ModelVersion:u64, @@ -26,7 +26,7 @@ pub struct PublishNewRequest{ #[allow(nonstandard_style)] #[derive(serde::Deserialize)] -pub struct PublishFixRequest{ +pub struct UploadFixRequest{ pub SubmissionID:i64, pub ModelID:u64, pub ModelVersion:u64, diff --git a/validation/src/upload_fix.rs b/validation/src/upload_fix.rs index 34bf7c4..8aa3bac 100644 --- a/validation/src/upload_fix.rs +++ b/validation/src/upload_fix.rs @@ -1,26 +1,26 @@ -use crate::nats_types::PublishFixRequest; +use crate::nats_types::UploadFixRequest; #[allow(dead_code)] #[derive(Debug)] -pub enum PublishError{ +pub enum UploadError{ Get(rbx_asset::cookie::GetError), Json(serde_json::Error), Upload(rbx_asset::cookie::UploadError), ApiActionSubmissionUploaded(submissions_api::Error), } -impl std::fmt::Display for PublishError{ +impl std::fmt::Display for UploadError{ fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{ write!(f,"{self:?}") } } -impl std::error::Error for PublishError{} +impl std::error::Error for UploadError{} -pub struct Publisher{ +pub struct Uploader{ roblox_cookie:rbx_asset::cookie::CookieContext, group_id:Option<u64>, api_internal:submissions_api::internal::Context, } -impl Publisher{ +impl Uploader{ pub const fn new( roblox_cookie:rbx_asset::cookie::CookieContext, group_id:Option<u64>, @@ -32,30 +32,30 @@ impl Publisher{ api_internal, } } - pub async fn publish(&self,publish_info:PublishFixRequest)->Result<(),PublishError>{ + pub async fn upload(&self,upload_info:UploadFixRequest)->Result<(),UploadError>{ // 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)?; + 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=self.roblox_cookie.upload(rbx_asset::cookie::UploadRequest{ - assetid:publish_info.TargetAssetID, + assetid:upload_info.TargetAssetID, groupId:self.group_id, name:None, description:None, ispublic:None, allowComments:None, - },model_data).await.map_err(PublishError::Upload)?; + },model_data).await.map_err(UploadError::Upload)?; // that's it, the database entry does not need to be changed. // mark submission as uploaded, TargetAssetID is unchanged self.api_internal.action_submission_uploaded(submissions_api::types::ActionSubmissionUploadedRequest{ - SubmissionID:publish_info.SubmissionID, + SubmissionID:upload_info.SubmissionID, TargetAssetID:None, - }).await.map_err(PublishError::ApiActionSubmissionUploaded)?; + }).await.map_err(UploadError::ApiActionSubmissionUploaded)?; Ok(()) } diff --git a/validation/src/upload_new.rs b/validation/src/upload_new.rs index fc6ad5e..6e4f074 100644 --- a/validation/src/upload_new.rs +++ b/validation/src/upload_new.rs @@ -1,27 +1,27 @@ -use crate::nats_types::PublishNewRequest; +use crate::nats_types::UploadNewRequest; #[allow(dead_code)] #[derive(Debug)] -pub enum PublishError{ +pub enum UploadError{ Get(rbx_asset::cookie::GetError), Json(serde_json::Error), Create(rbx_asset::cookie::CreateError), SystemTime(std::time::SystemTimeError), ApiActionSubmissionUploaded(submissions_api::Error), } -impl std::fmt::Display for PublishError{ +impl std::fmt::Display for UploadError{ fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{ write!(f,"{self:?}") } } -impl std::error::Error for PublishError{} +impl std::error::Error for UploadError{} -pub struct Publisher{ +pub struct Uploader{ roblox_cookie:rbx_asset::cookie::CookieContext, group_id:Option<u64>, api:submissions_api::internal::Context, } -impl Publisher{ +impl Uploader{ pub const fn new( roblox_cookie:rbx_asset::cookie::CookieContext, group_id:Option<u64>, @@ -33,27 +33,27 @@ impl Publisher{ api, } } - pub async fn publish(&self,publish_info:PublishNewRequest)->Result<(),PublishError>{ + pub async fn upload(&self,upload_info:UploadNewRequest)->Result<(),UploadError>{ // 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)?; + 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=self.roblox_cookie.create(rbx_asset::cookie::CreateRequest{ - name:publish_info.ModelName.clone(), + name:upload_info.ModelName.clone(), description:"".to_owned(), ispublic:false, allowComments:false, groupId:self.group_id, - },model_data).await.map_err(PublishError::Create)?; + },model_data).await.map_err(UploadError::Create)?; // note the asset id of the created model for later release, and mark the submission as uploaded self.api.action_submission_uploaded(submissions_api::types::ActionSubmissionUploadedRequest{ - SubmissionID:publish_info.SubmissionID, + SubmissionID:upload_info.SubmissionID, TargetAssetID:Some(upload_response.AssetId), - }).await.map_err(PublishError::ApiActionSubmissionUploaded)?; + }).await.map_err(UploadError::ApiActionSubmissionUploaded)?; Ok(()) }