Merge pull request 'ModrinthAPIv2' (#9) from spookdot/hopper:ModrinthAPIv2 into main
Reviewed-on: #9
This commit is contained in:
commit
0d8aaaf2c9
83
src/api.rs
83
src/api.rs
|
@ -12,24 +12,25 @@ pub struct SearchResponse {
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
pub struct ModResult {
|
pub struct ModResult {
|
||||||
pub mod_id: String, // TODO parse to `local-xxxxx` with regex
|
pub slug: String,
|
||||||
pub project_type: Option<String>, // NOTE this isn't in all search results?
|
|
||||||
pub author: String,
|
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub description: String,
|
pub description: String,
|
||||||
pub categories: Vec<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 downloads: isize,
|
||||||
pub page_url: String,
|
|
||||||
pub icon_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_created: String,
|
||||||
pub date_modified: String,
|
pub date_modified: String,
|
||||||
pub latest_version: String,
|
pub latest_version: String,
|
||||||
pub license: String,
|
pub license: String,
|
||||||
pub client_side: String,
|
pub gallery: Vec<String>,
|
||||||
pub server_side: String,
|
|
||||||
pub host: String,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ModResult {
|
impl ModResult {
|
||||||
|
@ -59,28 +60,43 @@ impl ModResult {
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
pub struct ModInfo {
|
pub struct ModInfo {
|
||||||
pub id: String, // TODO serialize mod id?
|
|
||||||
pub slug: String,
|
pub slug: String,
|
||||||
pub team: String, // TODO serialize team id?
|
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub description: String,
|
pub description: String,
|
||||||
pub body: String,
|
|
||||||
pub published: String, // TODO serialize datetime
|
|
||||||
pub updated: String, // TODO serialize datetime
|
|
||||||
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 categories: Vec<String>,
|
||||||
pub versions: Vec<String>,
|
pub additional_categories: Vec<String>, // NOTE not listed in OpenAPI docs
|
||||||
pub icon_url: Option<String>,
|
pub client_side: String, // TODO serialize as enum
|
||||||
|
pub server_side: String, // TODO serialize as enum
|
||||||
|
pub body: String,
|
||||||
pub issues_url: Option<String>,
|
pub issues_url: Option<String>,
|
||||||
pub source_url: Option<String>,
|
pub source_url: Option<String>,
|
||||||
pub wiki_url: Option<String>,
|
pub wiki_url: Option<String>,
|
||||||
pub discord_url: Option<String>,
|
pub discord_url: Option<String>,
|
||||||
pub donation_urls: Vec<DonationLink>,
|
pub donation_urls: Option<Vec<DonationLink>>,
|
||||||
|
pub project_type: String,
|
||||||
|
pub downloads: isize,
|
||||||
|
pub icon_url: Option<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: Option<String>, // NOTE not listed in OpenAPI docs, TODO serialize as datetime
|
||||||
|
pub followers: isize,
|
||||||
|
pub status: String,
|
||||||
|
pub license: License,
|
||||||
|
pub versions: Vec<String>,
|
||||||
|
pub gallery: Option<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)]
|
#[derive(Deserialize, Debug)]
|
||||||
|
@ -99,22 +115,21 @@ pub struct DonationLink {
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
pub struct ModVersion {
|
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 name: String,
|
||||||
pub version_number: String,
|
pub version_number: String,
|
||||||
pub changelog: Option<String>,
|
pub changelog: Option<String>,
|
||||||
pub changelog_url: Option<String>,
|
// pub dependencies: Option<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 date_published: String, // TODO serialize datetime
|
||||||
pub downloads: isize,
|
pub downloads: isize,
|
||||||
pub version_type: String, // TODO {alpha | beta | release}
|
pub changelog_url: Option<String>, // NOTE deprecated
|
||||||
pub files: Vec<ModVersionFile>,
|
pub files: Vec<ModVersionFile>,
|
||||||
// pub dependencies: Vec<String>, // TODO dependency wrangling, thank you modrinth, very cool
|
|
||||||
pub game_versions: Vec<String>,
|
|
||||||
pub loaders: Vec<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
|
@ -122,4 +137,6 @@ pub struct ModVersionFile {
|
||||||
pub hashes: HashMap<String, String>,
|
pub hashes: HashMap<String, String>,
|
||||||
pub url: String,
|
pub url: String,
|
||||||
pub filename: 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);
|
println!("Searching with query \"{}\"...", search_args.package_name);
|
||||||
|
|
||||||
let client = reqwest::Client::new();
|
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 {
|
let mut params = vec![("query", search_args.package_name.to_owned())];
|
||||||
params.push(("versions", versions.join(",")));
|
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)?;
|
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> {
|
async fn fetch_mod_info(ctx: &AppContext, mod_result: &ModResult) -> anyhow::Result<ModInfo> {
|
||||||
let mod_id = &mod_result.mod_id;
|
let mod_id = &mod_result.project_id;
|
||||||
println!("Fetching mod info for {} (ID: {})...", mod_result.title, mod_id);
|
println!(
|
||||||
|
"Fetching mod info for {} (ID: {})...",
|
||||||
|
mod_result.title, mod_id
|
||||||
|
);
|
||||||
|
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
let mod_id = mod_id[6..].to_owned(); // Remove "local-" prefix
|
|
||||||
let url = format!(
|
let url = format!(
|
||||||
"https://{}/api/v1/mod/{}",
|
"https://{}/v2/project/{}",
|
||||||
ctx.config.upstream.server_address, mod_id
|
ctx.config.upstream.server_address, mod_id
|
||||||
);
|
);
|
||||||
info!("GET {}", url);
|
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 client = reqwest::Client::new();
|
||||||
let url = format!(
|
let url = format!(
|
||||||
"https://{}/api/v1/version/{}",
|
"https://{}/v2/version/{}",
|
||||||
ctx.config.upstream.server_address, version_id
|
ctx.config.upstream.server_address, version_id
|
||||||
);
|
);
|
||||||
info!("GET {}", url);
|
info!("GET {}", url);
|
||||||
|
|
Loading…
Reference in New Issue