This commit is contained in:
Andrea Toska 2025-04-27 11:36:14 +02:00
commit 1c1aa0b383
No known key found for this signature in database
GPG key ID: 5B3C83807CCBE9A2

View file

@ -1,4 +1,5 @@
use std::env; use std::env;
use std::io::Cursor;
use chrono::{NaiveDate, NaiveDateTime}; use chrono::{NaiveDate, NaiveDateTime};
use gxhash::{gxhash32, gxhash64}; use gxhash::{gxhash32, gxhash64};
use minio::s3::builders::{ObjectContent}; use minio::s3::builders::{ObjectContent};
@ -423,30 +424,32 @@ pub async fn change_mii(
Ok(()) Ok(())
} }
fn build_object_content(data: Vec<u8>) -> ObjectContent {
ObjectContent::SegmentedBytes(SegmentedBytes::new_from_bytes(data))
}
pub async fn generate_mii_images(client: Arc<Client>, bucket: &str, pid: i32, mii_data: &str) { pub async fn generate_mii_images(client: Arc<Client>, bucket: &str, pid: i32, mii_data: &str) {
let user_mii_key = format!("mii/{}", pid); let user_mii_key = format!("mii/{}", pid);
println!("Starting Mii image generation for PID {}", pid); println!("Starting Mii image generation for PID {}", pid);
// Upload normal face images
if let Some(png_data) = get_image_png(mii_data).await { if let Some(png_data) = get_image_png(mii_data).await {
println!("Fetched PNG for PID {}, uploading...", pid); println!("Fetched PNG for PID {}, uploading...", pid);
let object_content = ObjectContent::from(png_data.clone()); let content = ObjectContent::from(Cursor::new(png_data.clone()));
match client.put_object_content( match client.put_object_content(
bucket, bucket,
&format!("{}/normal_face.png", user_mii_key), &format!("{}/normal_face.png", user_mii_key),
object_content content
).send().await { ).send().await {
Ok(_) => println!("Uploaded normal_face.png for PID {}", pid), Ok(_) => println!("Uploaded normal_face.png for PID {}", pid),
Err(e) => println!("Failed to upload normal_face.png for PID {}: {:?}", pid, e), Err(e) => println!("Failed to upload normal_face.png for PID {}: {:?}", pid, e),
} }
} else {
println!("Failed to fetch PNG for PID {}", pid);
} }
if let Some(tga_data) = get_image_tga(mii_data).await { if let Some(tga_data) = get_image_tga(mii_data).await {
println!("Fetched TGA for PID {}, uploading...", pid); println!("Fetched TGA for PID {}, uploading...", pid);
let object_content = ObjectContent::from(tga_data.clone()); let object_content = ObjectContent::from(Cursor::new(tga_data.clone()));
match client.put_object_content( match client.put_object_content(
bucket, bucket,
&format!("{}/standard.tga", user_mii_key), &format!("{}/standard.tga", user_mii_key),
@ -468,13 +471,16 @@ pub async fn generate_mii_images(client: Arc<Client>, bucket: &str, pid: i32, mi
]; ];
for expression in expressions.iter() { for expression in expressions.iter() {
let url = format!("https://mii-unsecure.ariankordi.net/miis/image.png?data={}&expression={}&type=face&width=128&instance_count=1", mii_data, expression); let url = format!(
"https://mii-unsecure.ariankordi.net/miis/image.png?data={}&expression={}&type=face&width=128&instance_count=1",
mii_data, expression
);
println!("Fetching expression '{}' for PID {}", expression, pid); println!("Fetching expression '{}' for PID {}", expression, pid);
if let Ok(resp) = reqwest::get(&url).await { if let Ok(resp) = reqwest::get(&url).await {
if let Ok(bytes) = resp.bytes().await { if let Ok(bytes) = resp.bytes().await {
println!("Fetched expression '{}', uploading...", expression); println!("Fetched expression '{}', uploading...", expression);
let object_content = ObjectContent::from(bytes.to_vec()); let object_content = ObjectContent::Bytes(bytes.to_vec());
match client.put_object_content( match client.put_object_content(
bucket, bucket,
&format!("{}/{}.png", user_mii_key, expression), &format!("{}/{}.png", user_mii_key, expression),
@ -491,13 +497,16 @@ pub async fn generate_mii_images(client: Arc<Client>, bucket: &str, pid: i32, mi
} }
} }
let body_url = format!("https://mii-unsecure.ariankordi.net/miis/image.png?data={}&type=all_body&width=270&instance_count=1", mii_data); let body_url = format!(
"https://mii-unsecure.ariankordi.net/miis/image.png?data={}&type=all_body&width=270&instance_count=1",
mii_data
);
println!("Fetching body image for PID {}", pid); println!("Fetching body image for PID {}", pid);
if let Ok(resp) = reqwest::get(&body_url).await { if let Ok(resp) = reqwest::get(&body_url).await {
if let Ok(bytes) = resp.bytes().await { if let Ok(bytes) = resp.bytes().await {
println!("Fetched body image, uploading..."); println!("Fetched body image, uploading...");
let object_content = ObjectContent::from(bytes.to_vec()); let object_content = ObjectContent::Bytes(bytes.to_vec());
match client.put_object_content( match client.put_object_content(
bucket, bucket,
&format!("{}/body.png", user_mii_key), &format!("{}/body.png", user_mii_key),
@ -517,3 +526,4 @@ pub async fn generate_mii_images(client: Arc<Client>, bucket: &str, pid: i32, mi
} }