Skip to content

Commit

Permalink
update api mod.json and allow * for deps
Browse files Browse the repository at this point in the history
  • Loading branch information
Fleeym committed Feb 19, 2024
1 parent 0bd16c2 commit 98eb7a8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
24 changes: 22 additions & 2 deletions src/types/mod_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ pub struct ModJson {
pub hash: String,
#[serde(default, rename = "early-load")]
pub early_load: bool,
#[serde(default)]
pub api: bool,
pub api: Option<serde_json::Value>,
pub gd: ModJsonGDVersionType,
#[serde(skip_deserializing)]
pub logo: Vec<u8>,
Expand Down Expand Up @@ -211,6 +210,15 @@ impl ModJson {
let mut ret: Vec<DependencyCreate> = vec![];

for i in deps {
if i.version == "*" {
ret.push(DependencyCreate {
dependency_id: i.id.clone(),
version: "*".to_string(),
compare: ModVersionCompare::MoreEq,
importance: i.importance,
});
continue;
}
let (dependency_ver, compare) = match split_version_and_compare(i.version.as_str()) {
Err(_) => {
return Err(ApiError::BadRequest(format!(
Expand Down Expand Up @@ -245,6 +253,15 @@ impl ModJson {
let mut ret: Vec<IncompatibilityCreate> = vec![];

for i in incompat {
if i.version == "*" {
ret.push(IncompatibilityCreate {
incompatibility_id: i.id.clone(),
version: "*".to_string(),
compare: ModVersionCompare::MoreEq,
importance: i.importance,
});
continue;
}
let (ver, compare) = match split_version_and_compare(i.version.as_str()) {
Err(_) => {
return Err(ApiError::BadRequest(format!(
Expand Down Expand Up @@ -342,6 +359,9 @@ fn parse_zip_entry_to_str(file: &mut ZipFile) -> Result<String, String> {
}

fn validate_dependency_version_str(ver: &str) -> bool {
if ver == "*" {
return true;
}
let mut copy = ver.to_string();
if ver.starts_with("<=") {
copy = copy.trim_start_matches("<=").to_string();
Expand Down
18 changes: 15 additions & 3 deletions src/types/models/mod_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ impl ModVersion {
separated.push_bind(&json.hash);
separated.push_bind(&json.geode);
separated.push_bind(json.early_load);
separated.push_bind(json.api);
separated.push_bind(json.api.is_some());
separated.push_bind(&json.id);
separated.push_unseparated(") RETURNING id");
let result = builder.build().fetch_one(&mut *pool).await;
Expand Down Expand Up @@ -268,7 +268,13 @@ impl ModVersion {
deps.into_iter()
.map(|x| ResponseDependency {
mod_id: x.dependency_id.clone(),
version: format!("{}{}", x.compare, x.version.trim_start_matches('v')),
version: {
if x.version == "*" {
"*".to_string()
} else {
format!("{}{}", x.compare, x.version.trim_start_matches('v'))
}
},
importance: x.importance,
})
.collect(),
Expand All @@ -279,7 +285,13 @@ impl ModVersion {
.into_iter()
.map(|x| ResponseIncompatibility {
mod_id: x.incompatibility_id.clone(),
version: format!("{}{}", x.compare, x.version.trim_start_matches('v')),
version: {
if x.version == "*" {
"*".to_string()
} else {
format!("{}{}", x.compare, x.version.trim_start_matches('v'))
}
},
importance: x.importance,
})
.collect(),
Expand Down

0 comments on commit 98eb7a8

Please sign in to comment.