Skip to content

Commit

Permalink
⭐feat: Add UUID parsing for LittleSkin and Mojang APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
FLYEMOJ1 committed Aug 19, 2024
1 parent b401c5b commit 2497274
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,20 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

// create a HTTP client and send a POST request
let client = Client::new();

// Send POST request to LittleSkin
let res = client.post("https://littleskin.cn/api/yggdrasil/api/profiles/minecraft")
.json(&body)
.send()?;

// get response text
// Get response from LittleSkin
let response_text = res.text()?;
println!("Response From LittleSkin Yggdrasil API: {:?}\n", response_text);

// Prase JSON response
// Parse JSON response from LittleSkin
let items: Vec<ResponseItem> = serde_json::from_str(&response_text)?;

// Regex format UUID
// Use regex to format UUID
let re = Regex::new(r"([a-fA-F0-9]{8})([a-fA-F0-9]{4})([a-fA-F0-9]{4})([a-fA-F0-9]{4})([a-fA-F0-9]{12})").unwrap();

for item in items {
Expand All @@ -42,10 +44,37 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
"{}-{}-{}-{}-{}",
&caps[1], &caps[2], &caps[3], &caps[4], &caps[5]
);
println!("Parsed Response");
println!("Parsed Response from LittleSkin");
println!("Username: {}", item.name);
println!("UUID: {}", formatted_uuid);
} else {
println!("Something wrong. Received: {}", item.id);
}
}

println!("Wait, trying to get UUID from Mojang API...\n");

// Send POST request to Mojang
let res = client.post("https://authserver.mojang.com/api/profiles/minecraft")
.json(&body)
.send()?;

// Get response from Mojang
let response_text = res.text()?;
println!("Response From Mojang API: {:?}\n", response_text);

// Parse JSON response from Mojang
let items: Vec<ResponseItem> = serde_json::from_str(&response_text)?;

for item in items {
if let Some(caps) = re.captures(&item.id) {
let formatted_uuid = format!(
"{}-{}-{}-{}-{}",
&caps[1], &caps[2], &caps[3], &caps[4], &caps[5]
);
println!("Parsed Response from Mojang");
println!("Username: {}", item.name);
println!("UUID: {}", formatted_uuid);
// This is not good enough, some one need to implement this piece of SH@T
} else {
println!("Something wrong. Received: {}", item.id);
}
Expand Down

0 comments on commit 2497274

Please sign in to comment.