add media_links to cover images

This commit is contained in:
Brandon Thomas committed 2024-09-05 20:55:32 -04:00
1 parent 382a2105cf
commit 6e1a597fd4
9 files changed
+26 -4

No files matched your search

@@ -5,6 +5,7 @@ use utoipa::ToSchema;
use buckets::public::media_files::bucket_file_path::MediaFileBucketPath;
use tokens::tokens::media_files::MediaFileToken;
use crate::http_server::common_responses::media_links::{MediaDomain, MediaLinks};
use crate::http_server::web_utils::bucket_urls::bucket_url_from_media_path::bucket_url_from_media_path;
/// There are currently 25 cover images numbered 0 to 24 (0-indexed).
@@ -21,14 +22,19 @@ const NUMBER_OF_COLORS_SALT_OFFSET : u8 = 1;
/// 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.
#[deprecated(note="This field doesn't point to the full URL. Use maybe_cover_image_public_bucket_url instead.")]
/// (DEPRECATED) URL path to the media file
#[deprecated(note="This field doesn't point to the full URL. Use media_links instead to leverage the CDN.")]
pub maybe_cover_image_public_bucket_path: Option<String>,
/// If a cover image is set, this is the URL to the asset.
/// (DEPRECATED) Full URL to the media file
#[deprecated(note="This points to the bucket. Use media_links instead to leverage the CDN.")]
pub maybe_cover_image_public_bucket_url: Option<Url>,
/// If a cover image is set, this is the path to the asset.
/// If a cover image is not set, use the information in `default_cover` instead.
/// Rich CDN links to the media, including thumbnails, previews, and more.
pub maybe_media_links: Option<MediaLinks>,
/// For items without a cover image, we can use one of our own.
pub default_cover: MediaFileDefaultCover,
}
@@ -53,18 +59,21 @@ impl MediaFileCoverImageDetails {
// TODO(bt,2024-04-07): Add column to schema to support + CRUD to add.
maybe_cover_image_public_bucket_path: None,
maybe_cover_image_public_bucket_url: None,
maybe_media_links: None,
default_cover: MediaFileDefaultCover::from_token_str(token),
}
}
pub fn from_optional_db_fields(
token: &MediaFileToken,
domain: MediaDomain,
maybe_cover_image_public_bucket_path: Option<&str>,
maybe_cover_image_public_bucket_prefix: Option<&str>,
maybe_cover_image_public_bucket_extension: Option<&str>,
) -> Self {
Self::from_optional_db_str_fields(
token.as_str(),
domain,
maybe_cover_image_public_bucket_path,
maybe_cover_image_public_bucket_prefix,
maybe_cover_image_public_bucket_extension
@@ -73,6 +82,7 @@ impl MediaFileCoverImageDetails {
pub fn from_optional_db_str_fields(
token: &str,
domain: MediaDomain,
maybe_cover_image_public_bucket_path: Option<&str>,
maybe_cover_image_public_bucket_prefix: Option<&str>,
maybe_cover_image_public_bucket_extension: Option<&str>,
@@ -96,9 +106,13 @@ impl MediaFileCoverImageDetails {
.map(|bucket_path| bucket_url_from_media_path(bucket_path).ok())
.flatten();
let maybe_media_links = maybe_bucket_path
.map(|path| MediaLinks::from_media_path(domain, &path));
Self {
maybe_cover_image_public_bucket_path,
maybe_cover_image_public_bucket_url,
maybe_media_links,
default_cover: MediaFileDefaultCover::from_token_str(token),
}
}
@@ -345,6 +345,7 @@ pub async fn batch_get_media_files_handler(
public_bucket_url: bucket_url_string_from_media_path(&public_bucket_path),
cover_image: MediaFileCoverImageDetails::from_optional_db_fields(
&result.token,
media_domain,
result.maybe_file_cover_image_public_bucket_hash.as_deref(),
result.maybe_file_cover_image_public_bucket_prefix.as_deref(),
result.maybe_file_cover_image_public_bucket_extension.as_deref(),
@@ -376,6 +376,7 @@ async fn modern_media_file_lookup(
.to_string(),
cover_image: MediaFileCoverImageDetails::from_optional_db_fields(
&result.token,
media_domain,
result.maybe_file_cover_image_public_bucket_hash.as_deref(),
result.maybe_file_cover_image_public_bucket_prefix.as_deref(),
result.maybe_file_cover_image_public_bucket_extension.as_deref(),
@@ -286,6 +286,7 @@ pub async fn list_featured_media_files_handler(
public_bucket_url: bucket_url_string_from_media_path(&public_bucket_path),
cover_image: MediaFileCoverImageDetails::from_optional_db_fields(
&m.token,
media_domain,
m.maybe_file_cover_image_public_bucket_hash.as_deref(),
m.maybe_file_cover_image_public_bucket_prefix.as_deref(),
m.maybe_file_cover_image_public_bucket_extension.as_deref(),
@@ -347,6 +347,7 @@ pub async fn list_media_files_for_user_handler(
public_bucket_url: bucket_url_string_from_media_path(&public_bucket_path),
cover_image: MediaFileCoverImageDetails::from_optional_db_fields(
&record.token,
media_domain,
record.maybe_file_cover_image_public_bucket_hash.as_deref(),
record.maybe_file_cover_image_public_bucket_prefix.as_deref(),
record.maybe_file_cover_image_public_bucket_extension.as_deref(),
@@ -353,6 +353,7 @@ pub async fn list_media_files_handler(
public_bucket_url: bucket_url_string_from_media_path(&public_bucket_path),
cover_image: MediaFileCoverImageDetails::from_optional_db_fields(
&record.token,
media_domain,
record.maybe_file_cover_image_public_bucket_hash.as_deref(),
record.maybe_file_cover_image_public_bucket_prefix.as_deref(),
record.maybe_file_cover_image_public_bucket_extension.as_deref(),
@@ -222,6 +222,7 @@ pub async fn list_pinned_media_files_handler(
public_bucket_url: bucket_url_string_from_media_path(&public_bucket_path),
cover_image: MediaFileCoverImageDetails::from_optional_db_fields(
&m.token,
media_domain,
m.maybe_file_cover_image_public_bucket_hash.as_deref(),
m.maybe_file_cover_image_public_bucket_prefix.as_deref(),
m.maybe_file_cover_image_public_bucket_extension.as_deref(),
@@ -240,6 +240,7 @@ pub async fn search_featured_media_files_handler(
public_bucket_url: bucket_url_string_from_media_path(&public_bucket_path),
cover_image: MediaFileCoverImageDetails::from_optional_db_fields(
&result.token,
media_domain,
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(),
@@ -270,6 +270,7 @@ pub async fn search_session_media_files_handler(
public_bucket_url: bucket_url_string_from_media_path(&public_bucket_path),
cover_image: MediaFileCoverImageDetails::from_optional_db_fields(
&result.token,
media_domain,
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(),