mirror of
https://github.com/modrinth/code.git
synced 2026-08-25 09:04:55 +00:00
Allow v2 version creation route to accept environment (#6454)
* Allow v2 version creation route to accept environment * fix
This commit is contained in:
@@ -184,6 +184,12 @@ pub async fn project_create(
|
||||
server_side,
|
||||
),
|
||||
);
|
||||
if let Some(environment) = v.environment {
|
||||
fields.insert(
|
||||
"environment".to_string(),
|
||||
json!(environment),
|
||||
);
|
||||
}
|
||||
fields.insert(
|
||||
"game_versions".to_string(),
|
||||
json!(v.game_versions),
|
||||
|
||||
@@ -55,6 +55,7 @@ pub struct InitialVersionData {
|
||||
pub dependencies: Vec<Dependency>,
|
||||
#[validate(length(min = 1))]
|
||||
pub game_versions: Vec<String>,
|
||||
pub environment: Option<String>,
|
||||
#[serde(alias = "version_type")]
|
||||
pub release_channel: VersionType,
|
||||
#[validate(length(min = 1))]
|
||||
@@ -160,22 +161,26 @@ pub async fn version_create(
|
||||
.iter()
|
||||
.any(|field| field == "environment")
|
||||
{
|
||||
// If so, we get the field of an example version of the project, and set the side types to match.
|
||||
fields.insert(
|
||||
"environment".into(),
|
||||
get_example_version_fields(
|
||||
legacy_create.project_id,
|
||||
client,
|
||||
&redis,
|
||||
)
|
||||
.await?
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.find(|f| f.field_name == "environment")
|
||||
.map_or(json!("unknown"), |f| {
|
||||
f.value.serialize_internal()
|
||||
}),
|
||||
);
|
||||
let environment =
|
||||
if let Some(environment) = legacy_create.environment {
|
||||
json!(environment)
|
||||
} else {
|
||||
// If so, we get the field of an example version of the project, and set the side types to match.
|
||||
get_example_version_fields(
|
||||
legacy_create.project_id,
|
||||
client,
|
||||
&redis,
|
||||
)
|
||||
.await?
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.find(|f| f.field_name == "environment")
|
||||
.map_or(json!("unknown"), |f| {
|
||||
f.value.serialize_internal()
|
||||
})
|
||||
};
|
||||
|
||||
fields.insert("environment".into(), environment);
|
||||
}
|
||||
// Handle project type via file extension prediction
|
||||
let mut project_type = None;
|
||||
|
||||
Reference in New Issue
Block a user