diff --git a/crates/lib/mysql_queries/src/queries/model_weights/get_weight.rs b/crates/lib/mysql_queries/src/queries/model_weights/get_weight.rs index 71efd4fc0d..bca423808f 100644 --- a/crates/lib/mysql_queries/src/queries/model_weights/get_weight.rs +++ b/crates/lib/mysql_queries/src/queries/model_weights/get_weight.rs @@ -158,6 +158,7 @@ async fn select_include_deleted( wt.original_filename, wt.file_size_bytes, wt.file_checksum_sha2, + wt.public_bucket_hash, wt.maybe_public_bucket_prefix, wt.maybe_public_bucket_extension, diff --git a/crates/lib/mysql_queries/src/queries/model_weights/list/list_weights_by_tokens.rs b/crates/lib/mysql_queries/src/queries/model_weights/list/list_weights_by_tokens.rs index b1bb8fd980..086a8bdf9d 100644 --- a/crates/lib/mysql_queries/src/queries/model_weights/list/list_weights_by_tokens.rs +++ b/crates/lib/mysql_queries/src/queries/model_weights/list/list_weights_by_tokens.rs @@ -31,6 +31,10 @@ pub struct WeightsByTokensRecord { pub maybe_public_bucket_prefix: Option, pub maybe_public_bucket_extension: Option, + pub maybe_avatar_public_bucket_hash: Option, + pub maybe_avatar_public_bucket_prefix: Option, + pub maybe_avatar_public_bucket_extension: Option, + pub cached_user_ratings_total_count: u32, pub cached_user_ratings_positive_count: u32, pub cached_user_ratings_negative_count: u32, @@ -79,6 +83,9 @@ async fn get_raw_weights_by_tokens( mw.public_bucket_hash, mw.maybe_public_bucket_prefix, mw.maybe_public_bucket_extension, + avatar.public_bucket_directory_hash as maybe_avatar_public_bucket_hash, + avatar.maybe_public_bucket_prefix as maybe_avatar_public_bucket_prefix, + avatar.maybe_public_bucket_extension as maybe_avatar_public_bucket_extension, mw.cached_user_ratings_negative_count, mw.cached_user_ratings_positive_count, mw.cached_user_ratings_total_count, @@ -91,6 +98,8 @@ async fn get_raw_weights_by_tokens( FROM model_weights as mw JOIN users ON users.token = mw.creator_user_token + LEFT OUTER JOIN media_files as avatar + ON avatar.token = mw.maybe_avatar_media_file_token WHERE mw.creator_set_visibility = "public" AND mw.token IN ( @@ -112,6 +121,9 @@ async fn get_raw_weights_by_tokens( mw.public_bucket_hash, mw.maybe_public_bucket_prefix, mw.maybe_public_bucket_extension, + avatar.public_bucket_directory_hash as maybe_avatar_public_bucket_hash, + avatar.maybe_public_bucket_prefix as maybe_avatar_public_bucket_prefix, + avatar.maybe_public_bucket_extension as maybe_avatar_public_bucket_extension, mw.cached_user_ratings_negative_count, mw.cached_user_ratings_positive_count, mw.cached_user_ratings_total_count, @@ -124,6 +136,8 @@ async fn get_raw_weights_by_tokens( FROM model_weights as mw JOIN users ON users.token = mw.creator_user_token + LEFT OUTER JOIN media_files as avatar + ON avatar.token = mw.maybe_avatar_media_file_token WHERE mw.creator_set_visibility = "public" AND mw.user_deleted_at IS NULL @@ -157,34 +171,38 @@ fn token_predicate(tokens: &[ModelWeightToken]) -> String { fn map_to_weights(dataset:Vec) -> Vec { let weights: Vec = dataset .into_iter() - .map(|dataset: RawWeightJoinUser| { + .map(|weight| { WeightsByTokensRecord { - token: dataset.token, - title: dataset.title, - weights_type: dataset.weights_type, - weights_category: dataset.weights_category, - maybe_thumbnail_token: dataset.maybe_thumbnail_token, + token: weight.token, + title: weight.title, + weights_type: weight.weights_type, + weights_category: weight.weights_category, + maybe_thumbnail_token: weight.maybe_thumbnail_token, - creator_user_token: dataset.creator_user_token, - creator_username:dataset.creator_username, - creator_display_name:dataset.creator_display_name, - creator_email_gravatar_hash:dataset.creator_email_gravatar_hash, + creator_user_token: weight.creator_user_token, + creator_username: weight.creator_username, + creator_display_name: weight.creator_display_name, + creator_email_gravatar_hash: weight.creator_email_gravatar_hash, - public_bucket_hash: dataset.public_bucket_hash, - maybe_public_bucket_prefix: dataset.maybe_public_bucket_prefix, - maybe_public_bucket_extension: dataset.maybe_public_bucket_extension, + public_bucket_hash: weight.public_bucket_hash, + maybe_public_bucket_prefix: weight.maybe_public_bucket_prefix, + maybe_public_bucket_extension: weight.maybe_public_bucket_extension, - cached_user_ratings_negative_count: dataset.cached_user_ratings_negative_count, - cached_user_ratings_positive_count: dataset.cached_user_ratings_positive_count, - cached_user_ratings_total_count: dataset.cached_user_ratings_total_count, + maybe_avatar_public_bucket_hash: weight.maybe_avatar_public_bucket_hash, + maybe_avatar_public_bucket_prefix: weight.maybe_avatar_public_bucket_prefix, + maybe_avatar_public_bucket_extension: weight.maybe_avatar_public_bucket_extension, - maybe_cached_user_ratings_ratio: dataset.maybe_cached_user_ratings_ratio, - cached_user_ratings_last_updated_at: dataset.cached_user_ratings_last_updated_at, + cached_user_ratings_negative_count: weight.cached_user_ratings_negative_count, + cached_user_ratings_positive_count: weight.cached_user_ratings_positive_count, + cached_user_ratings_total_count: weight.cached_user_ratings_total_count, - created_at: dataset.created_at, - updated_at: dataset.updated_at, - user_deleted_at: dataset.user_deleted_at, - mod_deleted_at: dataset.mod_deleted_at, + maybe_cached_user_ratings_ratio: weight.maybe_cached_user_ratings_ratio, + cached_user_ratings_last_updated_at: weight.cached_user_ratings_last_updated_at, + + created_at: weight.created_at, + updated_at: weight.updated_at, + user_deleted_at: weight.user_deleted_at, + mod_deleted_at: weight.mod_deleted_at, } }).collect(); @@ -210,7 +228,11 @@ fn map_to_weights(dataset:Vec) -> Vec pub public_bucket_hash: String, pub maybe_public_bucket_prefix: Option, pub maybe_public_bucket_extension: Option, - + + pub maybe_avatar_public_bucket_hash: Option, + pub maybe_avatar_public_bucket_prefix: Option, + pub maybe_avatar_public_bucket_extension: Option, + pub cached_user_ratings_total_count: u32, pub cached_user_ratings_positive_count: u32, pub cached_user_ratings_negative_count: u32, @@ -250,6 +272,9 @@ impl FromRow<'_, MySqlRow> for RawWeightJoinUser { public_bucket_hash: row.try_get("public_bucket_hash")?, maybe_public_bucket_prefix: row.try_get("maybe_public_bucket_prefix")?, maybe_public_bucket_extension: row.try_get("maybe_public_bucket_extension")?, + maybe_avatar_public_bucket_hash: row.try_get("maybe_avatar_public_bucket_hash")?, + maybe_avatar_public_bucket_prefix: row.try_get("maybe_avatar_public_bucket_prefix")?, + maybe_avatar_public_bucket_extension: row.try_get("maybe_avatar_public_bucket_extension")?, cached_user_ratings_total_count: row.try_get("cached_user_ratings_total_count")?, cached_user_ratings_positive_count: row.try_get("cached_user_ratings_positive_count")?, cached_user_ratings_negative_count: row.try_get("cached_user_ratings_negative_count")?, diff --git a/crates/lib/mysql_queries/src/queries/model_weights/list/list_weights_by_user.rs b/crates/lib/mysql_queries/src/queries/model_weights/list/list_weights_by_user.rs index 014548007a..403a26e04f 100644 --- a/crates/lib/mysql_queries/src/queries/model_weights/list/list_weights_by_user.rs +++ b/crates/lib/mysql_queries/src/queries/model_weights/list/list_weights_by_user.rs @@ -51,6 +51,10 @@ pub struct WeightsJoinUserRecord { pub public_bucket_hash: String, pub maybe_public_bucket_prefix: Option, pub maybe_public_bucket_extension: Option, + + pub maybe_avatar_public_bucket_hash: Option, + pub maybe_avatar_public_bucket_prefix: Option, + pub maybe_avatar_public_bucket_extension: Option, pub cached_user_ratings_total_count: u32, pub cached_user_ratings_positive_count: u32, @@ -134,38 +138,44 @@ fn select_total_count_field() -> String { fn select_result_fields() -> String { r#" - mw.token, - mw.title, - mw.weights_type, - mw.weights_category, - mw.maybe_thumbnail_token, - mw.description_markdown, - mw.description_rendered_html, - u.token as creator_user_token, - u.username as creator_username, - u.display_name as creator_display_name, - u.email_gravatar_hash as creator_email_gravatar_hash, - mw.creator_ip_address, - mw.creator_set_visibility, - mw.maybe_last_update_user_token, - mw.original_download_url, - mw.original_filename, - mw.file_size_bytes, - mw.file_checksum_sha2, - mw.public_bucket_hash, - mw.maybe_public_bucket_prefix, - mw.maybe_public_bucket_extension, - mw.cached_user_ratings_negative_count, - mw.cached_user_ratings_positive_count, - mw.cached_user_ratings_total_count, - mw.maybe_cached_user_ratings_ratio, - mw.cached_user_ratings_last_updated_at, - mw.version, - mw.created_at, - mw.updated_at, - mw.user_deleted_at, - mw.mod_deleted_at - "#.to_string() + mw.token, + mw.title, + mw.weights_type, + mw.weights_category, + mw.maybe_thumbnail_token, + mw.description_markdown, + mw.description_rendered_html, + u.token as creator_user_token, + u.username as creator_username, + u.display_name as creator_display_name, + u.email_gravatar_hash as creator_email_gravatar_hash, + mw.creator_ip_address, + mw.creator_set_visibility, + mw.maybe_last_update_user_token, + mw.original_download_url, + mw.original_filename, + mw.file_size_bytes, + mw.file_checksum_sha2, + + mw.public_bucket_hash, + mw.maybe_public_bucket_prefix, + mw.maybe_public_bucket_extension, + + avatar.public_bucket_directory_hash as maybe_avatar_public_bucket_hash, + avatar.maybe_public_bucket_prefix as maybe_avatar_public_bucket_prefix, + avatar.maybe_public_bucket_extension as maybe_avatar_public_bucket_extension, + + mw.cached_user_ratings_negative_count, + mw.cached_user_ratings_positive_count, + mw.cached_user_ratings_total_count, + mw.maybe_cached_user_ratings_ratio, + mw.cached_user_ratings_last_updated_at, + mw.version, + mw.created_at, + mw.updated_at, + mw.user_deleted_at, + mw.mod_deleted_at + "#.to_string() } fn query_builder<'a>( @@ -186,6 +196,8 @@ SELECT FROM model_weights as mw JOIN users as u ON u.token = mw.creator_user_token +LEFT OUTER JOIN media_files as avatar + ON avatar.token = mw.maybe_avatar_media_file_token "# )); @@ -215,44 +227,48 @@ JOIN users as u async fn map_to_weights(dataset:Vec) -> Vec { let weights: Vec = dataset .into_iter() - .map(|dataset: RawWeightJoinUser| { + .map(|weight: RawWeightJoinUser| { WeightsJoinUserRecord { - token: dataset.token, - title: dataset.title, - weights_type: dataset.weights_type, - weights_category: dataset.weights_category, - maybe_thumbnail_token: dataset.maybe_thumbnail_token, - description_markdown: dataset.description_markdown, - description_rendered_html: dataset.description_rendered_html, + token: weight.token, + title: weight.title, + weights_type: weight.weights_type, + weights_category: weight.weights_category, + maybe_thumbnail_token: weight.maybe_thumbnail_token, + description_markdown: weight.description_markdown, + description_rendered_html: weight.description_rendered_html, - creator_user_token: dataset.creator_user_token, - creator_ip_address: dataset.creator_ip_address, - creator_set_visibility: dataset.creator_set_visibility, + creator_user_token: weight.creator_user_token, + creator_ip_address: weight.creator_ip_address, + creator_set_visibility: weight.creator_set_visibility, - maybe_last_update_user_token: dataset.maybe_last_update_user_token, - original_download_url: dataset.original_download_url, - original_filename: dataset.original_filename, - file_size_bytes: dataset.file_size_bytes, - file_checksum_sha2: dataset.file_checksum_sha2, - public_bucket_hash: dataset.public_bucket_hash, - maybe_public_bucket_prefix: dataset.maybe_public_bucket_prefix, - maybe_public_bucket_extension: dataset.maybe_public_bucket_extension, + maybe_last_update_user_token: weight.maybe_last_update_user_token, + original_download_url: weight.original_download_url, + original_filename: weight.original_filename, + file_size_bytes: weight.file_size_bytes, + file_checksum_sha2: weight.file_checksum_sha2, + public_bucket_hash: weight.public_bucket_hash, + maybe_public_bucket_prefix: weight.maybe_public_bucket_prefix, + maybe_public_bucket_extension: weight.maybe_public_bucket_extension, - cached_user_ratings_negative_count: dataset.cached_user_ratings_negative_count, - cached_user_ratings_positive_count: dataset.cached_user_ratings_positive_count, - cached_user_ratings_total_count: dataset.cached_user_ratings_total_count, + maybe_avatar_public_bucket_hash: weight.maybe_avatar_public_bucket_hash, + maybe_avatar_public_bucket_prefix: weight.maybe_avatar_public_bucket_prefix, + maybe_avatar_public_bucket_extension: weight.maybe_avatar_public_bucket_extension, - maybe_cached_user_ratings_ratio: dataset.maybe_cached_user_ratings_ratio, - cached_user_ratings_last_updated_at: dataset.cached_user_ratings_last_updated_at, - version: dataset.version, - created_at: dataset.created_at, - updated_at: dataset.updated_at, - user_deleted_at: dataset.user_deleted_at, - mod_deleted_at: dataset.mod_deleted_at, + cached_user_ratings_negative_count: weight.cached_user_ratings_negative_count, + cached_user_ratings_positive_count: weight.cached_user_ratings_positive_count, + cached_user_ratings_total_count: weight.cached_user_ratings_total_count, - creator_username:dataset.creator_username, - creator_display_name:dataset.creator_display_name, - creator_email_gravatar_hash:dataset.creator_email_gravatar_hash + maybe_cached_user_ratings_ratio: weight.maybe_cached_user_ratings_ratio, + cached_user_ratings_last_updated_at: weight.cached_user_ratings_last_updated_at, + version: weight.version, + created_at: weight.created_at, + updated_at: weight.updated_at, + user_deleted_at: weight.user_deleted_at, + mod_deleted_at: weight.mod_deleted_at, + + creator_username: weight.creator_username, + creator_display_name: weight.creator_display_name, + creator_email_gravatar_hash: weight.creator_email_gravatar_hash, } }).collect(); @@ -288,7 +304,11 @@ async fn map_to_weights(dataset:Vec) -> Vec, pub maybe_public_bucket_extension: Option, - + + pub maybe_avatar_public_bucket_hash: Option, + pub maybe_avatar_public_bucket_prefix: Option, + pub maybe_avatar_public_bucket_extension: Option, + pub cached_user_ratings_total_count: u32, pub cached_user_ratings_positive_count: u32, pub cached_user_ratings_negative_count: u32, @@ -309,7 +329,7 @@ async fn map_to_weights(dataset:Vec) -> Vec for RawWeightJoinUser { - fn from_row(row: &MySqlRow) -> std::result::Result { + fn from_row(row: &MySqlRow) -> Result { Ok(Self { token: row.try_get("token")?, weights_type: row.try_get("weights_type")?, @@ -329,6 +349,9 @@ impl FromRow<'_, MySqlRow> for RawWeightJoinUser { public_bucket_hash: row.try_get("public_bucket_hash")?, maybe_public_bucket_prefix: row.try_get("maybe_public_bucket_prefix")?, maybe_public_bucket_extension: row.try_get("maybe_public_bucket_extension")?, + maybe_avatar_public_bucket_hash: row.try_get("maybe_avatar_public_bucket_hash")?, + maybe_avatar_public_bucket_prefix: row.try_get("maybe_avatar_public_bucket_prefix")?, + maybe_avatar_public_bucket_extension: row.try_get("maybe_avatar_public_bucket_extension")?, cached_user_ratings_total_count: row.try_get("cached_user_ratings_total_count")?, cached_user_ratings_positive_count: row.try_get("cached_user_ratings_positive_count")?, cached_user_ratings_negative_count: row.try_get("cached_user_ratings_negative_count")?, diff --git a/crates/lib/mysql_queries/src/queries/model_weights/list/list_weights_query_builder.rs b/crates/lib/mysql_queries/src/queries/model_weights/list/list_weights_query_builder.rs index 270501e94d..9d7ccec4e6 100644 --- a/crates/lib/mysql_queries/src/queries/model_weights/list/list_weights_query_builder.rs +++ b/crates/lib/mysql_queries/src/queries/model_weights/list/list_weights_query_builder.rs @@ -57,6 +57,10 @@ pub struct WeightJoinUser { pub maybe_public_bucket_prefix: Option, pub maybe_public_bucket_extension: Option, + pub maybe_avatar_public_bucket_hash: Option, + pub maybe_avatar_public_bucket_prefix: Option, + pub maybe_avatar_public_bucket_extension: Option, + pub cached_user_ratings_total_count: u32, pub cached_user_ratings_positive_count: u32, pub cached_user_ratings_negative_count: u32, @@ -234,6 +238,9 @@ impl ListWeightsQueryBuilder { public_bucket_hash: record.public_bucket_hash, maybe_public_bucket_prefix: record.maybe_public_bucket_prefix, maybe_public_bucket_extension: record.maybe_public_bucket_extension, + maybe_avatar_public_bucket_hash: record.maybe_avatar_public_bucket_hash, + maybe_avatar_public_bucket_prefix: record.maybe_avatar_public_bucket_prefix, + maybe_avatar_public_bucket_extension: record.maybe_avatar_public_bucket_extension, cached_user_ratings_total_count: record.cached_user_ratings_total_count, cached_user_ratings_positive_count: record.cached_user_ratings_positive_count, cached_user_ratings_negative_count: record.cached_user_ratings_negative_count, @@ -282,6 +289,9 @@ impl ListWeightsQueryBuilder { model_weights.public_bucket_hash, model_weights.maybe_public_bucket_prefix, model_weights.maybe_public_bucket_extension, + avatar.public_bucket_directory_hash as maybe_avatar_public_bucket_hash, + avatar.maybe_public_bucket_prefix as maybe_avatar_public_bucket_prefix, + avatar.maybe_public_bucket_extension as maybe_avatar_public_bucket_extension, model_weights.cached_user_ratings_total_count, model_weights.cached_user_ratings_positive_count, model_weights.cached_user_ratings_negative_count, @@ -298,6 +308,8 @@ impl ListWeightsQueryBuilder { FROM model_weights JOIN users ON users.token = model_weights.creator_user_token + LEFT OUTER JOIN media_files as avatar + ON avatar.token = model_weights.maybe_avatar_media_file_token "#.to_string(); query.push_str(&self.build_predicates()); @@ -443,6 +455,10 @@ struct RawWeightJoinUser { pub maybe_public_bucket_prefix: Option, pub maybe_public_bucket_extension: Option, + pub maybe_avatar_public_bucket_hash: Option, + pub maybe_avatar_public_bucket_prefix: Option, + pub maybe_avatar_public_bucket_extension: Option, + pub cached_user_ratings_total_count: u32, pub cached_user_ratings_positive_count: u32, pub cached_user_ratings_negative_count: u32, diff --git a/crates/service/web/storyteller_web/src/http_server/endpoints/weights/get_weight.rs b/crates/service/web/storyteller_web/src/http_server/endpoints/weights/get_weight.rs index 66980cbc0c..407bf7da95 100644 --- a/crates/service/web/storyteller_web/src/http_server/endpoints/weights/get_weight.rs +++ b/crates/service/web/storyteller_web/src/http_server/endpoints/weights/get_weight.rs @@ -36,6 +36,7 @@ pub struct GetWeightResponse { file_size_bytes: i32, file_checksum_sha2: String, + /// Avatars are small descriptive images that can be set for any model. /// If an avatar is set, this is the path to the asset. maybe_avatar_public_bucket_path: Option, @@ -148,8 +149,8 @@ pub async fn get_weight_handler( .map(|hash| { MediaFileBucketPath::from_object_hash( hash, - weight.maybe_public_bucket_prefix.as_deref(), - weight.maybe_public_bucket_extension.as_deref()) + weight.maybe_avatar_public_bucket_prefix.as_deref(), + weight.maybe_avatar_public_bucket_extension.as_deref()) .get_full_object_path_str() .to_string() }); diff --git a/crates/service/web/storyteller_web/src/http_server/endpoints/weights/list_available_weights.rs b/crates/service/web/storyteller_web/src/http_server/endpoints/weights/list_available_weights.rs index 31ca53bb86..f9bdfd6d5e 100644 --- a/crates/service/web/storyteller_web/src/http_server/endpoints/weights/list_available_weights.rs +++ b/crates/service/web/storyteller_web/src/http_server/endpoints/weights/list_available_weights.rs @@ -7,6 +7,7 @@ use chrono::{DateTime, Utc}; use log::{info, warn}; use rand::Rng; use utoipa::ToSchema; +use buckets::public::media_files::bucket_file_path::MediaFileBucketPath; use enums::by_table::model_weights::{ weights_category::WeightsCategory, @@ -16,6 +17,7 @@ use enums::common::visibility::Visibility; use mysql_queries::queries::model_weights::list::list_weights_query_builder::ListWeightsQueryBuilder; use tokens::tokens::model_weights::ModelWeightToken; use tokens::tokens::users::UserToken; +use crate::http_server::common_responses::user_details_lite::UserDetailsLight; use crate::server_state::ServerState; @@ -48,12 +50,14 @@ pub struct ModelWeightForList { pub title: String, - pub maybe_thumbnail_token: Option, - pub description_markdown: String, pub description_rendered_html: String, - pub creator_user_token: UserToken, + /// Avatars are small descriptive images that can be set for any model. + /// If an avatar is set, this is the path to the asset. + pub maybe_avatar_public_bucket_path: Option, + + pub creator: UserDetailsLight, pub creator_set_visibility: Visibility, pub file_size_bytes: i32, @@ -64,8 +68,6 @@ pub struct ModelWeightForList { pub cached_user_ratings_negative_count: u32, pub maybe_cached_user_ratings_ratio: Option, - pub version: i32, - pub created_at: DateTime, pub updated_at: DateTime, @@ -222,39 +224,56 @@ pub async fn list_available_weights_handler( let response = ListAvailableWeightsSuccessResponse { success: true, weights: weights_page.weights.into_iter() - .map(|weights| ModelWeightForList { - weight_token: weights.token, - title: weights.title, - weights_type: weights.weights_type, - weights_category: weights.weights_category, + .map(|weight| { - maybe_thumbnail_token:weights.maybe_thumbnail_token, - description_markdown: weights.description_markdown, - description_rendered_html: weights.description_rendered_html, + let maybe_avatar = weight.maybe_avatar_public_bucket_hash + .as_deref() + .map(|hash| { + MediaFileBucketPath::from_object_hash( + hash, + weight.maybe_avatar_public_bucket_prefix.as_deref(), + weight.maybe_avatar_public_bucket_extension.as_deref()) + .get_full_object_path_str() + .to_string() + }); - creator_user_token: weights.creator_user_token, - creator_set_visibility: weights.creator_set_visibility, + ModelWeightForList { + weight_token: weight.token, + title: weight.title, + weights_type: weight.weights_type, + weights_category: weight.weights_category, - file_size_bytes:weights.file_size_bytes, - file_checksum_sha2: weights.file_checksum_sha2, + description_markdown: weight.description_markdown, + description_rendered_html: weight.description_rendered_html, + maybe_avatar_public_bucket_path: maybe_avatar, - cached_user_ratings_total_count: weights.cached_user_ratings_total_count, - cached_user_ratings_positive_count: weights.cached_user_ratings_positive_count, - cached_user_ratings_negative_count: weights.cached_user_ratings_negative_count, - maybe_cached_user_ratings_ratio: weights.maybe_cached_user_ratings_ratio, + creator: UserDetailsLight::from_db_fields( + &weight.creator_user_token, + &weight.creator_username, + &weight.creator_display_name, + &weight.creator_email_gravatar_hash + ), + creator_set_visibility: weight.creator_set_visibility, - version: weights.version, + file_size_bytes: weight.file_size_bytes, + file_checksum_sha2: weight.file_checksum_sha2, - created_at: weights.created_at, - updated_at: weights.updated_at, + cached_user_ratings_total_count: weight.cached_user_ratings_total_count, + cached_user_ratings_positive_count: weight.cached_user_ratings_positive_count, + cached_user_ratings_negative_count: weight.cached_user_ratings_negative_count, + maybe_cached_user_ratings_ratio: weight.maybe_cached_user_ratings_ratio, - creator_username: weights.creator_username, - creator_display_name: weights.creator_display_name, - creator_email_gravatar_hash: weights.creator_email_gravatar_hash, + created_at: weight.created_at, + updated_at: weight.updated_at, - // TODO: FIX THIS when we align again. - bookmarks: random_bool, - likes: rng.gen_range(0..1000), + creator_username: weight.creator_username, + creator_display_name: weight.creator_display_name, + creator_email_gravatar_hash: weight.creator_email_gravatar_hash, + + // TODO: FIX THIS when we align again. + bookmarks: random_bool, + likes: rng.gen_range(0..1000), + } }).collect::>(), cursor_next, cursor_previous, diff --git a/crates/service/web/storyteller_web/src/http_server/endpoints/weights/list_featured_weights.rs b/crates/service/web/storyteller_web/src/http_server/endpoints/weights/list_featured_weights.rs index e761e3a448..b087100b26 100644 --- a/crates/service/web/storyteller_web/src/http_server/endpoints/weights/list_featured_weights.rs +++ b/crates/service/web/storyteller_web/src/http_server/endpoints/weights/list_featured_weights.rs @@ -7,6 +7,7 @@ use chrono::{DateTime, Utc}; use log::{debug, error, warn}; use r2d2_redis::redis::Commands; use utoipa::ToSchema; +use buckets::public::media_files::bucket_file_path::MediaFileBucketPath; use enums::by_table::model_weights::{ weights_category::WeightsCategory, @@ -33,10 +34,12 @@ pub struct ModelWeightForList { pub title: String, - pub maybe_thumbnail_token: Option, - pub creator: UserDetailsLight, + /// Avatars are small descriptive images that can be set for any model. + /// If an avatar is set, this is the path to the asset. + pub maybe_avatar_public_bucket_path: Option, + pub cached_user_ratings_total_count: u32, pub cached_user_ratings_positive_count: u32, pub cached_user_ratings_negative_count: u32, @@ -125,24 +128,38 @@ pub async fn list_featured_weights_handler( let response = ListFeaturedWeightsSuccessResponse { success: true, weights: weights.into_iter() - .map(|w| ModelWeightForList { - weight_token: w.token, - title: w.title, - weights_type: w.weights_type, - weights_category: w.weights_category, - maybe_thumbnail_token: w.maybe_thumbnail_token, - creator: UserDetailsLight::from_db_fields( - &w.creator_user_token, - &w.creator_username, - &w.creator_display_name, - &w.creator_email_gravatar_hash - ), - cached_user_ratings_total_count: w.cached_user_ratings_total_count, - cached_user_ratings_positive_count: w.cached_user_ratings_positive_count, - cached_user_ratings_negative_count: w.cached_user_ratings_negative_count, - maybe_cached_user_ratings_ratio: w.maybe_cached_user_ratings_ratio, - created_at: w.created_at, - updated_at: w.updated_at, + .map(|w| { + + let maybe_avatar = w.maybe_avatar_public_bucket_hash + .as_deref() + .map(|hash| { + MediaFileBucketPath::from_object_hash( + hash, + w.maybe_avatar_public_bucket_prefix.as_deref(), + w.maybe_avatar_public_bucket_extension.as_deref()) + .get_full_object_path_str() + .to_string() + }); + + ModelWeightForList { + weight_token: w.token, + title: w.title, + weights_type: w.weights_type, + weights_category: w.weights_category, + maybe_avatar_public_bucket_path: maybe_avatar, + creator: UserDetailsLight::from_db_fields( + &w.creator_user_token, + &w.creator_username, + &w.creator_display_name, + &w.creator_email_gravatar_hash + ), + cached_user_ratings_total_count: w.cached_user_ratings_total_count, + cached_user_ratings_positive_count: w.cached_user_ratings_positive_count, + cached_user_ratings_negative_count: w.cached_user_ratings_negative_count, + maybe_cached_user_ratings_ratio: w.maybe_cached_user_ratings_ratio, + created_at: w.created_at, + updated_at: w.updated_at, + } }).collect::>(), }; diff --git a/crates/service/web/storyteller_web/src/http_server/endpoints/weights/list_weights_by_user.rs b/crates/service/web/storyteller_web/src/http_server/endpoints/weights/list_weights_by_user.rs index e93c50d50e..12d0f5a2a6 100644 --- a/crates/service/web/storyteller_web/src/http_server/endpoints/weights/list_weights_by_user.rs +++ b/crates/service/web/storyteller_web/src/http_server/endpoints/weights/list_weights_by_user.rs @@ -8,6 +8,7 @@ use actix_web::web::{Path, Query}; use chrono::{DateTime, Utc}; use log::warn; use utoipa::{IntoParams, ToSchema}; +use buckets::public::media_files::bucket_file_path::MediaFileBucketPath; use enums::common::visibility::Visibility; use mysql_queries::queries::model_weights::list::list_weights_by_user::{list_weights_by_creator_username, ListWeightsForUserArgs}; @@ -25,16 +26,20 @@ pub struct Weight { creator: UserDetailsLight, creator_set_visibility: Visibility, - maybe_thumbnail_token: Option, - description_markdown: String, description_rendered_html: String, file_size_bytes: i32, file_checksum_sha2: String, + + /// Avatars are small descriptive images that can be set for any model. + /// If an avatar is set, this is the path to the asset. + maybe_avatar_public_bucket_path: Option, + cached_user_ratings_total_count: u32, cached_user_ratings_positive_count: u32, cached_user_ratings_negative_count: u32, + maybe_cached_user_ratings_ratio: Option, cached_user_ratings_last_updated_at: DateTime, @@ -150,6 +155,18 @@ pub async fn list_weights_by_user_handler( }; let weights:Vec = results_page.records.into_iter().map(|weight| { + + let maybe_avatar = weight.maybe_avatar_public_bucket_hash + .as_deref() + .map(|hash| { + MediaFileBucketPath::from_object_hash( + hash, + weight.maybe_avatar_public_bucket_prefix.as_deref(), + weight.maybe_avatar_public_bucket_extension.as_deref()) + .get_full_object_path_str() + .to_string() + }); + Weight { weight_token: weight.token, title: weight.title, @@ -159,7 +176,7 @@ pub async fn list_weights_by_user_handler( &weight.creator_display_name, &weight.creator_email_gravatar_hash, ), - maybe_thumbnail_token: weight.maybe_thumbnail_token, + maybe_avatar_public_bucket_path: maybe_avatar, description_markdown: weight.description_markdown, description_rendered_html: weight.description_rendered_html, file_size_bytes: weight.file_size_bytes,