You've already forked AstralRinth
forked from didirus/AstralRinth
Make changelog in version response optional (#5115)
* Make changelog on version routes optional * fix clippy * fix ci
This commit is contained in:
@@ -306,7 +306,8 @@ pub struct LegacyVersion {
|
||||
pub featured: bool,
|
||||
pub name: String,
|
||||
pub version_number: String,
|
||||
pub changelog: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub changelog: Option<String>,
|
||||
pub changelog_url: Option<String>,
|
||||
pub date_published: DateTime<Utc>,
|
||||
pub downloads: u32,
|
||||
|
||||
@@ -661,7 +661,8 @@ pub struct Version {
|
||||
/// Games for which this version is compatible with, extracted from Loader/Project types
|
||||
pub games: Vec<String>,
|
||||
/// The changelog for this version of the project.
|
||||
pub changelog: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub changelog: Option<String>,
|
||||
|
||||
/// The date that this version was published.
|
||||
pub date_published: DateTime<Utc>,
|
||||
@@ -714,7 +715,7 @@ impl From<VersionQueryResult> for Version {
|
||||
version_number: v.version_number,
|
||||
project_types: data.project_types,
|
||||
games: data.games,
|
||||
changelog: v.changelog,
|
||||
changelog: Some(v.changelog),
|
||||
date_published: v.date_published,
|
||||
downloads: v.downloads as u32,
|
||||
version_type: match v.version_type.as_str() {
|
||||
|
||||
@@ -37,6 +37,12 @@ pub struct VersionListFilters {
|
||||
pub version_type: Option<VersionType>,
|
||||
pub limit: Option<usize>,
|
||||
pub offset: Option<usize>,
|
||||
#[serde(default = "default_true")]
|
||||
pub include_changelog: bool,
|
||||
}
|
||||
|
||||
fn default_true() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
#[get("version")]
|
||||
@@ -95,6 +101,7 @@ pub async fn version_list(
|
||||
version_type: filters.version_type,
|
||||
limit: filters.limit,
|
||||
offset: filters.offset,
|
||||
include_changelog: filters.include_changelog,
|
||||
};
|
||||
|
||||
let response = v3::versions::version_list(
|
||||
@@ -153,6 +160,8 @@ pub async fn version_project_get(
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct VersionIds {
|
||||
pub ids: String,
|
||||
#[serde(default = "default_true")]
|
||||
pub include_changelog: bool,
|
||||
}
|
||||
|
||||
#[get("versions")]
|
||||
@@ -163,7 +172,10 @@ pub async fn versions_get(
|
||||
redis: web::Data<RedisPool>,
|
||||
session_queue: web::Data<AuthQueue>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let ids = v3::versions::VersionIds { ids: ids.ids };
|
||||
let ids = v3::versions::VersionIds {
|
||||
ids: ids.ids,
|
||||
include_changelog: ids.include_changelog,
|
||||
};
|
||||
let response = v3::versions::versions_get(
|
||||
req,
|
||||
web::Query(ids),
|
||||
|
||||
@@ -436,7 +436,7 @@ async fn version_create_inner(
|
||||
version_number: builder.version_number.clone(),
|
||||
project_types: all_project_types,
|
||||
games: all_games,
|
||||
changelog: builder.changelog.clone(),
|
||||
changelog: Some(builder.changelog.clone()),
|
||||
date_published: Utc::now(),
|
||||
downloads: 0,
|
||||
version_type: version_data.release_channel,
|
||||
|
||||
@@ -121,6 +121,12 @@ pub async fn version_project_get_helper(
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct VersionIds {
|
||||
pub ids: String,
|
||||
#[serde(default = "default_true")]
|
||||
pub include_changelog: bool,
|
||||
}
|
||||
|
||||
fn default_true() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
pub async fn versions_get(
|
||||
@@ -150,10 +156,16 @@ pub async fn versions_get(
|
||||
.map(|x| x.1)
|
||||
.ok();
|
||||
|
||||
let versions =
|
||||
let mut versions =
|
||||
filter_visible_versions(versions_data, &user_option, &pool, &redis)
|
||||
.await?;
|
||||
|
||||
if !ids.include_changelog {
|
||||
for version in &mut versions {
|
||||
version.changelog = None;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(HttpResponse::Ok().json(versions))
|
||||
}
|
||||
|
||||
@@ -715,6 +727,8 @@ pub struct VersionListFilters {
|
||||
Returns if it matches any of the values
|
||||
*/
|
||||
pub loader_fields: Option<String>,
|
||||
#[serde(default = "default_true")]
|
||||
pub include_changelog: bool,
|
||||
}
|
||||
|
||||
pub async fn version_list(
|
||||
@@ -856,10 +870,16 @@ pub async fn version_list(
|
||||
});
|
||||
response.dedup_by(|a, b| a.inner.id == b.inner.id);
|
||||
|
||||
let response =
|
||||
let mut response =
|
||||
filter_visible_versions(response, &user_option, &pool, &redis)
|
||||
.await?;
|
||||
|
||||
if !filters.include_changelog {
|
||||
for version in &mut response {
|
||||
version.changelog = None;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(HttpResponse::Ok().json(response))
|
||||
} else {
|
||||
Err(ApiError::NotFound)
|
||||
|
||||
@@ -84,7 +84,7 @@ pub async fn test_patch_version() {
|
||||
.await;
|
||||
assert_eq!(version.name, "new version name");
|
||||
assert_eq!(version.version_number, "1.3.0");
|
||||
assert_eq!(version.changelog, "new changelog");
|
||||
assert_eq!(version.changelog, Some("new changelog".into()));
|
||||
assert_eq!(
|
||||
version.version_type,
|
||||
serde_json::from_str::<VersionType>("\"beta\"").unwrap()
|
||||
|
||||
Reference in New Issue
Block a user