You've already forked AstralRinth
forked from didirus/AstralRinth
feat(labrinth): rework v3 side types to a single environment field (#3701)
* feat(labrinth): rework v3 side types to a single `environment` field This field is meant to be able to represent the existing v2 side type information and beyond, in a way that may also be slightly easier to comprehend. * chore(labrinth/migrations): use proper val for `HAVING` clause * feat(labrinth): add `side_types_migration_review_status` field to projects
This commit is contained in:
committed by
GitHub
parent
65126b3a23
commit
ef04dcc37b
@@ -105,7 +105,7 @@ pub async fn version_create(
|
||||
json!(legacy_create.game_versions),
|
||||
);
|
||||
|
||||
// Get all possible side-types for loaders given- we will use these to check if we need to convert/apply singleplayer, etc.
|
||||
// Get all possible side-types for loaders given- we will use these to check if we need to convert/apply side types
|
||||
let loaders =
|
||||
match v3::tags::loader_list(client.clone(), redis.clone())
|
||||
.await
|
||||
@@ -136,53 +136,32 @@ pub async fn version_create(
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// Copies side types of another version of the project.
|
||||
// If no version exists, defaults to all false.
|
||||
// If no version exists, defaults to an unknown side type.
|
||||
// This is inherently lossy, but not much can be done about it, as side types are no longer associated with projects,
|
||||
// so the 'missing' ones can't be easily accessed, and versions do need to have these fields explicitly set.
|
||||
let side_type_loader_field_names = [
|
||||
"singleplayer",
|
||||
"client_and_server",
|
||||
"client_only",
|
||||
"server_only",
|
||||
];
|
||||
// so the 'missing' ones can't be easily accessed, and versions do need to have that field explicitly set.
|
||||
|
||||
// Check if loader_fields_aggregate contains any of these side types
|
||||
// Check if loader_fields_aggregate contains the side types
|
||||
// We assume these four fields are linked together.
|
||||
if loader_fields_aggregate
|
||||
.iter()
|
||||
.any(|f| side_type_loader_field_names.contains(&f.as_str()))
|
||||
.any(|field| field == "environment")
|
||||
{
|
||||
// If so, we get the fields of the example version of the project, and set the side types to match.
|
||||
fields.extend(
|
||||
side_type_loader_field_names
|
||||
.iter()
|
||||
.map(|f| (f.to_string(), json!(false))),
|
||||
);
|
||||
if let Some(example_version_fields) =
|
||||
// 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?
|
||||
{
|
||||
fields.extend(
|
||||
example_version_fields.into_iter().filter_map(
|
||||
|f| {
|
||||
if side_type_loader_field_names
|
||||
.contains(&f.field_name.as_str())
|
||||
{
|
||||
Some((
|
||||
f.field_name,
|
||||
f.value.serialize_internal(),
|
||||
))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.find(|f| f.field_name == "environment")
|
||||
.map_or(json!("unknown"), |f| {
|
||||
f.value.serialize_internal()
|
||||
}),
|
||||
);
|
||||
}
|
||||
// Handle project type via file extension prediction
|
||||
let mut project_type = None;
|
||||
|
||||
Reference in New Issue
Block a user