mirror of
https://github.com/modrinth/code.git
synced 2026-08-27 10:04:52 +00:00
fix: v3 environment fields in all v2 endpoints (#7082)
This commit is contained in:
@@ -28,6 +28,8 @@ pub struct LegacyProject {
|
||||
pub server_side: LegacySideType,
|
||||
/// A list of game versions this project supports
|
||||
pub game_versions: Vec<String>,
|
||||
/// The environments this project supports
|
||||
pub environment: Vec<String>,
|
||||
|
||||
// All other fields are the same as V3
|
||||
// If they change, or their constituent types change, we may need to
|
||||
@@ -125,6 +127,14 @@ impl LegacyProject {
|
||||
.filter_map(|v| v.as_str())
|
||||
.map(|v| v.to_string())
|
||||
.collect();
|
||||
let environment = data
|
||||
.fields
|
||||
.get("environment")
|
||||
.unwrap_or(&Vec::new())
|
||||
.iter()
|
||||
.filter_map(|v| v.as_str())
|
||||
.map(|v| v.to_string())
|
||||
.collect();
|
||||
|
||||
if let Some(versions_item) = versions_item {
|
||||
// Extract side types from remaining fields
|
||||
@@ -221,6 +231,7 @@ impl LegacyProject {
|
||||
client_side,
|
||||
server_side,
|
||||
game_versions,
|
||||
environment,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,6 +313,9 @@ pub struct LegacyVersion {
|
||||
/// A list of loaders this project supports (has a newtype struct)
|
||||
pub loaders: Vec<Loader>,
|
||||
|
||||
/// The environment this version supports
|
||||
pub environment: String,
|
||||
|
||||
pub id: VersionId,
|
||||
pub project_id: ProjectId,
|
||||
pub author_id: UserId,
|
||||
@@ -332,6 +346,12 @@ impl From<Version> for LegacyVersion {
|
||||
}
|
||||
}
|
||||
}
|
||||
let environment = data
|
||||
.fields
|
||||
.get("environment")
|
||||
.and_then(|value| value.as_str())
|
||||
.unwrap_or("unknown")
|
||||
.to_string();
|
||||
|
||||
// - if loader is mrpack, this is a modpack
|
||||
// the v2 loaders are whatever the corresponding loader fields are
|
||||
@@ -366,6 +386,7 @@ impl From<Version> for LegacyVersion {
|
||||
dependencies: data.dependencies,
|
||||
game_versions,
|
||||
loaders,
|
||||
environment,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ pub struct LegacyResultSearchProject {
|
||||
pub license: String,
|
||||
pub client_side: String,
|
||||
pub server_side: String,
|
||||
pub environment: Vec<String>,
|
||||
pub gallery: Vec<String>,
|
||||
pub featured_gallery: Option<String>,
|
||||
pub color: Option<u32>,
|
||||
@@ -118,6 +119,14 @@ impl LegacyResultSearchProject {
|
||||
|
||||
let environment =
|
||||
get_one_string_loader_field("environment").unwrap_or("unknown");
|
||||
let environments = result_search_project
|
||||
.loader_fields
|
||||
.get("environment")
|
||||
.cloned()
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.filter_map(|environment| environment.as_str().map(String::from))
|
||||
.collect();
|
||||
|
||||
let (client_side, server_side) =
|
||||
v2_reroute::convert_v3_environment_to_v2_side_types(
|
||||
@@ -141,6 +150,7 @@ impl LegacyResultSearchProject {
|
||||
all_project_types: result_search_project.all_project_types,
|
||||
client_side,
|
||||
server_side,
|
||||
environment: environments,
|
||||
versions,
|
||||
latest_version: result_search_project.version_id,
|
||||
categories,
|
||||
|
||||
Reference in New Issue
Block a user