From 7d2147779a707dcc4b099fa0ee55eb855fa87f98 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Sat, 14 Dec 2024 12:44:56 -0800 Subject: [PATCH] submissions-api: v0.1.1 --- submissions-api-rs/Cargo.lock | 2 +- submissions-api-rs/Cargo.toml | 2 +- submissions-api-rs/src/lib.rs | 28 ++++++++++++++++++++++++---- validation/Cargo.lock | 4 ++-- validation/Cargo.toml | 2 +- validation/src/publish_fix.rs | 11 ++++++----- validation/src/publish_new.rs | 9 +++++---- validation/src/validator.rs | 4 ++-- 8 files changed, 42 insertions(+), 20 deletions(-) diff --git a/submissions-api-rs/Cargo.lock b/submissions-api-rs/Cargo.lock index 4e9a058..6dac768 100644 --- a/submissions-api-rs/Cargo.lock +++ b/submissions-api-rs/Cargo.lock @@ -952,7 +952,7 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "submissions-api" -version = "0.1.0" +version = "0.1.1" dependencies = [ "reqwest", "serde", diff --git a/submissions-api-rs/Cargo.toml b/submissions-api-rs/Cargo.toml index cd3a126..b43aa4d 100644 --- a/submissions-api-rs/Cargo.toml +++ b/submissions-api-rs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "submissions-api" -version = "0.1.0" +version = "0.1.1" edition = "2021" publish = ["strafesnet"] repository = "https://git.itzana.me/StrafesNET/maps-service" diff --git a/submissions-api-rs/src/lib.rs b/submissions-api-rs/src/lib.rs index d580421..6639031 100644 --- a/submissions-api-rs/src/lib.rs +++ b/submissions-api-rs/src/lib.rs @@ -50,13 +50,19 @@ pub struct ScriptPolicyResponse{ #[allow(nonstandard_style)] pub struct UpdateSubmissionModelRequest{ - pub ID:i64, + pub SubmissionID:i64, pub ModelID:u64, pub ModelVersion:u64, } pub struct SubmissionID(pub i64); +#[allow(nonstandard_style)] +pub struct ActionSubmissionUploadedRequest{ + pub SubmissionID:i64, + pub TargetAssetID:Option, +} + #[derive(Clone)] pub struct Context{ base_url:String, @@ -112,7 +118,7 @@ impl Context{ .json().await.map_err(Error::Reqwest) } pub async fn update_submission_model(&self,config:UpdateSubmissionModelRequest)->Result<(),Error>{ - let url_raw=format!("{}/submissions/{}/model",self.base_url,config.ID); + let url_raw=format!("{}/submissions/{}/model",self.base_url,config.SubmissionID); let mut url=reqwest::Url::parse(url_raw.as_str()).map_err(Error::ParseError)?; { @@ -126,6 +132,20 @@ impl Context{ Ok(()) } - action!(action_submission_validate,"validator-validated"); - action!(action_submission_publish,"validator-published"); + pub async fn action_submission_uploaded(&self,config:ActionSubmissionUploadedRequest)->Result<(),Error>{ + let url_raw=format!("{}/submissions/{}/status/uploaded",self.base_url,config.SubmissionID); + let mut url=reqwest::Url::parse(url_raw.as_str()).map_err(Error::ParseError)?; + + if let Some(target_asset_id)=config.TargetAssetID{ + url.query_pairs_mut() + .append_pair("TargetAssetID",target_asset_id.to_string().as_str()); + } + + self.post(url).await.map_err(Error::Reqwest)? + .error_for_status().map_err(Error::Reqwest)?; + + Ok(()) + } + action!(action_submission_validated,"validator-validated"); + action!(action_submission_released,"releaser-released"); } diff --git a/validation/Cargo.lock b/validation/Cargo.lock index a3b7492..ca2e0a5 100644 --- a/validation/Cargo.lock +++ b/validation/Cargo.lock @@ -1804,9 +1804,9 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "submissions-api" -version = "0.1.0" +version = "0.1.1" source = "sparse+https://git.itzana.me/api/packages/strafesnet/cargo/" -checksum = "7969c6c0b770ecfb57220c340f732d62a6fb1165b9ef038e33e7cd5a9658bdd5" +checksum = "7a56a1a29c7608cab695b426e286a435752321ed718c03199c858b2ab13525e3" dependencies = [ "reqwest", "serde", diff --git a/validation/Cargo.toml b/validation/Cargo.toml index ee09354..d96d68c 100644 --- a/validation/Cargo.toml +++ b/validation/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -submissions-api = { version = "0.1.0", registry = "strafesnet" } +submissions-api = { version = "0.1.1", registry = "strafesnet" } async-nats = "0.38.0" futures = "0.3.31" rbx_asset = { version = "0.2.5", registry = "strafesnet" } diff --git a/validation/src/publish_fix.rs b/validation/src/publish_fix.rs index b4016ab..f0e5f2f 100644 --- a/validation/src/publish_fix.rs +++ b/validation/src/publish_fix.rs @@ -6,7 +6,7 @@ pub enum PublishError{ Get(rbx_asset::cookie::GetError), Json(serde_json::Error), Upload(rbx_asset::cookie::UploadError), - ApiActionSubmissionPublish(submissions_api::Error), + ApiActionSubmissionUploaded(submissions_api::Error), } impl std::fmt::Display for PublishError{ fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{ @@ -52,10 +52,11 @@ impl Publisher{ // that's it, the database entry does not need to be changed. - // mark submission as published - self.api.action_submission_publish( - submissions_api::SubmissionID(publish_info.SubmissionID) - ).await.map_err(PublishError::ApiActionSubmissionPublish)?; + // mark submission as uploaded, TargetAssetID is unchanged + self.api.action_submission_uploaded(submissions_api::ActionSubmissionUploadedRequest{ + SubmissionID:publish_info.SubmissionID, + TargetAssetID:None, + }).await.map_err(PublishError::ApiActionSubmissionUploaded)?; Ok(()) } diff --git a/validation/src/publish_new.rs b/validation/src/publish_new.rs index aed4fa8..a3e1efc 100644 --- a/validation/src/publish_new.rs +++ b/validation/src/publish_new.rs @@ -50,10 +50,11 @@ impl Publisher{ groupId:Some(crate::GROUP_STRAFESNET), },model_data).await.map_err(PublishError::Create)?; - // mark submission as published - self.api.action_submission_publish( - submissions_api::SubmissionID(publish_info.SubmissionID) - ).await.map_err(PublishError::ApiActionSubmissionPublish)?; + // note the asset id of the created model for later release, and mark the submission as uploaded + self.api.action_submission_uploaded(submissions_api::ActionSubmissionUploadedRequest{ + SubmissionID:publish_info.SubmissionID, + TargetAssetID:Some(upload_response.AssetId), + }).await.map_err(PublishError::ApiActionSubmissionPublish)?; Ok(()) } diff --git a/validation/src/validator.rs b/validation/src/validator.rs index 6bdec4f..e96e3c3 100644 --- a/validation/src/validator.rs +++ b/validation/src/validator.rs @@ -167,14 +167,14 @@ impl Validator{ // update the submission to use the validated model self.api.update_submission_model(submissions_api::UpdateSubmissionModelRequest{ - ID:validate_info.SubmissionID, + SubmissionID:validate_info.SubmissionID, ModelID:model_id, ModelVersion:1, //TODO }).await.map_err(ValidateError::ApiUpdateSubmissionModel)?; }; // update the submission model status to validated - self.api.action_submission_validate( + self.api.action_submission_validated( submissions_api::SubmissionID(validate_info.SubmissionID) ).await.map_err(ValidateError::ApiActionSubmissionValidate)?;