mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-16 06:42:14 +00:00
cover image details for media files
This commit is contained in:
1 parent
53f02cd820
commit
d397311957
10 files changed
+79
-49
No files matched your search
@@ -27,6 +27,7 @@ use users_component::endpoints::login_handler::*;
|
||||
use users_component::endpoints::logout_handler::*;
|
||||
use users_component::endpoints::session_info_handler::*;
|
||||
|
||||
use crate::http_server::common_responses::media_file_default_cover::MediaFileCoverImageDetails;
|
||||
use crate::http_server::common_responses::media_file_default_cover::MediaFileDefaultCover;
|
||||
use crate::http_server::common_responses::media_file_origin_details::*;
|
||||
use crate::http_server::common_responses::media_file_social_meta_lite::MediaFileSocialMetaLight;
|
||||
@@ -161,6 +162,7 @@ use crate::http_server::web_utils::response_success_helpers::*;
|
||||
Visibility,
|
||||
|
||||
// Common cover image types
|
||||
MediaFileCoverImageDetails,
|
||||
MediaFileDefaultCover,
|
||||
UserDefaultAvatarInfo,
|
||||
WeightsCoverImageDetails,
|
||||
|
||||
@@ -18,22 +18,14 @@
|
||||
#[macro_use] extern crate magic_crypt;
|
||||
#[macro_use] extern crate serde_derive;
|
||||
|
||||
use std::error::Error;
|
||||
|
||||
use actix_web::{App, HttpServer};
|
||||
use r2d2_redis::redis::Commands;
|
||||
use utoipa::OpenApi;
|
||||
use utoipa_swagger_ui::SwaggerUi;
|
||||
|
||||
use actix_web::{App, HttpServer, middleware, web};
|
||||
use actix_web::middleware::{DefaultHeaders, Logger};
|
||||
|
||||
use r2d2_redis::r2d2;
|
||||
use r2d2_redis::redis::Commands;
|
||||
use r2d2_redis::RedisConnectionManager;
|
||||
use sqlx::mysql::MySqlPoolOptions;
|
||||
use sqlx::MySqlPool;
|
||||
use tokio::runtime::Runtime;
|
||||
|
||||
use errors::AnyhowResult;
|
||||
|
||||
use crate::configs::static_api_tokens::{StaticApiTokenConfig, StaticApiTokens, StaticApiTokenSet};
|
||||
use crate::server_state::{DurableInMemoryCaches, EnvConfig, EphemeralInMemoryCaches, InMemoryCaches, RedisRateLimiters, ServerInfo, ServerState, StaticFeatureFlags, StripeSettings, TrollBans, TwitchOauth, TwitchOauthSecrets};
|
||||
use api_doc::ApiDoc;
|
||||
|
||||
pub mod billing;
|
||||
pub mod configs;
|
||||
@@ -48,17 +40,8 @@ pub mod threads;
|
||||
pub mod util;
|
||||
pub mod validations;
|
||||
|
||||
use std::{
|
||||
error::Error,
|
||||
future::{self, Ready},
|
||||
net::Ipv4Addr,
|
||||
};
|
||||
|
||||
pub mod api_doc;
|
||||
use api_doc::ApiDoc;
|
||||
|
||||
use futures::future::LocalBoxFuture;
|
||||
use utoipa::OpenApi;
|
||||
#[actix_web::main]
|
||||
async fn main() -> Result<(), impl Error> {
|
||||
HttpServer::new(move || {
|
||||
|
||||
+33
@@ -3,6 +3,7 @@ use std::hash::{DefaultHasher, Hash, Hasher};
|
||||
use utoipa::ToSchema;
|
||||
|
||||
use tokens::tokens::media_files::MediaFileToken;
|
||||
use crate::http_server::common_responses::weights_cover_image_details::WeightsDefaultCoverInfo;
|
||||
|
||||
/// There are currently 25 cover images numbered 0 to 24 (0-indexed).
|
||||
/// The original dataset was numbered 1 - 25, but I renamed 25 to 0.
|
||||
@@ -12,12 +13,44 @@ const NUMBER_OF_IMAGES_SALT_OFFSET : u8 = 5;
|
||||
const NUMBER_OF_COLORS : u64 = 8;
|
||||
const NUMBER_OF_COLORS_SALT_OFFSET : u8 = 1;
|
||||
|
||||
|
||||
/// Everything we need to create a cover image.
|
||||
/// Cover images are small descriptive images that can be set for any media file.
|
||||
/// If a cover image is set, this is the path to the asset.
|
||||
#[derive(Clone, Serialize, ToSchema)]
|
||||
pub struct MediaFileCoverImageDetails {
|
||||
// TODO(bt,2024-04-07): Add column to schema to support + CRUD to add.
|
||||
/// If a cover image is set, this is the path to the asset.
|
||||
pub maybe_cover_image_public_bucket_path: Option<String>,
|
||||
|
||||
/// For items without a cover image, we can use one of our own.
|
||||
pub default_cover: MediaFileDefaultCover,
|
||||
}
|
||||
|
||||
/// The default cover is composed of an image and color pair that are
|
||||
/// predefined by the frontend.
|
||||
#[derive(Clone, Serialize,ToSchema)]
|
||||
pub struct MediaFileDefaultCover {
|
||||
pub image_index: u8,
|
||||
pub color_index: u8,
|
||||
}
|
||||
|
||||
impl MediaFileCoverImageDetails {
|
||||
/// Typical constructor
|
||||
pub fn from_token(token: &MediaFileToken) -> Self {
|
||||
Self::from_token_str(token.as_str())
|
||||
}
|
||||
|
||||
/// For non-media file tokens (eg. emulated TTS results)
|
||||
pub fn from_token_str(token: &str) -> Self {
|
||||
Self {
|
||||
// TODO(bt,2024-04-07): Add column to schema to support + CRUD to add.
|
||||
maybe_cover_image_public_bucket_path: None,
|
||||
default_cover: MediaFileDefaultCover::from_token_str(token),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MediaFileDefaultCover {
|
||||
/// Typical constructor
|
||||
pub fn from_token(token: &MediaFileToken) -> Self {
|
||||
|
||||
+6
-4
@@ -27,7 +27,7 @@ use tokens::tokens::model_weights::ModelWeightToken;
|
||||
use tokens::tokens::prompts::PromptToken;
|
||||
use users_component::common_responses::user_details_lite::UserDetailsLight;
|
||||
|
||||
use crate::http_server::common_responses::media_file_default_cover::MediaFileDefaultCover;
|
||||
use crate::http_server::common_responses::media_file_default_cover::{MediaFileCoverImageDetails, MediaFileDefaultCover};
|
||||
use crate::http_server::common_responses::simple_entity_stats::SimpleEntityStats;
|
||||
use crate::http_server::web_utils::response_error_helpers::to_simple_json_error;
|
||||
use crate::server_state::ServerState;
|
||||
@@ -79,8 +79,10 @@ pub struct BatchMediaFileInfo {
|
||||
/// URL to the media file
|
||||
pub public_bucket_path: String,
|
||||
|
||||
// Default cover image if there is nothing else we can use as a cover and thumbnail.
|
||||
pub default_cover: MediaFileDefaultCover,
|
||||
/// Information about the cover image. Many media files do not require a cover image,
|
||||
/// e.g. image files, video files with thumbnails, audio files, etc.
|
||||
/// 3D files require them.
|
||||
pub cover_image: MediaFileCoverImageDetails,
|
||||
|
||||
//// Provenance Data
|
||||
//pub origin_product: MediaFileOriginProductCategory,
|
||||
@@ -282,7 +284,7 @@ pub async fn batch_get_media_files_handler(
|
||||
maybe_engine_extension,
|
||||
maybe_batch_token: result.maybe_batch_token,
|
||||
public_bucket_path,
|
||||
default_cover: MediaFileDefaultCover::from_token(&result.token),
|
||||
cover_image: MediaFileCoverImageDetails::from_token(&result.token),
|
||||
maybe_title: result.maybe_title,
|
||||
maybe_text_transcript: result.maybe_text_transcript,
|
||||
maybe_model_weight_info: match result.maybe_model_weights_token {
|
||||
|
||||
+7
-5
@@ -24,7 +24,7 @@ use tokens::tokens::model_weights::ModelWeightToken;
|
||||
use tokens::tokens::prompts::PromptToken;
|
||||
use users_component::common_responses::user_details_lite::UserDetailsLight;
|
||||
|
||||
use crate::http_server::common_responses::media_file_default_cover::MediaFileDefaultCover;
|
||||
use crate::http_server::common_responses::media_file_default_cover::{MediaFileCoverImageDetails, MediaFileDefaultCover};
|
||||
use crate::http_server::common_responses::simple_entity_stats::SimpleEntityStats;
|
||||
use crate::http_server::web_utils::response_error_helpers::to_simple_json_error;
|
||||
use crate::server_state::ServerState;
|
||||
@@ -65,8 +65,10 @@ pub struct MediaFileInfo {
|
||||
/// URL to the media file
|
||||
pub public_bucket_path: String,
|
||||
|
||||
// Default cover image if there is nothing else we can use as a cover and thumbnail.
|
||||
pub default_cover: MediaFileDefaultCover,
|
||||
/// Information about the cover image. Many media files do not require a cover image,
|
||||
/// e.g. image files, video files with thumbnails, audio files, etc.
|
||||
/// 3D files require them.
|
||||
pub cover_image: MediaFileCoverImageDetails,
|
||||
|
||||
//// Provenance Data
|
||||
//pub origin_product: MediaFileOriginProductCategory,
|
||||
@@ -298,7 +300,7 @@ async fn modern_media_file_lookup(
|
||||
maybe_engine_extension,
|
||||
maybe_batch_token: result.maybe_batch_token,
|
||||
public_bucket_path,
|
||||
default_cover: MediaFileDefaultCover::from_token(&result.token),
|
||||
cover_image: MediaFileCoverImageDetails::from_token(&result.token),
|
||||
maybe_title: result.maybe_title,
|
||||
maybe_text_transcript: result.maybe_text_transcript,
|
||||
maybe_model_weight_info: match result.maybe_model_weights_token {
|
||||
@@ -390,7 +392,7 @@ async fn emulate_media_file_with_legacy_tts_result_lookup(
|
||||
maybe_engine_extension: None,
|
||||
maybe_batch_token: None,
|
||||
public_bucket_path,
|
||||
default_cover: MediaFileDefaultCover::from_token_str(&result.tts_result_token),
|
||||
cover_image: MediaFileCoverImageDetails::from_token_str(&result.tts_result_token),
|
||||
maybe_model_weight_info: Some(GetMediaFileModelInfo {
|
||||
// NB: These should be reasonable synthetic defaults for emulated TT2 results, even the "ModelWeightToken".
|
||||
weight_token: ModelWeightToken::new_from_str(&result.tts_model_token),
|
||||
|
||||
+6
-4
@@ -17,7 +17,7 @@ use mysql_queries::queries::media_files::list::list_media_files_by_tokens::list_
|
||||
use tokens::tokens::media_files::MediaFileToken;
|
||||
use users_component::common_responses::user_details_lite::UserDetailsLight;
|
||||
|
||||
use crate::http_server::common_responses::media_file_default_cover::MediaFileDefaultCover;
|
||||
use crate::http_server::common_responses::media_file_default_cover::{MediaFileCoverImageDetails, MediaFileDefaultCover};
|
||||
use crate::http_server::common_responses::media_file_origin_details::MediaFileOriginDetails;
|
||||
use crate::http_server::common_responses::simple_entity_stats::SimpleEntityStats;
|
||||
use crate::server_state::ServerState;
|
||||
@@ -39,8 +39,10 @@ pub struct MediaFile {
|
||||
/// URL to the media file
|
||||
pub public_bucket_path: String,
|
||||
|
||||
// Default cover image if there is nothing else we can use as a cover and thumbnail.
|
||||
pub default_cover: MediaFileDefaultCover,
|
||||
/// Information about the cover image. Many media files do not require a cover image,
|
||||
/// e.g. image files, video files with thumbnails, audio files, etc.
|
||||
/// 3D files require them.
|
||||
pub cover_image: MediaFileCoverImageDetails,
|
||||
|
||||
#[deprecated(note="Use MediaFileOriginDetails instead")]
|
||||
pub origin_category: MediaFileOriginCategory,
|
||||
@@ -164,7 +166,7 @@ pub async fn list_featured_media_files_handler(
|
||||
token: m.token.clone(),
|
||||
media_type: m.media_type,
|
||||
public_bucket_path,
|
||||
default_cover: MediaFileDefaultCover::from_token(&m.token),
|
||||
cover_image: MediaFileCoverImageDetails::from_token(&m.token),
|
||||
origin: MediaFileOriginDetails::from_db_fields_str(
|
||||
m.origin_category,
|
||||
m.origin_product_category,
|
||||
|
||||
+6
-4
@@ -19,7 +19,7 @@ use mysql_queries::queries::media_files::list::list_media_files::{list_media_fil
|
||||
use tokens::tokens::media_files::MediaFileToken;
|
||||
use users_component::common_responses::user_details_lite::UserDetailsLight;
|
||||
|
||||
use crate::http_server::common_responses::media_file_default_cover::MediaFileDefaultCover;
|
||||
use crate::http_server::common_responses::media_file_default_cover::{MediaFileCoverImageDetails, MediaFileDefaultCover};
|
||||
use crate::http_server::common_responses::media_file_origin_details::MediaFileOriginDetails;
|
||||
use crate::http_server::common_responses::pagination_cursors::PaginationCursors;
|
||||
use crate::http_server::common_responses::simple_entity_stats::SimpleEntityStats;
|
||||
@@ -68,8 +68,10 @@ pub struct MediaFileListItem {
|
||||
/// URL to the media file.
|
||||
pub public_bucket_path: String,
|
||||
|
||||
// Default cover image if there is nothing else we can use as a cover and thumbnail.
|
||||
pub default_cover: MediaFileDefaultCover,
|
||||
/// Information about the cover image. Many media files do not require a cover image,
|
||||
/// e.g. image files, video files with thumbnails, audio files, etc.
|
||||
/// 3D files require them.
|
||||
pub cover_image: MediaFileCoverImageDetails,
|
||||
|
||||
pub maybe_creator: Option<UserDetailsLight>,
|
||||
|
||||
@@ -243,7 +245,7 @@ pub async fn list_media_files_handler(
|
||||
record.maybe_public_bucket_extension.as_deref())
|
||||
.get_full_object_path_str()
|
||||
.to_string(),
|
||||
default_cover: MediaFileDefaultCover::from_token(&record.token),
|
||||
cover_image: MediaFileCoverImageDetails::from_token(&record.token),
|
||||
maybe_creator: UserDetailsLight::from_optional_db_fields_owned(
|
||||
record.maybe_creator_user_token,
|
||||
record.maybe_creator_username,
|
||||
|
||||
+6
-4
@@ -20,7 +20,7 @@ use mysql_queries::queries::media_files::list::list_media_files_for_user::{list_
|
||||
use tokens::tokens::batch_generations::BatchGenerationToken;
|
||||
use tokens::tokens::media_files::MediaFileToken;
|
||||
|
||||
use crate::http_server::common_responses::media_file_default_cover::MediaFileDefaultCover;
|
||||
use crate::http_server::common_responses::media_file_default_cover::{MediaFileCoverImageDetails, MediaFileDefaultCover};
|
||||
use crate::http_server::common_responses::media_file_origin_details::MediaFileOriginDetails;
|
||||
use crate::http_server::common_responses::pagination_page::PaginationPage;
|
||||
use crate::http_server::common_responses::simple_entity_stats::SimpleEntityStats;
|
||||
@@ -72,8 +72,10 @@ pub struct MediaFilesByBatchListItem {
|
||||
/// URL to the media file.
|
||||
pub public_bucket_path: String,
|
||||
|
||||
// Default cover image if there is nothing else we can use as a cover and thumbnail.
|
||||
pub default_cover: MediaFileDefaultCover,
|
||||
/// Information about the cover image. Many media files do not require a cover image,
|
||||
/// e.g. image files, video files with thumbnails, audio files, etc.
|
||||
/// 3D files require them.
|
||||
pub cover_image: MediaFileCoverImageDetails,
|
||||
|
||||
pub creator_set_visibility: Visibility,
|
||||
|
||||
@@ -218,7 +220,7 @@ pub async fn list_media_files_by_batch_token_handler(
|
||||
record.maybe_public_bucket_extension.as_deref())
|
||||
.get_full_object_path_str()
|
||||
.to_string(),
|
||||
default_cover: MediaFileDefaultCover::from_token(&record.token),
|
||||
cover_image: MediaFileCoverImageDetails::from_token(&record.token),
|
||||
creator_set_visibility: record.creator_set_visibility,
|
||||
maybe_title: record.maybe_title,
|
||||
maybe_text_transcript: record.maybe_text_transcript,
|
||||
|
||||
+6
-4
@@ -20,7 +20,7 @@ use enums::common::visibility::Visibility;
|
||||
use mysql_queries::queries::media_files::list::list_media_files_for_user::{list_media_files_for_user, ListMediaFileForUserArgs};
|
||||
use tokens::tokens::media_files::MediaFileToken;
|
||||
|
||||
use crate::http_server::common_responses::media_file_default_cover::MediaFileDefaultCover;
|
||||
use crate::http_server::common_responses::media_file_default_cover::{MediaFileCoverImageDetails, MediaFileDefaultCover};
|
||||
use crate::http_server::common_responses::media_file_origin_details::MediaFileOriginDetails;
|
||||
use crate::http_server::common_responses::pagination_page::PaginationPage;
|
||||
use crate::http_server::common_responses::simple_entity_stats::SimpleEntityStats;
|
||||
@@ -82,8 +82,10 @@ pub struct MediaFileForUserListItem {
|
||||
/// URL to the media file.
|
||||
pub public_bucket_path: String,
|
||||
|
||||
// Default cover image if there is nothing else we can use as a cover and thumbnail.
|
||||
pub default_cover: MediaFileDefaultCover,
|
||||
/// Information about the cover image. Many media files do not require a cover image,
|
||||
/// e.g. image files, video files with thumbnails, audio files, etc.
|
||||
/// 3D files require them.
|
||||
pub cover_image: MediaFileCoverImageDetails,
|
||||
|
||||
pub creator_set_visibility: Visibility,
|
||||
|
||||
@@ -253,7 +255,7 @@ pub async fn list_media_files_for_user_handler(
|
||||
record.maybe_public_bucket_extension.as_deref())
|
||||
.get_full_object_path_str()
|
||||
.to_string(),
|
||||
default_cover: MediaFileDefaultCover::from_token(&record.token),
|
||||
cover_image: MediaFileCoverImageDetails::from_token(&record.token),
|
||||
creator_set_visibility: record.creator_set_visibility,
|
||||
maybe_title: record.maybe_title,
|
||||
maybe_text_transcript: record.maybe_text_transcript,
|
||||
|
||||
+1
-1
@@ -18,9 +18,9 @@ use mysql_queries::queries::model_weights::list::list_weights_by_user::{list_wei
|
||||
use tokens::tokens::model_weights::ModelWeightToken;
|
||||
use users_component::common_responses::user_details_lite::UserDetailsLight;
|
||||
|
||||
use crate::http_server::common_responses::weights_cover_image_details::WeightsCoverImageDetails;
|
||||
use crate::http_server::common_responses::pagination_page::PaginationPage;
|
||||
use crate::http_server::common_responses::simple_entity_stats::SimpleEntityStats;
|
||||
use crate::http_server::common_responses::weights_cover_image_details::WeightsCoverImageDetails;
|
||||
use crate::server_state::ServerState;
|
||||
|
||||
#[derive(Serialize, Clone, ToSchema)]
|
||||
|
||||
Reference in new issue
Block a user