mirror of
https://github.com/LCE-Hub/LCE-Emerald-Launcher.git
synced 2026-09-24 09:03:44 +00:00
fix(commands/skin): add support for skin->url
This commit is contained in:
@@ -25,12 +25,23 @@ pub async fn fetch_skin(app: AppHandle, username: String) -> Result<(String, Str
|
||||
}
|
||||
let mc_api_text = mc_api_res.text().await.map_err(|e| format!("Failed to read mc api text: {}", e))?;
|
||||
let mc_api_data: serde_json::Value = serde_json::from_str(&mc_api_text).map_err(|e| format!("Invalid MC API JSON: {}", e))?;
|
||||
let image_b64 = mc_api_data.get("skin")
|
||||
if let Some(b64) = mc_api_data.get("skin")
|
||||
.and_then(|s| s.get("image"))
|
||||
.and_then(|v| v.as_str())
|
||||
{
|
||||
return Ok((b64.to_string(), name_exact));
|
||||
}
|
||||
let skin_url = mc_api_data.get("skin")
|
||||
.and_then(|s| s.get("url"))
|
||||
.and_then(|v| v.as_str())
|
||||
.ok_or_else(|| "No skin found".to_string())?;
|
||||
|
||||
Ok((image_b64.to_string(), name_exact))
|
||||
let skin_resp = client.get(skin_url).send().await.map_err(|e| format!("Failed to fetch skin image: {}", e))?;
|
||||
if !skin_resp.status().is_success() {
|
||||
return Err(format!("Failed to download skin image: {}", skin_resp.status()));
|
||||
}
|
||||
let skin_bytes = skin_resp.bytes().await.map_err(|e| format!("Failed to read skin image bytes: {}", e))?;
|
||||
let image_b64 = base64::engine::general_purpose::STANDARD.encode(&skin_bytes);
|
||||
Ok((image_b64, name_exact))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
|
||||
Reference in New Issue
Block a user