validation: pull out submissions api
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
1450c0f3a2
commit
4ce5d5e535
1
submissions-api-rs/.gitignore
vendored
Normal file
1
submissions-api-rs/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
1451
submissions-api-rs/Cargo.lock
generated
Normal file
1451
submissions-api-rs/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "api"
|
||||
name = "submissions-api"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
publish = ["strafesnet"]
|
24
validation/Cargo.lock
generated
24
validation/Cargo.lock
generated
@ -41,16 +41,6 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "api"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "arrayref"
|
||||
version = "0.3.9"
|
||||
@ -968,7 +958,6 @@ dependencies = [
|
||||
name = "maps-validation"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"api",
|
||||
"async-nats",
|
||||
"futures",
|
||||
"rbx_asset",
|
||||
@ -979,6 +968,7 @@ dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
"siphasher",
|
||||
"submissions-api",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
@ -1812,6 +1802,18 @@ version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
|
||||
|
||||
[[package]]
|
||||
name = "submissions-api"
|
||||
version = "0.1.0"
|
||||
source = "sparse+https://git.itzana.me/api/packages/strafesnet/cargo/"
|
||||
checksum = "7969c6c0b770ecfb57220c340f732d62a6fb1165b9ef038e33e7cd5a9658bdd5"
|
||||
dependencies = [
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "subtle"
|
||||
version = "2.6.1"
|
||||
|
@ -4,7 +4,7 @@ version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
api = { path = "api" }
|
||||
submissions-api = { version = "0.1.0", registry = "strafesnet" }
|
||||
async-nats = "0.38.0"
|
||||
futures = "0.3.31"
|
||||
rbx_asset = { version = "0.2.5", registry = "strafesnet" }
|
||||
|
@ -11,7 +11,7 @@ RUN cargo chef prepare --recipe-path recipe.json
|
||||
|
||||
FROM chef AS builder
|
||||
COPY --from=planner /app/recipe.json recipe.json
|
||||
COPY api ./api
|
||||
|
||||
# Notice that we are specifying the --target flag!
|
||||
RUN cargo chef cook --release --target x86_64-unknown-linux-musl --recipe-path recipe.json
|
||||
COPY . .
|
||||
|
@ -9,7 +9,7 @@ mod message_handler;
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug)]
|
||||
pub enum StartupError{
|
||||
API(api::ReqwestError),
|
||||
API(submissions_api::ReqwestError),
|
||||
NatsConnect(async_nats::ConnectError),
|
||||
NatsGetStream(async_nats::jetstream::context::GetStreamError),
|
||||
NatsConsumer(async_nats::jetstream::stream::ConsumerError),
|
||||
@ -34,7 +34,7 @@ async fn main()->Result<(),StartupError>{
|
||||
|
||||
// maps-service api
|
||||
let api_host=std::env::var("API_HOST").expect("API_HOST env required");
|
||||
let api=api::Context::new(api_host).map_err(StartupError::API)?;
|
||||
let api=submissions_api::Context::new(api_host).map_err(StartupError::API)?;
|
||||
|
||||
// nats
|
||||
let nats_host=std::env::var("NATS_HOST").expect("NATS_HOST env required");
|
||||
|
@ -26,7 +26,7 @@ pub struct MessageHandler{
|
||||
impl MessageHandler{
|
||||
pub fn new(
|
||||
cookie_context:rbx_asset::cookie::CookieContext,
|
||||
api:api::Context,
|
||||
api:submissions_api::Context,
|
||||
)->Self{
|
||||
Self{
|
||||
publish_new:crate::publish_new::Publisher::new(cookie_context.clone(),api.clone()),
|
||||
|
@ -6,7 +6,7 @@ pub enum PublishError{
|
||||
Get(rbx_asset::cookie::GetError),
|
||||
Json(serde_json::Error),
|
||||
Upload(rbx_asset::cookie::UploadError),
|
||||
ApiActionSubmissionPublish(api::Error),
|
||||
ApiActionSubmissionPublish(submissions_api::Error),
|
||||
}
|
||||
impl std::fmt::Display for PublishError{
|
||||
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
||||
@ -17,12 +17,12 @@ impl std::error::Error for PublishError{}
|
||||
|
||||
pub struct Publisher{
|
||||
roblox_cookie:rbx_asset::cookie::CookieContext,
|
||||
api:api::Context,
|
||||
api:submissions_api::Context,
|
||||
}
|
||||
impl Publisher{
|
||||
pub const fn new(
|
||||
roblox_cookie:rbx_asset::cookie::CookieContext,
|
||||
api:api::Context,
|
||||
api:submissions_api::Context,
|
||||
)->Self{
|
||||
Self{
|
||||
roblox_cookie,
|
||||
@ -54,7 +54,7 @@ impl Publisher{
|
||||
|
||||
// mark submission as published
|
||||
self.api.action_submission_publish(
|
||||
api::SubmissionID(publish_info.SubmissionID)
|
||||
submissions_api::SubmissionID(publish_info.SubmissionID)
|
||||
).await.map_err(PublishError::ApiActionSubmissionPublish)?;
|
||||
|
||||
Ok(())
|
||||
|
@ -7,7 +7,7 @@ pub enum PublishError{
|
||||
Json(serde_json::Error),
|
||||
Create(rbx_asset::cookie::CreateError),
|
||||
SystemTime(std::time::SystemTimeError),
|
||||
ApiActionSubmissionPublish(api::Error),
|
||||
ApiActionSubmissionPublish(submissions_api::Error),
|
||||
}
|
||||
impl std::fmt::Display for PublishError{
|
||||
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
||||
@ -18,12 +18,12 @@ impl std::error::Error for PublishError{}
|
||||
|
||||
pub struct Publisher{
|
||||
roblox_cookie:rbx_asset::cookie::CookieContext,
|
||||
api:api::Context,
|
||||
api:submissions_api::Context,
|
||||
}
|
||||
impl Publisher{
|
||||
pub const fn new(
|
||||
roblox_cookie:rbx_asset::cookie::CookieContext,
|
||||
api:api::Context,
|
||||
api:submissions_api::Context,
|
||||
)->Self{
|
||||
Self{
|
||||
roblox_cookie,
|
||||
@ -52,7 +52,7 @@ impl Publisher{
|
||||
|
||||
// mark submission as published
|
||||
self.api.action_submission_publish(
|
||||
api::SubmissionID(publish_info.SubmissionID)
|
||||
submissions_api::SubmissionID(publish_info.SubmissionID)
|
||||
).await.map_err(PublishError::ApiActionSubmissionPublish)?;
|
||||
|
||||
Ok(())
|
||||
|
@ -20,10 +20,10 @@ pub enum ValidateError{
|
||||
Get(rbx_asset::cookie::GetError),
|
||||
Json(serde_json::Error),
|
||||
ReadDom(ReadDomError),
|
||||
ApiGetScriptPolicy(api::Error),
|
||||
ApiGetScript(api::Error),
|
||||
ApiUpdateSubmissionModel(api::Error),
|
||||
ApiActionSubmissionValidate(api::Error),
|
||||
ApiGetScriptPolicy(submissions_api::Error),
|
||||
ApiGetScript(submissions_api::Error),
|
||||
ApiUpdateSubmissionModel(submissions_api::Error),
|
||||
ApiActionSubmissionValidate(submissions_api::Error),
|
||||
WriteDom(rbx_binary::EncodeError),
|
||||
Upload(rbx_asset::cookie::UploadError),
|
||||
Create(rbx_asset::cookie::CreateError),
|
||||
@ -37,13 +37,13 @@ impl std::error::Error for ValidateError{}
|
||||
|
||||
pub struct Validator{
|
||||
roblox_cookie:rbx_asset::cookie::CookieContext,
|
||||
api:api::Context,
|
||||
api:submissions_api::Context,
|
||||
}
|
||||
|
||||
impl Validator{
|
||||
pub const fn new(
|
||||
roblox_cookie:rbx_asset::cookie::CookieContext,
|
||||
api:api::Context,
|
||||
api:submissions_api::Context,
|
||||
)->Self{
|
||||
Self{
|
||||
roblox_cookie,
|
||||
@ -86,18 +86,18 @@ impl Validator{
|
||||
let hash=std::hash::Hasher::finish(&hasher);
|
||||
|
||||
// fetch the script policy
|
||||
let script_policy=self.api.get_script_policy_from_hash(api::ScriptPolicyHashRequest{
|
||||
let script_policy=self.api.get_script_policy_from_hash(submissions_api::ScriptPolicyHashRequest{
|
||||
hash:format!("{:x}",hash),
|
||||
}).await.map_err(ValidateError::ApiGetScriptPolicy)?;
|
||||
|
||||
// write the policy to the script_map, fetching the replacement code if necessary
|
||||
*replacement=match script_policy.Policy{
|
||||
api::Policy::None=>Policy::None,
|
||||
api::Policy::Allowed=>Policy::Allowed,
|
||||
api::Policy::Blocked=>Policy::Blocked,
|
||||
api::Policy::Delete=>Policy::Delete,
|
||||
api::Policy::Replace=>{
|
||||
let script=self.api.get_script(api::GetScriptRequest{
|
||||
submissions_api::Policy::None=>Policy::None,
|
||||
submissions_api::Policy::Allowed=>Policy::Allowed,
|
||||
submissions_api::Policy::Blocked=>Policy::Blocked,
|
||||
submissions_api::Policy::Delete=>Policy::Delete,
|
||||
submissions_api::Policy::Replace=>{
|
||||
let script=self.api.get_script(submissions_api::GetScriptRequest{
|
||||
ScriptID:script_policy.ToScriptID,
|
||||
}).await.map_err(ValidateError::ApiGetScript)?;
|
||||
Policy::Replace(script.Source)
|
||||
@ -166,7 +166,7 @@ impl Validator{
|
||||
};
|
||||
|
||||
// update the submission to use the validated model
|
||||
self.api.update_submission_model(api::UpdateSubmissionModelRequest{
|
||||
self.api.update_submission_model(submissions_api::UpdateSubmissionModelRequest{
|
||||
ID:validate_info.SubmissionID,
|
||||
ModelID:model_id,
|
||||
ModelVersion:1, //TODO
|
||||
@ -175,7 +175,7 @@ impl Validator{
|
||||
|
||||
// update the submission model status to validated
|
||||
self.api.action_submission_validate(
|
||||
api::SubmissionID(validate_info.SubmissionID)
|
||||
submissions_api::SubmissionID(validate_info.SubmissionID)
|
||||
).await.map_err(ValidateError::ApiActionSubmissionValidate)?;
|
||||
|
||||
Ok(())
|
||||
|
Loading…
Reference in New Issue
Block a user