Update URLs and Structs for Modrinth API v2
This commit is contained in:
parent
44a81cf148
commit
d2325fe31f
85
src/api.rs
85
src/api.rs
|
@ -12,24 +12,25 @@ pub struct SearchResponse {
|
|||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct ModResult {
|
||||
pub mod_id: String, // TODO parse to `local-xxxxx` with regex
|
||||
pub project_type: Option<String>, // NOTE this isn't in all search results?
|
||||
pub author: String,
|
||||
pub slug: String,
|
||||
pub title: String,
|
||||
pub description: String,
|
||||
pub categories: Vec<String>,
|
||||
pub versions: Vec<String>,
|
||||
pub display_categories: Vec<String>, // NOTE this is not in the OpenAPI docs
|
||||
pub client_side: String,
|
||||
pub server_side: String,
|
||||
pub project_type: String, // NOTE this isn't in all search results?
|
||||
pub downloads: isize,
|
||||
pub page_url: String,
|
||||
pub icon_url: String,
|
||||
pub author_url: String,
|
||||
pub project_id: String, // TODO parse to 'local-xxxx' with reegex
|
||||
pub author: String,
|
||||
pub versions: Vec<String>,
|
||||
pub follows: isize,
|
||||
pub date_created: String,
|
||||
pub date_modified: String,
|
||||
pub latest_version: String,
|
||||
pub license: String,
|
||||
pub client_side: String,
|
||||
pub server_side: String,
|
||||
pub host: String,
|
||||
pub gallery: Vec<String>,
|
||||
}
|
||||
|
||||
impl ModResult {
|
||||
|
@ -59,28 +60,43 @@ impl ModResult {
|
|||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct ModInfo {
|
||||
pub id: String, // TODO serialize mod id?
|
||||
pub slug: String,
|
||||
pub team: String, // TODO serialize team id?
|
||||
pub title: String,
|
||||
pub description: String,
|
||||
pub categories: Vec<String>,
|
||||
pub additional_categories: Vec<String>, // NOTE not listed in OpenAPI docs
|
||||
pub client_side: String, // TODO serialize as enum
|
||||
pub server_side: String, // TODO serialize as enum
|
||||
pub body: String,
|
||||
pub published: String, // TODO serialize datetime
|
||||
pub updated: String, // TODO serialize datetime
|
||||
pub issues_url: String,
|
||||
pub source_url: String,
|
||||
pub wiki_url: Option<String>,
|
||||
pub discord_url: String,
|
||||
pub donation_urls: Vec<DonationLink>,
|
||||
pub project_type: String,
|
||||
pub downloads: isize,
|
||||
pub icon_url: String,
|
||||
pub id: String, // TODO serialize mod id?
|
||||
pub team: String, // TODO serialize team id?
|
||||
pub body_url: Option<String>, // NOTE deprecated
|
||||
pub moderator_message: Option<String>,
|
||||
pub published: String, // TODO serialize as datetime
|
||||
pub updated: String, // TODO serialize as datetime
|
||||
pub approved: String, // NOTE not listed in OpenAPI docs, TODO serialize as datetime
|
||||
pub followers: isize,
|
||||
pub status: String,
|
||||
pub license: License,
|
||||
pub client_side: String, // TODO serialize as enum
|
||||
pub server_side: String, // TODO serialize as enum
|
||||
pub downloads: isize,
|
||||
pub followers: isize,
|
||||
pub categories: Vec<String>,
|
||||
pub versions: Vec<String>,
|
||||
pub icon_url: Option<String>,
|
||||
pub issues_url: Option<String>,
|
||||
pub source_url: Option<String>,
|
||||
pub wiki_url: Option<String>,
|
||||
pub discord_url: Option<String>,
|
||||
pub donation_urls: Vec<DonationLink>,
|
||||
pub gallery: Vec<GalleryEntry>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct GalleryEntry {
|
||||
pub url: String,
|
||||
pub featured: bool,
|
||||
pub title: String,
|
||||
pub description: String,
|
||||
pub created: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
|
@ -99,22 +115,21 @@ pub struct DonationLink {
|
|||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct ModVersion {
|
||||
pub id: String, // version id
|
||||
pub mod_id: String, // mod id
|
||||
pub author_id: String, // user id
|
||||
// NOTE modrinth docs list this as a String, but is actually a bool?
|
||||
// featured: String, // user id
|
||||
pub name: String,
|
||||
pub version_number: String,
|
||||
pub changelog: Option<String>,
|
||||
pub changelog_url: Option<String>,
|
||||
pub date_published: String, // TODO serialize datetime
|
||||
pub downloads: isize,
|
||||
pub version_type: String, // TODO {alpha | beta | release}
|
||||
pub files: Vec<ModVersionFile>,
|
||||
// pub dependencies: Vec<String>, // TODO dependency wrangling, thank you modrinth, very cool
|
||||
pub game_versions: Vec<String>,
|
||||
pub version_type: String, // TODO {alpha | beta | release}
|
||||
pub loaders: Vec<String>,
|
||||
pub featured: bool,
|
||||
pub id: String, // version id
|
||||
pub project_id: String, // mod id
|
||||
pub author_id: String, // user id
|
||||
pub date_published: String, // TODO serialize datetime
|
||||
pub downloads: isize,
|
||||
pub changelog_url: Option<String>, // NOTE deprecated
|
||||
pub files: Vec<ModVersionFile>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
|
@ -122,4 +137,6 @@ pub struct ModVersionFile {
|
|||
pub hashes: HashMap<String, String>,
|
||||
pub url: String,
|
||||
pub filename: String,
|
||||
pub primary: bool,
|
||||
pub size: isize,
|
||||
}
|
||||
|
|
24
src/main.rs
24
src/main.rs
|
@ -14,10 +14,16 @@ async fn search_mods(ctx: &AppContext, search_args: &SearchArgs) -> anyhow::Resu
|
|||
println!("Searching with query \"{}\"...", search_args.package_name);
|
||||
|
||||
let client = reqwest::Client::new();
|
||||
let url = format!("https://{}/api/v1/mod", ctx.config.upstream.server_address);
|
||||
let url = format!("https://{}/v2/search", ctx.config.upstream.server_address);
|
||||
|
||||
let mut params = vec![("query", search_args.package_name.to_owned())]; if let Some(versions) = &search_args.version {
|
||||
params.push(("versions", versions.join(",")));
|
||||
let mut params = vec![("query", search_args.package_name.to_owned())];
|
||||
if let Some(versions) = &search_args.version {
|
||||
let versions_facets = versions
|
||||
.iter()
|
||||
.map(|e| format!("[\"versions:{}\"]", e))
|
||||
.collect::<Vec<String>>()
|
||||
.join(",");
|
||||
params.push(("facets", format!("[{}]", versions_facets)));
|
||||
}
|
||||
|
||||
let url = reqwest::Url::parse_with_params(url.as_str(), ¶ms)?;
|
||||
|
@ -96,13 +102,15 @@ async fn select_from_results(
|
|||
}
|
||||
|
||||
async fn fetch_mod_info(ctx: &AppContext, mod_result: &ModResult) -> anyhow::Result<ModInfo> {
|
||||
let mod_id = &mod_result.mod_id;
|
||||
println!("Fetching mod info for {} (ID: {})...", mod_result.title, mod_id);
|
||||
let mod_id = &mod_result.project_id;
|
||||
println!(
|
||||
"Fetching mod info for {} (ID: {})...",
|
||||
mod_result.title, mod_id
|
||||
);
|
||||
|
||||
let client = reqwest::Client::new();
|
||||
let mod_id = mod_id[6..].to_owned(); // Remove "local-" prefix
|
||||
let url = format!(
|
||||
"https://{}/api/v1/mod/{}",
|
||||
"https://{}/v2/project/{}",
|
||||
ctx.config.upstream.server_address, mod_id
|
||||
);
|
||||
info!("GET {}", url);
|
||||
|
@ -116,7 +124,7 @@ async fn fetch_mod_version(ctx: &AppContext, version_id: &String) -> anyhow::Res
|
|||
|
||||
let client = reqwest::Client::new();
|
||||
let url = format!(
|
||||
"https://{}/api/v1/version/{}",
|
||||
"https://{}/v2/version/{}",
|
||||
ctx.config.upstream.server_address, version_id
|
||||
);
|
||||
info!("GET {}", url);
|
||||
|
|
Loading…
Reference in New Issue