cover image details on all informational weight endpoints

This commit is contained in:
Brandon Thomas committed 2024-01-11 23:32:52 -05:00
1 parent f251e8b88a
commit c01ffe33a5
4 files changed
+52 -1

No files matched your search

@@ -15,6 +15,7 @@ use enums::by_table::model_weights::weights_types::WeightsType;
use enums::common::visibility::Visibility;
use mysql_queries::queries::model_weights::get_weight::get_weight_by_token;
use tokens::tokens::model_weights::ModelWeightToken;
use crate::http_server::common_responses::cover_image_details::CoverImageDetails;
use crate::http_server::common_responses::simple_entity_stats::SimpleEntityStats;
use crate::http_server::common_responses::user_details_lite::UserDetailsLight;
@@ -40,8 +41,12 @@ pub struct GetWeightResponse {
file_size_bytes: i32,
file_checksum_sha2: String,
/// Information about the cover image.
pub cover_image: CoverImageDetails,
/// Cover images are small descriptive images that can be set for any model.
/// If a cover image is set, this is the path to the asset.
#[deprecated(note="switch to CoverImageDetails")]
maybe_cover_image_public_bucket_path: Option<String>,
/// Statistics about the weights
@@ -149,6 +154,13 @@ pub async fn get_weight_handler(
}
}
let cover_image_details = CoverImageDetails::from_optional_db_fields(
&weight.token,
weight.maybe_cover_image_public_bucket_hash.as_deref(),
weight.maybe_cover_image_public_bucket_prefix.as_deref(),
weight.maybe_cover_image_public_bucket_extension.as_deref(),
);
let maybe_cover_image = weight.maybe_cover_image_public_bucket_hash
.as_deref()
.map(|hash| {
@@ -176,6 +188,7 @@ pub async fn get_weight_handler(
// TODO(bt,2023-12-24): Migrated the column. We should return nullable fields, but I don't want to break the frontend
description_markdown: weight.maybe_description_markdown.unwrap_or_else(|| "".to_string()),
description_rendered_html: weight.maybe_description_rendered_html.unwrap_or_else(|| "".to_string()),
cover_image: cover_image_details,
maybe_cover_image_public_bucket_path: maybe_cover_image,
creator,
creator_set_visibility: weight.creator_set_visibility,
@@ -15,6 +15,7 @@ use enums::by_table::model_weights::{
};
use mysql_queries::queries::model_weights::list::list_weights_by_tokens::list_weights_by_tokens;
use tokens::tokens::model_weights::ModelWeightToken;
use crate::http_server::common_responses::cover_image_details::CoverImageDetails;
use crate::http_server::common_responses::simple_entity_stats::SimpleEntityStats;
use crate::http_server::common_responses::user_details_lite::UserDetailsLight;
@@ -37,8 +38,12 @@ pub struct ModelWeightForList {
pub creator: UserDetailsLight,
/// Information about the cover image.
pub cover_image: CoverImageDetails,
/// Cover images are small descriptive images that can be set for any model.
/// If a cover image is set, this is the path to the asset.
#[deprecated(note="switch to CoverImageDetails")]
pub maybe_cover_image_public_bucket_path: Option<String>,
/// Statistics about the weights
@@ -128,6 +133,12 @@ pub async fn list_featured_weights_handler(
success: true,
results: weights.into_iter()
.map(|w| {
let cover_image_details = CoverImageDetails::from_optional_db_fields(
&w.token,
w.maybe_cover_image_public_bucket_hash.as_deref(),
w.maybe_cover_image_public_bucket_prefix.as_deref(),
w.maybe_cover_image_public_bucket_extension.as_deref(),
);
let maybe_cover_image = w.maybe_cover_image_public_bucket_hash
.as_deref()
@@ -145,6 +156,7 @@ pub async fn list_featured_weights_handler(
title: w.title,
weight_type: w.weights_type,
weight_category: w.weights_category,
cover_image: cover_image_details,
maybe_cover_image_public_bucket_path: maybe_cover_image,
creator: UserDetailsLight::from_db_fields(
&w.creator_user_token,
@@ -16,6 +16,7 @@ use enums::common::view_as::ViewAs;
use enums::common::visibility::Visibility;
use mysql_queries::queries::model_weights::list::list_weights_by_user::{list_weights_by_creator_username, ListWeightsForUserArgs};
use tokens::tokens::model_weights::ModelWeightToken;
use crate::http_server::common_responses::cover_image_details::CoverImageDetails;
use crate::http_server::common_responses::pagination_page::PaginationPage;
use crate::http_server::common_responses::simple_entity_stats::SimpleEntityStats;
@@ -39,8 +40,12 @@ pub struct Weight {
file_size_bytes: i32,
file_checksum_sha2: String,
/// Information about the cover image.
pub cover_image: CoverImageDetails,
/// Cover images are small descriptive images that can be set for any model.
/// If a cover image is set, this is the path to the asset.
#[deprecated(note="switch to CoverImageDetails")]
maybe_cover_image_public_bucket_path: Option<String>,
/// Statistics about the weights
@@ -179,7 +184,14 @@ pub async fn list_weights_by_user_handler(
}
};
let weights:Vec<Weight> = results_page.records.into_iter().map(|weight| {
let weights: Vec<Weight> = results_page.records.into_iter().map(|weight| {
let cover_image_details = CoverImageDetails::from_optional_db_fields(
&weight.token,
weight.maybe_cover_image_public_bucket_hash.as_deref(),
weight.maybe_cover_image_public_bucket_prefix.as_deref(),
weight.maybe_cover_image_public_bucket_extension.as_deref(),
);
let maybe_cover_image = weight.maybe_cover_image_public_bucket_hash
.as_deref()
@@ -203,6 +215,7 @@ pub async fn list_weights_by_user_handler(
&weight.creator_display_name,
&weight.creator_email_gravatar_hash,
),
cover_image: cover_image_details,
maybe_cover_image_public_bucket_path: maybe_cover_image,
file_size_bytes: weight.file_size_bytes,
file_checksum_sha2: weight.file_checksum_sha2,
@@ -20,6 +20,7 @@ use enums::by_table::model_weights::weights_category::WeightsCategory;
use enums::by_table::model_weights::weights_types::WeightsType;
use enums::common::visibility::Visibility;
use tokens::tokens::model_weights::ModelWeightToken;
use crate::http_server::common_responses::cover_image_details::CoverImageDetails;
use crate::http_server::common_responses::simple_entity_stats::SimpleEntityStats;
use crate::http_server::common_responses::user_details_lite::UserDetailsLight;
@@ -44,6 +45,10 @@ pub struct ModelWeightSearchResult {
pub creator: UserDetailsLight,
/// Information about the cover image.
pub cover_image: CoverImageDetails,
#[deprecated(note="switch to CoverImageDetails")]
pub maybe_cover_image_public_bucket_path: Option<String>,
pub stats: SimpleEntityStats,
@@ -117,6 +122,13 @@ pub async fn search_model_weights_handler(
let results = results.into_iter()
.map(|result| {
let cover_image_details = CoverImageDetails::from_optional_db_fields(
&result.token,
result.maybe_cover_image_public_bucket_hash.as_deref(),
result.maybe_cover_image_public_bucket_prefix.as_deref(),
result.maybe_cover_image_public_bucket_extension.as_deref(),
);
let maybe_cover_image = result.maybe_cover_image_public_bucket_hash
.as_deref()
.map(|hash| {
@@ -139,6 +151,7 @@ pub async fn search_model_weights_handler(
&result.creator_display_name,
&result.creator_gravatar_hash,
),
cover_image: cover_image_details,
maybe_cover_image_public_bucket_path: maybe_cover_image,
stats: SimpleEntityStats {
positive_rating_count: result.ratings_positive_count,