Skip to content

Commit

Permalink
Modrinth uses id instead of slug (can't do the same for curseforge)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricky12Awesome committed Jun 3, 2022
1 parent a5dd246 commit ed65522
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
/test_packwiz
1 change: 1 addition & 0 deletions .idea/packwiz_modlist.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ serde = { version = "^1.0", features = ["derive"] }
serde_json = "^1.0"
clap = { version = "^3.1", features = ["cargo", "derive"] }
toml = "^0.5"
tokio = { version = "^1.17", features = ["full"] }
tokio = { version = "^1.19", features = ["full"] }
futures = "^0.3"
thiserror = "^1.0"
colored = "^2.0"
Expand Down
20 changes: 9 additions & 11 deletions src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,9 @@ pub struct PackMod {
pub name: String,
pub filename: String,
pub side: String,
pub download: PackModDownload,
pub update: PackModUpdate,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PackModDownload {
pub url: String,
#[serde(alias = "hash-format")]
pub hash_format: String,
pub hash: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PackModUpdate {
pub curseforge: Option<PackModUpdateCurseforge>,
Expand Down Expand Up @@ -99,8 +90,15 @@ impl From<ModrinthProject> for Project {
impl Project {
pub fn url(&self) -> String {
match self {
Project::CurseForge(CurseForgeProject { slug, .. }) => format!("https://www.curseforge.com/minecraft/mc-mods/{}", slug),
Project::Modrinth(ModrinthProject { slug, .. }) => format!("https://modrinth.com/mod/{}", slug)
Project::CurseForge(CurseForgeProject { slug, .. }) => format!("https://www.curseforge.com/minecraft/mc-mods/{slug}"),
Project::Modrinth(ModrinthProject { id, .. }) => format!("https://modrinth.com/mod/{id}")
}
}

pub fn id(&self) -> String {
match self {
Project::CurseForge(CurseForgeProject { id, .. }) => id.to_string(),
Project::Modrinth(ModrinthProject { id, .. }) => id.clone()
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ pub fn display_project(format: &str, project: &Project) -> String {
.replace("{DESCRIPTION}", &project.description())
.replace("{SUMMARY}", &project.description())
.replace("{URL}", &project.url())
.replace("{ID}", &project.id())
.replace("{SLUG}", &project.slug())
.replace("\\n", "\n")
}

pub async fn generate(args: &Args) -> GlobalResult<Data> {
Expand All @@ -29,9 +31,9 @@ pub async fn write_projects<W>(args: &Args, data: &Data, writer: &mut W) -> Glob
for project in &data.projects {
let display = display_project(&args.format, project);

info!("{}", &display);
info!("{display}");

let display = format!("{}\n", display);
let display = format!("{display}\n");

writer.write_all(&display.into_bytes()).await?;
}
Expand Down

0 comments on commit ed65522

Please sign in to comment.