Skip to content

Commit 63870ec

Browse files
authored
Merge pull request #120 from Not-A-Normal-Robot/inline-mcapi
Inline mcapi code into main branch
2 parents ee5d6b6 + 7efee4e commit 63870ec

File tree

11 files changed

+774
-134
lines changed

11 files changed

+774
-134
lines changed

Cargo.lock

Lines changed: 9 additions & 67 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ glob = "0.3"
4646
hex = "0.4"
4747
indexmap = "2.1"
4848
indicatif = "0.18"
49-
mcapi = { git = "https://github.com/ParadigmMC/mcapi.git" }
5049
md-5 = "0.10"
5150
notify-debouncer-full = { version = "0.3" }
5251
opener = "0.8"
@@ -78,6 +77,8 @@ tokio-util = { version = "0.7", features = ["io"] }
7877
toml = "0.9"
7978
walkdir = "2.4"
8079
zip = "0.6"
80+
lazy_static = "1.5.0"
81+
thiserror = "2.0.17"
8182

8283
[features]
8384
autocomplete = ["clap_complete"]

src/core/bootstrap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use pathdiff::diff_paths;
99
use tokio::fs;
1010
use walkdir::WalkDir;
1111

12-
use crate::model::BootstrappedFile;
12+
use crate::{model::BootstrappedFile, util::dollar_repl};
1313

1414
use super::BuildContext;
1515

@@ -230,7 +230,7 @@ impl BuildContext<'_> {
230230
}
231231

232232
pub fn bootstrap_content(&self, content: &str) -> String {
233-
mcapi::dollar_repl(content, |k| {
233+
dollar_repl(content, |k| {
234234
let k = k.trim();
235235

236236
let (k, def) = if let Some((k, def)) = k.split_once(':') {

src/interop/markdown.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,13 +294,12 @@ impl MarkdownAPI<'_> {
294294
}
295295

296296
Downloadable::Hangar { id, version } => {
297-
let proj = mcapi::hangar::fetch_project(&self.0.http_client, id).await?;
297+
let proj = crate::sources::hangar::fetch_project(&self.0.http_client, id).await?;
298298

299299
(
300300
format!(
301301
"[{}](https://hangar.papermc.io/{})",
302-
proj.name,
303-
proj.namespace.to_string()
302+
proj.name, proj.namespace
304303
),
305304
sanitize(&proj.description)?,
306305
version.clone(),

src/model/servertoml.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use std::{
99
use anyhow::{anyhow, bail, Result};
1010
use serde::{Deserialize, Serialize};
1111

12+
use crate::util::dollar_repl;
13+
1214
use super::{ClientSideMod, Downloadable, Hook, ServerLauncher, ServerType, World};
1315

1416
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
@@ -140,7 +142,7 @@ impl Server {
140142
}
141143

142144
pub fn format(&self, str: &str) -> String {
143-
mcapi::dollar_repl(str, |key| match key {
145+
dollar_repl(str, |key| match key {
144146
"mcver" | "mcversion" | "SERVER_VERSION" => Some(self.mc_version.clone()),
145147
"SERVER_NAME" => Some(self.name.clone()),
146148
k => self.variables.get(k).cloned(),

src/sources/fabric.rs

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,53 @@
11
use std::{borrow::Cow, collections::HashMap};
22

3+
use crate::app::{App, CacheStrategy, ResolvedFile};
34
use anyhow::{anyhow, Result};
4-
use mcapi::fabric::{FabricInstaller, FabricLoader, FABRIC_META_URL};
5+
use serde::{Deserialize, Serialize};
56

6-
use crate::app::{App, CacheStrategy, ResolvedFile};
7+
pub const FABRIC_META_URL: &str = "https://meta.fabricmc.net";
8+
9+
#[derive(Debug, Deserialize, Serialize, Clone)]
10+
pub struct FabricLoader {
11+
pub separator: String,
12+
pub build: u64,
13+
pub maven: String,
14+
pub version: String,
15+
pub stable: bool,
16+
}
17+
18+
#[derive(Debug, Deserialize, Serialize, Clone)]
19+
pub struct FabricInstaller {
20+
pub url: String,
21+
pub maven: String,
22+
pub version: String,
23+
pub stable: bool,
24+
}
25+
26+
pub async fn fetch_loaders(client: &reqwest::Client) -> Result<Vec<FabricLoader>> {
27+
Ok(client
28+
.get(FABRIC_META_URL.to_owned() + "/v2/versions/loader")
29+
.send()
30+
.await?
31+
.error_for_status()?
32+
.json()
33+
.await?)
34+
}
35+
36+
pub async fn fetch_installers(client: &reqwest::Client) -> Result<Vec<FabricInstaller>> {
37+
Ok(client
38+
.get(FABRIC_META_URL.to_owned() + "/v2/versions/installer")
39+
.send()
40+
.await?
41+
.error_for_status()?
42+
.json()
43+
.await?)
44+
}
745

846
pub struct FabricAPI<'a>(pub &'a App);
947

1048
impl FabricAPI<'_> {
1149
pub async fn fetch_loaders(&self) -> Result<Vec<FabricLoader>> {
12-
Ok(mcapi::fabric::fetch_loaders(&self.0.http_client).await?)
50+
fetch_loaders(&self.0.http_client).await
1351
}
1452

1553
pub async fn fetch_latest_loader(&self) -> Result<String> {
@@ -23,7 +61,7 @@ impl FabricAPI<'_> {
2361
}
2462

2563
pub async fn fetch_installers(&self) -> Result<Vec<FabricInstaller>> {
26-
Ok(mcapi::fabric::fetch_installers(&self.0.http_client).await?)
64+
fetch_installers(&self.0.http_client).await
2765
}
2866

2967
pub async fn fetch_latest_installer(&self) -> Result<String> {

0 commit comments

Comments
 (0)