submissions-api: v0.1.1

This commit is contained in:
Quaternions 2024-12-14 12:44:56 -08:00
parent 7e940cdfb1
commit 7d2147779a
8 changed files with 42 additions and 20 deletions

View File

@ -952,7 +952,7 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
[[package]] [[package]]
name = "submissions-api" name = "submissions-api"
version = "0.1.0" version = "0.1.1"
dependencies = [ dependencies = [
"reqwest", "reqwest",
"serde", "serde",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "submissions-api" name = "submissions-api"
version = "0.1.0" version = "0.1.1"
edition = "2021" edition = "2021"
publish = ["strafesnet"] publish = ["strafesnet"]
repository = "https://git.itzana.me/StrafesNET/maps-service" repository = "https://git.itzana.me/StrafesNET/maps-service"

View File

@ -50,13 +50,19 @@ pub struct ScriptPolicyResponse{
#[allow(nonstandard_style)] #[allow(nonstandard_style)]
pub struct UpdateSubmissionModelRequest{ pub struct UpdateSubmissionModelRequest{
pub ID:i64, pub SubmissionID:i64,
pub ModelID:u64, pub ModelID:u64,
pub ModelVersion:u64, pub ModelVersion:u64,
} }
pub struct SubmissionID(pub i64); pub struct SubmissionID(pub i64);
#[allow(nonstandard_style)]
pub struct ActionSubmissionUploadedRequest{
pub SubmissionID:i64,
pub TargetAssetID:Option<u64>,
}
#[derive(Clone)] #[derive(Clone)]
pub struct Context{ pub struct Context{
base_url:String, base_url:String,
@ -112,7 +118,7 @@ impl Context{
.json().await.map_err(Error::Reqwest) .json().await.map_err(Error::Reqwest)
} }
pub async fn update_submission_model(&self,config:UpdateSubmissionModelRequest)->Result<(),Error>{ 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)?; let mut url=reqwest::Url::parse(url_raw.as_str()).map_err(Error::ParseError)?;
{ {
@ -126,6 +132,20 @@ impl Context{
Ok(()) Ok(())
} }
action!(action_submission_validate,"validator-validated"); pub async fn action_submission_uploaded(&self,config:ActionSubmissionUploadedRequest)->Result<(),Error>{
action!(action_submission_publish,"validator-published"); 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");
} }

4
validation/Cargo.lock generated
View File

@ -1804,9 +1804,9 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
[[package]] [[package]]
name = "submissions-api" name = "submissions-api"
version = "0.1.0" version = "0.1.1"
source = "sparse+https://git.itzana.me/api/packages/strafesnet/cargo/" source = "sparse+https://git.itzana.me/api/packages/strafesnet/cargo/"
checksum = "7969c6c0b770ecfb57220c340f732d62a6fb1165b9ef038e33e7cd5a9658bdd5" checksum = "7a56a1a29c7608cab695b426e286a435752321ed718c03199c858b2ab13525e3"
dependencies = [ dependencies = [
"reqwest", "reqwest",
"serde", "serde",

View File

@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
submissions-api = { version = "0.1.0", registry = "strafesnet" } submissions-api = { version = "0.1.1", registry = "strafesnet" }
async-nats = "0.38.0" async-nats = "0.38.0"
futures = "0.3.31" futures = "0.3.31"
rbx_asset = { version = "0.2.5", registry = "strafesnet" } rbx_asset = { version = "0.2.5", registry = "strafesnet" }

View File

@ -6,7 +6,7 @@ pub enum PublishError{
Get(rbx_asset::cookie::GetError), Get(rbx_asset::cookie::GetError),
Json(serde_json::Error), Json(serde_json::Error),
Upload(rbx_asset::cookie::UploadError), Upload(rbx_asset::cookie::UploadError),
ApiActionSubmissionPublish(submissions_api::Error), ApiActionSubmissionUploaded(submissions_api::Error),
} }
impl std::fmt::Display for PublishError{ impl std::fmt::Display for PublishError{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{ 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. // that's it, the database entry does not need to be changed.
// mark submission as published // mark submission as uploaded, TargetAssetID is unchanged
self.api.action_submission_publish( self.api.action_submission_uploaded(submissions_api::ActionSubmissionUploadedRequest{
submissions_api::SubmissionID(publish_info.SubmissionID) SubmissionID:publish_info.SubmissionID,
).await.map_err(PublishError::ApiActionSubmissionPublish)?; TargetAssetID:None,
}).await.map_err(PublishError::ApiActionSubmissionUploaded)?;
Ok(()) Ok(())
} }

View File

@ -50,10 +50,11 @@ impl Publisher{
groupId:Some(crate::GROUP_STRAFESNET), groupId:Some(crate::GROUP_STRAFESNET),
},model_data).await.map_err(PublishError::Create)?; },model_data).await.map_err(PublishError::Create)?;
// mark submission as published // note the asset id of the created model for later release, and mark the submission as uploaded
self.api.action_submission_publish( self.api.action_submission_uploaded(submissions_api::ActionSubmissionUploadedRequest{
submissions_api::SubmissionID(publish_info.SubmissionID) SubmissionID:publish_info.SubmissionID,
).await.map_err(PublishError::ApiActionSubmissionPublish)?; TargetAssetID:Some(upload_response.AssetId),
}).await.map_err(PublishError::ApiActionSubmissionPublish)?;
Ok(()) Ok(())
} }

View File

@ -167,14 +167,14 @@ impl Validator{
// update the submission to use the validated model // update the submission to use the validated model
self.api.update_submission_model(submissions_api::UpdateSubmissionModelRequest{ self.api.update_submission_model(submissions_api::UpdateSubmissionModelRequest{
ID:validate_info.SubmissionID, SubmissionID:validate_info.SubmissionID,
ModelID:model_id, ModelID:model_id,
ModelVersion:1, //TODO ModelVersion:1, //TODO
}).await.map_err(ValidateError::ApiUpdateSubmissionModel)?; }).await.map_err(ValidateError::ApiUpdateSubmissionModel)?;
}; };
// update the submission model status to validated // update the submission model status to validated
self.api.action_submission_validate( self.api.action_submission_validated(
submissions_api::SubmissionID(validate_info.SubmissionID) submissions_api::SubmissionID(validate_info.SubmissionID)
).await.map_err(ValidateError::ApiActionSubmissionValidate)?; ).await.map_err(ValidateError::ApiActionSubmissionValidate)?;