mirror of
https://github.com/storytold/artcraft.git
synced 2026-10-25 11:19:29 -04:00
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
37873971d0 | ||
|
|
3c78006bda | ||
|
|
afbbff3119 | ||
|
|
b9d78b7bcc | ||
|
|
b17df6fc0b |
+21
-8
@@ -1,5 +1,7 @@
|
||||
use crate::http_server::common_responses::media::cdn_link;
|
||||
use crate::http_server::common_responses::media::media_domain::MediaDomain;
|
||||
use bucket_paths::legacy::typified_paths::public::media_files::bucket_file_path::MediaFileBucketPath;
|
||||
use server_environment::ServerEnvironment;
|
||||
use url::Url;
|
||||
use utoipa::ToSchema;
|
||||
|
||||
@@ -24,24 +26,27 @@ impl CoverImageLinks {
|
||||
|
||||
pub fn from_media_path(
|
||||
domain: MediaDomain,
|
||||
server_environment: ServerEnvironment,
|
||||
bucket_path: &MediaFileBucketPath,
|
||||
) -> Option<Self> {
|
||||
let rooted_path = bucket_path.get_full_object_path_str();
|
||||
Self::from_rooted_path(domain, rooted_path)
|
||||
Self::from_rooted_path(domain, server_environment, rooted_path)
|
||||
}
|
||||
|
||||
pub fn from_maybe_media_path(
|
||||
domain: MediaDomain,
|
||||
server_environment: ServerEnvironment,
|
||||
bucket_path: Option<&MediaFileBucketPath>,
|
||||
) -> Option<Self> {
|
||||
match bucket_path {
|
||||
None => None,
|
||||
Some(bucket_path) => Self::from_media_path(domain, bucket_path),
|
||||
Some(bucket_path) => Self::from_media_path(domain, server_environment, bucket_path),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_parts(
|
||||
domain: MediaDomain,
|
||||
server_environment: ServerEnvironment,
|
||||
maybe_cover_image_public_bucket_path: Option<&str>,
|
||||
maybe_cover_image_public_bucket_prefix: Option<&str>,
|
||||
maybe_cover_image_public_bucket_extension: Option<&str>,
|
||||
@@ -55,11 +60,12 @@ impl CoverImageLinks {
|
||||
maybe_cover_image_public_bucket_prefix,
|
||||
maybe_cover_image_public_bucket_extension
|
||||
);
|
||||
Self::from_media_path(domain, &bucket_path)
|
||||
Self::from_media_path(domain, server_environment, &bucket_path)
|
||||
}
|
||||
|
||||
pub fn from_rooted_path(
|
||||
domain: MediaDomain,
|
||||
server_environment: ServerEnvironment,
|
||||
rooted_path: &str,
|
||||
) -> Option<Self> {
|
||||
if !rooted_path.ends_with(".jpg")
|
||||
@@ -68,17 +74,24 @@ impl CoverImageLinks {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut cdn_url = domain.new_cdn_url();
|
||||
let mut cdn_url = cdn_link::new_cdn_url(domain, server_environment);
|
||||
cdn_url.set_path(rooted_path);
|
||||
|
||||
Some(Self {
|
||||
cdn_url,
|
||||
thumbnail_template: thumbnail_template(domain, rooted_path),
|
||||
thumbnail_template: thumbnail_template(domain, server_environment, rooted_path),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn thumbnail_template(media_domain: MediaDomain, rooted_path: &str) -> String {
|
||||
let host = media_domain.cdn_url_str();
|
||||
format!("{host}/cdn-cgi/image/width={{WIDTH}},quality={QUALITY}{rooted_path}")
|
||||
fn thumbnail_template(media_domain: MediaDomain, server_environment: ServerEnvironment, rooted_path: &str) -> String {
|
||||
let host = cdn_link::get_cdn_host(media_domain, server_environment);
|
||||
match server_environment {
|
||||
ServerEnvironment::Production => {
|
||||
format!("{host}/cdn-cgi/image/width={{WIDTH}},quality={QUALITY}{rooted_path}")
|
||||
}
|
||||
ServerEnvironment::Development => {
|
||||
format!("{host}{rooted_path}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+21
-8
@@ -1,6 +1,8 @@
|
||||
use crate::http_server::common_responses::media::cdn_link;
|
||||
use crate::http_server::common_responses::media::media_domain::MediaDomain;
|
||||
use artcraft_api_defs::common::responses::cover_image_links::CoverImageLinks;
|
||||
use bucket_paths::legacy::typified_paths::public::media_files::bucket_file_path::MediaFileBucketPath;
|
||||
use server_environment::ServerEnvironment;
|
||||
|
||||
// TODO(bt,2024-09-18): Consolidate thumbnail builder code and vars
|
||||
// TODO(bt,2024-09-05): Worth reducing the quality at all?
|
||||
@@ -12,24 +14,27 @@ impl CoverImageLinksBuilder {
|
||||
|
||||
pub fn from_media_path(
|
||||
domain: MediaDomain,
|
||||
server_environment: ServerEnvironment,
|
||||
bucket_path: &MediaFileBucketPath,
|
||||
) -> Option<CoverImageLinks> {
|
||||
let rooted_path = bucket_path.get_full_object_path_str();
|
||||
Self::from_rooted_path(domain, rooted_path)
|
||||
Self::from_rooted_path(domain, server_environment, rooted_path)
|
||||
}
|
||||
|
||||
pub fn from_maybe_media_path(
|
||||
domain: MediaDomain,
|
||||
server_environment: ServerEnvironment,
|
||||
bucket_path: Option<&MediaFileBucketPath>,
|
||||
) -> Option<CoverImageLinks> {
|
||||
match bucket_path {
|
||||
None => None,
|
||||
Some(bucket_path) => Self::from_media_path(domain, bucket_path),
|
||||
Some(bucket_path) => Self::from_media_path(domain, server_environment, bucket_path),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_parts(
|
||||
domain: MediaDomain,
|
||||
server_environment: ServerEnvironment,
|
||||
maybe_cover_image_public_bucket_path: Option<&str>,
|
||||
maybe_cover_image_public_bucket_prefix: Option<&str>,
|
||||
maybe_cover_image_public_bucket_extension: Option<&str>,
|
||||
@@ -43,11 +48,12 @@ impl CoverImageLinksBuilder {
|
||||
maybe_cover_image_public_bucket_prefix,
|
||||
maybe_cover_image_public_bucket_extension
|
||||
);
|
||||
Self::from_media_path(domain, &bucket_path)
|
||||
Self::from_media_path(domain, server_environment, &bucket_path)
|
||||
}
|
||||
|
||||
pub fn from_rooted_path(
|
||||
domain: MediaDomain,
|
||||
server_environment: ServerEnvironment,
|
||||
rooted_path: &str,
|
||||
) -> Option<CoverImageLinks> {
|
||||
if !rooted_path.ends_with(".jpg")
|
||||
@@ -56,17 +62,24 @@ impl CoverImageLinksBuilder {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut cdn_url = domain.new_cdn_url();
|
||||
let mut cdn_url = cdn_link::new_cdn_url(domain, server_environment);
|
||||
cdn_url.set_path(rooted_path);
|
||||
|
||||
Some(CoverImageLinks {
|
||||
cdn_url,
|
||||
thumbnail_template: thumbnail_template(domain, rooted_path),
|
||||
thumbnail_template: thumbnail_template(domain, server_environment, rooted_path),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn thumbnail_template(media_domain: MediaDomain, rooted_path: &str) -> String {
|
||||
let host = media_domain.cdn_url_str();
|
||||
format!("{host}/cdn-cgi/image/width={{WIDTH}},quality={QUALITY}{rooted_path}")
|
||||
fn thumbnail_template(media_domain: MediaDomain, server_environment: ServerEnvironment, rooted_path: &str) -> String {
|
||||
let host = cdn_link::get_cdn_host(media_domain, server_environment);
|
||||
match server_environment {
|
||||
ServerEnvironment::Production => {
|
||||
format!("{host}/cdn-cgi/image/width={{WIDTH}},quality={QUALITY}{rooted_path}")
|
||||
}
|
||||
ServerEnvironment::Development => {
|
||||
format!("{host}{rooted_path}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+156
-10
@@ -3,10 +3,11 @@ use std::hash::{Hash, Hasher};
|
||||
use url::Url;
|
||||
use utoipa::ToSchema;
|
||||
|
||||
use crate::http_server::common_responses::media::cdn_link;
|
||||
use crate::http_server::common_responses::media::cover_image_links::CoverImageLinks;
|
||||
use crate::http_server::common_responses::media::media_domain::MediaDomain;
|
||||
use crate::http_server::web_utils::bucket_urls::bucket_url_from_media_path::bucket_url_from_media_path;
|
||||
use bucket_paths::legacy::typified_paths::public::media_files::bucket_file_path::MediaFileBucketPath;
|
||||
use server_environment::ServerEnvironment;
|
||||
use tokens::tokens::media_files::MediaFileToken;
|
||||
|
||||
/// There are currently 25 cover images numbered 0 to 24 (0-indexed).
|
||||
@@ -62,7 +63,11 @@ impl MediaFileCoverImageDetails {
|
||||
}
|
||||
|
||||
/// For non-media file tokens (eg. emulated TTS results)
|
||||
pub fn from_token_str(token: &str) -> Self {
|
||||
pub fn from_legacy_token_str(token: &str) -> Self {
|
||||
Self::from_token_str(token)
|
||||
}
|
||||
|
||||
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,
|
||||
@@ -76,6 +81,7 @@ impl MediaFileCoverImageDetails {
|
||||
pub fn from_optional_db_fields(
|
||||
token: &MediaFileToken,
|
||||
domain: MediaDomain,
|
||||
server_environment: ServerEnvironment,
|
||||
maybe_cover_image_public_bucket_path: Option<&str>,
|
||||
maybe_cover_image_public_bucket_prefix: Option<&str>,
|
||||
maybe_cover_image_public_bucket_extension: Option<&str>,
|
||||
@@ -83,15 +89,17 @@ impl MediaFileCoverImageDetails {
|
||||
Self::from_optional_db_str_fields(
|
||||
token.as_str(),
|
||||
domain,
|
||||
server_environment,
|
||||
maybe_cover_image_public_bucket_path,
|
||||
maybe_cover_image_public_bucket_prefix,
|
||||
maybe_cover_image_public_bucket_extension
|
||||
)
|
||||
}
|
||||
|
||||
pub fn from_optional_db_str_fields(
|
||||
fn from_optional_db_str_fields(
|
||||
token: &str,
|
||||
domain: MediaDomain,
|
||||
server_environment: ServerEnvironment,
|
||||
maybe_cover_image_public_bucket_path: Option<&str>,
|
||||
maybe_cover_image_public_bucket_prefix: Option<&str>,
|
||||
maybe_cover_image_public_bucket_extension: Option<&str>,
|
||||
@@ -112,19 +120,19 @@ impl MediaFileCoverImageDetails {
|
||||
// NB: Fail construction open.
|
||||
let maybe_cover_image_public_bucket_url = maybe_bucket_path
|
||||
.as_ref()
|
||||
.map(|bucket_path| bucket_url_from_media_path(bucket_path).ok())
|
||||
.flatten();
|
||||
.and_then(|bucket_path| {
|
||||
let rooted_path = bucket_path.get_full_object_path_str();
|
||||
let mut url = cdn_link::new_cdn_url(domain, server_environment);
|
||||
url.set_path(rooted_path);
|
||||
Some(url)
|
||||
});
|
||||
|
||||
let maybe_links = CoverImageLinks::from_maybe_media_path(
|
||||
domain, maybe_bucket_path.as_ref());
|
||||
|
||||
// let maybe_media_links = maybe_bucket_path
|
||||
// .map(|path| MediaLinks::from_media_path(domain, &path));
|
||||
domain, server_environment, maybe_bucket_path.as_ref());
|
||||
|
||||
Self {
|
||||
maybe_cover_image_public_bucket_path,
|
||||
maybe_cover_image_public_bucket_url,
|
||||
//maybe_media_links,
|
||||
maybe_links,
|
||||
default_cover: MediaFileDefaultCover::from_token_str(token),
|
||||
}
|
||||
@@ -181,4 +189,142 @@ mod tests {
|
||||
assert_eq!(cover.color_index, 0);
|
||||
assert_eq!(cover.image_index, 23);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cover_image_url_production() {
|
||||
let token = MediaFileToken::new_from_str("test_token");
|
||||
let domain = super::MediaDomain::FakeYou;
|
||||
let env = super::ServerEnvironment::Production;
|
||||
|
||||
let details = super::MediaFileCoverImageDetails::from_optional_db_fields(
|
||||
&token,
|
||||
domain,
|
||||
env,
|
||||
Some("bucket_hash"),
|
||||
Some("image_"),
|
||||
Some(".png"),
|
||||
);
|
||||
|
||||
let url = details.maybe_cover_image_public_bucket_url.unwrap();
|
||||
assert!(
|
||||
url.as_str().starts_with("https://cdn-2.fakeyou.com"),
|
||||
"Production URL should start with https://cdn-2.fakeyou.com, got: {}",
|
||||
url
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cover_image_url_development() {
|
||||
let token = MediaFileToken::new_from_str("test_token");
|
||||
let domain = super::MediaDomain::FakeYou;
|
||||
let env = super::ServerEnvironment::Development;
|
||||
|
||||
let details = super::MediaFileCoverImageDetails::from_optional_db_fields(
|
||||
&token,
|
||||
domain,
|
||||
env,
|
||||
Some("bucket_hash"),
|
||||
Some("image_"),
|
||||
Some(".png"),
|
||||
);
|
||||
|
||||
let url = details.maybe_cover_image_public_bucket_url.unwrap();
|
||||
assert!(
|
||||
url.as_str().starts_with("https://pub-c8a4a5bdbdb048f286b77bdf9f786ff2.r2.dev/"),
|
||||
"Development URL should start with https://pub-c8a4a5bdbdb048f286b77bdf9f786ff2.r2.dev/, got: {}",
|
||||
url
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cover_image_links_cdn_url_production() {
|
||||
let token = MediaFileToken::new_from_str("test_token");
|
||||
let domain = super::MediaDomain::FakeYou;
|
||||
let env = super::ServerEnvironment::Production;
|
||||
|
||||
let details = super::MediaFileCoverImageDetails::from_optional_db_fields(
|
||||
&token,
|
||||
domain,
|
||||
env,
|
||||
Some("bucket_hash"),
|
||||
Some("image_"),
|
||||
Some(".png"),
|
||||
);
|
||||
|
||||
let links = details.maybe_links.unwrap();
|
||||
assert!(
|
||||
links.cdn_url.as_str().starts_with("https://cdn-2.fakeyou.com"),
|
||||
"Production cdn_url should start with https://cdn-2.fakeyou.com, got: {}",
|
||||
links.cdn_url
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cover_image_links_cdn_url_development() {
|
||||
let token = MediaFileToken::new_from_str("test_token");
|
||||
let domain = super::MediaDomain::FakeYou;
|
||||
let env = super::ServerEnvironment::Development;
|
||||
|
||||
let details = super::MediaFileCoverImageDetails::from_optional_db_fields(
|
||||
&token,
|
||||
domain,
|
||||
env,
|
||||
Some("bucket_hash"),
|
||||
Some("image_"),
|
||||
Some(".png"),
|
||||
);
|
||||
|
||||
let links = details.maybe_links.unwrap();
|
||||
assert!(
|
||||
links.cdn_url.as_str().starts_with("https://pub-c8a4a5bdbdb048f286b77bdf9f786ff2.r2.dev/"),
|
||||
"Development cdn_url should start with https://pub-c8a4a5bdbdb048f286b77bdf9f786ff2.r2.dev/, got: {}",
|
||||
links.cdn_url
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cover_image_links_thumbnail_template_production() {
|
||||
let token = MediaFileToken::new_from_str("test_token");
|
||||
let domain = super::MediaDomain::FakeYou;
|
||||
let env = super::ServerEnvironment::Production;
|
||||
|
||||
let details = super::MediaFileCoverImageDetails::from_optional_db_fields(
|
||||
&token,
|
||||
domain,
|
||||
env,
|
||||
Some("bucket_hash"),
|
||||
Some("image_"),
|
||||
Some(".png"),
|
||||
);
|
||||
|
||||
let links = details.maybe_links.unwrap();
|
||||
assert!(
|
||||
links.thumbnail_template.starts_with("https://cdn-2.fakeyou.com"),
|
||||
"Production thumbnail_template should start with https://cdn-2.fakeyou.com, got: {}",
|
||||
links.thumbnail_template
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cover_image_links_thumbnail_template_development() {
|
||||
let token = MediaFileToken::new_from_str("test_token");
|
||||
let domain = super::MediaDomain::FakeYou;
|
||||
let env = super::ServerEnvironment::Development;
|
||||
|
||||
let details = super::MediaFileCoverImageDetails::from_optional_db_fields(
|
||||
&token,
|
||||
domain,
|
||||
env,
|
||||
Some("bucket_hash"),
|
||||
Some("image_"),
|
||||
Some(".png"),
|
||||
);
|
||||
|
||||
let links = details.maybe_links.unwrap();
|
||||
assert!(
|
||||
links.thumbnail_template.starts_with("https://pub-c8a4a5bdbdb048f286b77bdf9f786ff2.r2.dev/"),
|
||||
"Development thumbnail_template should start with https://pub-c8a4a5bdbdb048f286b77bdf9f786ff2.r2.dev/, got: {}",
|
||||
links.thumbnail_template
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+5
-21
@@ -1,8 +1,8 @@
|
||||
use crate::http_server::common_responses::media::cover_image_links_builder::CoverImageLinksBuilder;
|
||||
use crate::http_server::common_responses::media::media_domain::MediaDomain;
|
||||
use crate::http_server::web_utils::bucket_urls::bucket_url_from_media_path::bucket_url_from_media_path;
|
||||
use artcraft_api_defs::common::responses::media_file_cover_image_details::{MediaFileCoverImageDetails, MediaFileDefaultCover};
|
||||
use bucket_paths::legacy::typified_paths::public::media_files::bucket_file_path::MediaFileBucketPath;
|
||||
use server_environment::ServerEnvironment;
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use tokens::tokens::media_files::MediaFileToken;
|
||||
@@ -42,6 +42,7 @@ impl MediaFileCoverImageDetailsBuilder {
|
||||
pub fn from_optional_db_fields(
|
||||
token: &MediaFileToken,
|
||||
domain: MediaDomain,
|
||||
server_environment: ServerEnvironment,
|
||||
maybe_cover_image_public_bucket_path: Option<&str>,
|
||||
maybe_cover_image_public_bucket_prefix: Option<&str>,
|
||||
maybe_cover_image_public_bucket_extension: Option<&str>,
|
||||
@@ -49,6 +50,7 @@ impl MediaFileCoverImageDetailsBuilder {
|
||||
Self::from_optional_db_str_fields(
|
||||
token.as_str(),
|
||||
domain,
|
||||
server_environment,
|
||||
maybe_cover_image_public_bucket_path,
|
||||
maybe_cover_image_public_bucket_prefix,
|
||||
maybe_cover_image_public_bucket_extension
|
||||
@@ -58,6 +60,7 @@ impl MediaFileCoverImageDetailsBuilder {
|
||||
pub fn from_optional_db_str_fields(
|
||||
token: &str,
|
||||
domain: MediaDomain,
|
||||
server_environment: ServerEnvironment,
|
||||
maybe_cover_image_public_bucket_path: Option<&str>,
|
||||
maybe_cover_image_public_bucket_prefix: Option<&str>,
|
||||
maybe_cover_image_public_bucket_extension: Option<&str>,
|
||||
@@ -69,29 +72,10 @@ impl MediaFileCoverImageDetailsBuilder {
|
||||
maybe_cover_image_public_bucket_extension
|
||||
));
|
||||
|
||||
let maybe_cover_image_public_bucket_path = maybe_bucket_path
|
||||
.as_ref()
|
||||
.map(|bucket_path| bucket_path
|
||||
.get_full_object_path_str()
|
||||
.to_string());
|
||||
|
||||
// NB: Fail construction open.
|
||||
let maybe_cover_image_public_bucket_url = maybe_bucket_path
|
||||
.as_ref()
|
||||
.map(|bucket_path| bucket_url_from_media_path(bucket_path).ok())
|
||||
.flatten();
|
||||
|
||||
let maybe_links = CoverImageLinksBuilder::from_maybe_media_path(
|
||||
domain, maybe_bucket_path.as_ref());
|
||||
|
||||
// let maybe_media_links = maybe_bucket_path
|
||||
// .map(|path| MediaLinks::from_media_path(domain, &path));
|
||||
domain, server_environment, maybe_bucket_path.as_ref());
|
||||
|
||||
MediaFileCoverImageDetails {
|
||||
// NB: The code using this builder does not populate or read these legacy fields:
|
||||
// maybe_cover_image_public_bucket_path,
|
||||
// maybe_cover_image_public_bucket_url,
|
||||
// maybe_media_links,
|
||||
maybe_links,
|
||||
default_cover: MediaFileDefaultCoverBuilder::from_token_str(token),
|
||||
}
|
||||
|
||||
+12
-6
@@ -1,12 +1,13 @@
|
||||
use url::Url;
|
||||
use utoipa::ToSchema;
|
||||
|
||||
use crate::http_server::common_responses::media::cdn_link;
|
||||
use crate::http_server::common_responses::media::cover_image_links::CoverImageLinks;
|
||||
use crate::http_server::common_responses::media::media_domain::MediaDomain;
|
||||
use crate::http_server::web_utils::bucket_urls::bucket_url_from_media_path::bucket_url_from_media_path;
|
||||
use crate::util::placeholder_images::cover_images::default_cover_image_color_from_token::default_cover_image_color_from_token;
|
||||
use crate::util::placeholder_images::cover_images::default_cover_image_from_token::default_cover_image_from_token;
|
||||
use bucket_paths::legacy::typified_paths::public::media_files::bucket_file_path::MediaFileBucketPath;
|
||||
use server_environment::ServerEnvironment;
|
||||
use tokens::tokens::model_weights::ModelWeightToken;
|
||||
|
||||
/// Everything we need to create a cover image.
|
||||
@@ -45,6 +46,7 @@ impl WeightsCoverImageDetails {
|
||||
|
||||
pub fn from_optional_db_fields(
|
||||
domain: MediaDomain,
|
||||
server_environment: ServerEnvironment,
|
||||
model_weight_token: &ModelWeightToken,
|
||||
maybe_cover_image_public_bucket_path: Option<&str>,
|
||||
maybe_cover_image_public_bucket_prefix: Option<&str>,
|
||||
@@ -66,13 +68,15 @@ impl WeightsCoverImageDetails {
|
||||
// NB: Fail construction open.
|
||||
let maybe_cover_image_public_bucket_url = maybe_bucket_path
|
||||
.as_ref()
|
||||
.map(|bucket_path| bucket_url_from_media_path(bucket_path).ok())
|
||||
.flatten();
|
||||
|
||||
let image_index = default_cover_image_from_token(model_weight_token);
|
||||
.and_then(|bucket_path| {
|
||||
let rooted_path = bucket_path.get_full_object_path_str();
|
||||
let mut url = cdn_link::new_cdn_url(domain, server_environment);
|
||||
url.set_path(rooted_path);
|
||||
Some(url)
|
||||
});
|
||||
|
||||
let maybe_links = CoverImageLinks::from_maybe_media_path(
|
||||
domain, maybe_bucket_path.as_ref());
|
||||
domain, server_environment, maybe_bucket_path.as_ref());
|
||||
|
||||
Self {
|
||||
maybe_cover_image_public_bucket_path,
|
||||
@@ -96,6 +100,7 @@ impl WeightsDefaultCoverInfo {
|
||||
mod tests {
|
||||
use crate::http_server::common_responses::media::media_domain::MediaDomain;
|
||||
use crate::http_server::common_responses::media::weights_cover_image_details::WeightsCoverImageDetails;
|
||||
use server_environment::ServerEnvironment;
|
||||
use tokens::tokens::model_weights::ModelWeightToken;
|
||||
use url::Url;
|
||||
|
||||
@@ -109,6 +114,7 @@ mod tests {
|
||||
|
||||
let cover_image = WeightsCoverImageDetails::from_optional_db_fields(
|
||||
domain,
|
||||
ServerEnvironment::Production,
|
||||
&token,
|
||||
maybe_public_bucket_hash,
|
||||
maybe_prefix,
|
||||
|
||||
+2
-1
@@ -341,10 +341,11 @@ pub async fn batch_get_media_files_handler(
|
||||
public_bucket_path: public_bucket_path
|
||||
.get_full_object_path_str()
|
||||
.to_string(),
|
||||
public_bucket_url: bucket_url_string_from_media_path(&public_bucket_path),
|
||||
public_bucket_url: bucket_url_string_from_media_path(&public_bucket_path, media_domain, server_state.server_environment),
|
||||
cover_image: MediaFileCoverImageDetails::from_optional_db_fields(
|
||||
&result.token,
|
||||
media_domain,
|
||||
server_state.server_environment,
|
||||
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(),
|
||||
|
||||
+4
-3
@@ -366,7 +366,7 @@ async fn modern_media_file_lookup(
|
||||
maybe_batch_token: result.maybe_batch_token,
|
||||
maybe_scene_source_media_file_token: result.maybe_scene_source_media_file_token,
|
||||
media_links: MediaLinksBuilder::from_media_path_and_env(media_domain, server_state.server_environment, &public_bucket_path),
|
||||
public_bucket_url: bucket_url_from_media_path(&public_bucket_path)
|
||||
public_bucket_url: bucket_url_from_media_path(&public_bucket_path, media_domain, server_state.server_environment)
|
||||
.map_err(|err| {
|
||||
warn!("error creating URL: {:?}", err);
|
||||
GetMediaFileError::ServerError
|
||||
@@ -377,6 +377,7 @@ async fn modern_media_file_lookup(
|
||||
cover_image: MediaFileCoverImageDetails::from_optional_db_fields(
|
||||
&result.token,
|
||||
media_domain,
|
||||
server_state.server_environment,
|
||||
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(),
|
||||
@@ -503,13 +504,13 @@ async fn emulate_media_file_with_legacy_tts_result_lookup(
|
||||
maybe_batch_token: None,
|
||||
maybe_scene_source_media_file_token: None,
|
||||
media_links: MediaLinksBuilder::from_rooted_path_and_env(media_domain, server_state.server_environment, &public_bucket_path),
|
||||
public_bucket_url: bucket_url_from_str_path(&public_bucket_path)
|
||||
public_bucket_url: bucket_url_from_str_path(&public_bucket_path, media_domain, server_state.server_environment)
|
||||
.map_err(|err| {
|
||||
warn!("error creating URL: {:?}", err);
|
||||
GetMediaFileError::ServerError
|
||||
})?,
|
||||
public_bucket_path,
|
||||
cover_image: MediaFileCoverImageDetails::from_token_str(&result.tts_result_token),
|
||||
cover_image: MediaFileCoverImageDetails::from_legacy_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),
|
||||
|
||||
+1
-1
@@ -8,7 +8,6 @@ use crate::http_server::common_responses::media::media_links_builder::MediaLinks
|
||||
use crate::http_server::common_responses::user_details_lite_builder::UserDetailsLightBuilder;
|
||||
use crate::http_server::endpoints::media_files::get::get_media_file_handler::GetMediaFilePathInfo;
|
||||
use crate::http_server::endpoints::media_files::helpers::get_media_domain::get_media_domain;
|
||||
use crate::http_server::web_utils::bucket_urls::bucket_url_string_from_media_path::bucket_url_string_from_media_path;
|
||||
use crate::http_server::web_utils::response_error_helpers::to_simple_json_error;
|
||||
use crate::state::server_state::ServerState;
|
||||
use actix_web::error::ResponseError;
|
||||
@@ -120,6 +119,7 @@ pub async fn list_batch_generated_redux_media_files_handler(
|
||||
cover_image: MediaFileCoverImageDetailsBuilder::from_optional_db_fields(
|
||||
&result.token,
|
||||
media_domain,
|
||||
server_state.server_environment,
|
||||
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(),
|
||||
|
||||
+2
-1
@@ -296,10 +296,11 @@ pub async fn list_featured_media_files_handler(
|
||||
public_bucket_path: public_bucket_path
|
||||
.get_full_object_path_str()
|
||||
.to_string(),
|
||||
public_bucket_url: bucket_url_string_from_media_path(&public_bucket_path),
|
||||
public_bucket_url: bucket_url_string_from_media_path(&public_bucket_path, media_domain, server_state.server_environment),
|
||||
cover_image: MediaFileCoverImageDetails::from_optional_db_fields(
|
||||
&m.token,
|
||||
media_domain,
|
||||
server_state.server_environment,
|
||||
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(),
|
||||
|
||||
+1
-1
@@ -285,7 +285,7 @@ pub async fn list_media_files_by_batch_token_handler(
|
||||
public_bucket_path: public_bucket_path
|
||||
.get_full_object_path_str()
|
||||
.to_string(),
|
||||
public_bucket_url: bucket_url_string_from_media_path(&public_bucket_path),
|
||||
public_bucket_url: bucket_url_string_from_media_path(&public_bucket_path, media_domain, server_state.server_environment),
|
||||
cover_image: MediaFileCoverImageDetails::from_token(&record.token),
|
||||
creator_set_visibility: record.creator_set_visibility,
|
||||
is_user_upload: record.is_user_upload,
|
||||
|
||||
+2
-1
@@ -344,10 +344,11 @@ pub async fn list_media_files_for_user_handler(
|
||||
public_bucket_path: public_bucket_path
|
||||
.get_full_object_path_str()
|
||||
.to_string(),
|
||||
public_bucket_url: bucket_url_string_from_media_path(&public_bucket_path),
|
||||
public_bucket_url: bucket_url_string_from_media_path(&public_bucket_path, media_domain, server_state.server_environment),
|
||||
cover_image: MediaFileCoverImageDetails::from_optional_db_fields(
|
||||
&record.token,
|
||||
media_domain,
|
||||
server_state.server_environment,
|
||||
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(),
|
||||
|
||||
+2
-1
@@ -353,10 +353,11 @@ pub async fn list_media_files_handler(
|
||||
public_bucket_path: public_bucket_path
|
||||
.get_full_object_path_str()
|
||||
.to_string(),
|
||||
public_bucket_url: bucket_url_string_from_media_path(&public_bucket_path),
|
||||
public_bucket_url: bucket_url_string_from_media_path(&public_bucket_path, media_domain, server_state.server_environment),
|
||||
cover_image: MediaFileCoverImageDetails::from_optional_db_fields(
|
||||
&record.token,
|
||||
media_domain,
|
||||
server_state.server_environment,
|
||||
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(),
|
||||
|
||||
+2
-1
@@ -223,10 +223,11 @@ pub async fn list_pinned_media_files_handler(
|
||||
public_bucket_path: public_bucket_path
|
||||
.get_full_object_path_str()
|
||||
.to_string(),
|
||||
public_bucket_url: bucket_url_string_from_media_path(&public_bucket_path),
|
||||
public_bucket_url: bucket_url_string_from_media_path(&public_bucket_path, media_domain, server_state.server_environment),
|
||||
cover_image: MediaFileCoverImageDetails::from_optional_db_fields(
|
||||
&m.token,
|
||||
media_domain,
|
||||
server_state.server_environment,
|
||||
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(),
|
||||
|
||||
+2
-1
@@ -235,10 +235,11 @@ pub async fn search_featured_media_files_handler(
|
||||
public_bucket_path: public_bucket_path
|
||||
.get_full_object_path_str()
|
||||
.to_string(),
|
||||
public_bucket_url: bucket_url_string_from_media_path(&public_bucket_path),
|
||||
public_bucket_url: bucket_url_string_from_media_path(&public_bucket_path, media_domain, server_state.server_environment),
|
||||
cover_image: MediaFileCoverImageDetails::from_optional_db_fields(
|
||||
&result.token,
|
||||
media_domain,
|
||||
server_state.server_environment,
|
||||
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(),
|
||||
|
||||
+2
-1
@@ -262,10 +262,11 @@ pub async fn search_session_media_files_handler(
|
||||
public_bucket_path: public_bucket_path
|
||||
.get_full_object_path_str()
|
||||
.to_string(),
|
||||
public_bucket_url: bucket_url_string_from_media_path(&public_bucket_path),
|
||||
public_bucket_url: bucket_url_string_from_media_path(&public_bucket_path, media_domain, server_state.server_environment),
|
||||
cover_image: MediaFileCoverImageDetails::from_optional_db_fields(
|
||||
&result.token,
|
||||
media_domain,
|
||||
server_state.server_environment,
|
||||
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(),
|
||||
|
||||
+2
@@ -243,6 +243,7 @@ pub async fn list_user_bookmarks_for_user_handler(
|
||||
maybe_media_file_cover = Some(MediaFileCoverImageDetails::from_optional_db_fields(
|
||||
&MediaFileToken::new_from_str(&user_bookmark.entity_token),
|
||||
media_domain,
|
||||
server_state.server_environment,
|
||||
user_bookmark.maybe_media_file_cover_image_public_bucket_hash.as_deref(),
|
||||
user_bookmark.maybe_media_file_cover_image_public_bucket_prefix.as_deref(),
|
||||
user_bookmark.maybe_media_file_cover_image_public_bucket_extension.as_deref(),
|
||||
@@ -251,6 +252,7 @@ pub async fn list_user_bookmarks_for_user_handler(
|
||||
UserBookmarkEntityType::ModelWeight => {
|
||||
maybe_model_weight_cover = Some(WeightsCoverImageDetails::from_optional_db_fields(
|
||||
media_domain,
|
||||
server_state.server_environment,
|
||||
&ModelWeightToken::new_from_str(&user_bookmark.entity_token),
|
||||
user_bookmark.maybe_model_weight_cover_image_public_bucket_hash.as_deref(),
|
||||
user_bookmark.maybe_model_weight_cover_image_public_bucket_prefix.as_deref(),
|
||||
|
||||
+1
@@ -184,6 +184,7 @@ pub async fn get_weight_handler(
|
||||
|
||||
let cover_image_details = WeightsCoverImageDetails::from_optional_db_fields(
|
||||
media_domain,
|
||||
server_state.server_environment,
|
||||
&weight.token,
|
||||
weight.maybe_cover_image_public_bucket_hash.as_deref(),
|
||||
weight.maybe_cover_image_public_bucket_prefix.as_deref(),
|
||||
|
||||
+1
@@ -234,6 +234,7 @@ pub async fn list_available_weights_handler(
|
||||
.map(|weight| {
|
||||
let cover_image_details = WeightsCoverImageDetails::from_optional_db_fields(
|
||||
media_domain,
|
||||
server_state.server_environment,
|
||||
&weight.token,
|
||||
weight.maybe_cover_image_public_bucket_hash.as_deref(),
|
||||
weight.maybe_cover_image_public_bucket_prefix.as_deref(),
|
||||
|
||||
+1
@@ -235,6 +235,7 @@ pub async fn list_featured_weights_handler(
|
||||
.map(|w| {
|
||||
let cover_image_details = WeightsCoverImageDetails::from_optional_db_fields(
|
||||
media_domain,
|
||||
server_state.server_environment,
|
||||
&w.token,
|
||||
w.maybe_cover_image_public_bucket_hash.as_deref(),
|
||||
w.maybe_cover_image_public_bucket_prefix.as_deref(),
|
||||
|
||||
+1
@@ -156,6 +156,7 @@ pub async fn list_pinned_weights_handler(
|
||||
.map(|w| {
|
||||
let cover_image_details = WeightsCoverImageDetails::from_optional_db_fields(
|
||||
media_domain,
|
||||
server_state.server_environment,
|
||||
&w.token,
|
||||
w.maybe_cover_image_public_bucket_hash.as_deref(),
|
||||
w.maybe_cover_image_public_bucket_prefix.as_deref(),
|
||||
|
||||
+1
@@ -212,6 +212,7 @@ pub async fn list_weights_by_user_handler(
|
||||
|
||||
let cover_image_details = WeightsCoverImageDetails::from_optional_db_fields(
|
||||
media_domain,
|
||||
server_state.server_environment,
|
||||
&weight.token,
|
||||
weight.maybe_cover_image_public_bucket_hash.as_deref(),
|
||||
weight.maybe_cover_image_public_bucket_prefix.as_deref(),
|
||||
|
||||
+1
@@ -201,6 +201,7 @@ pub async fn search_model_weights_impl(
|
||||
.map(|result| {
|
||||
let cover_image_details = WeightsCoverImageDetails::from_optional_db_fields(
|
||||
media_domain,
|
||||
server_state.server_environment,
|
||||
&result.token,
|
||||
result.maybe_cover_image_public_bucket_hash.as_deref(),
|
||||
result.maybe_cover_image_public_bucket_prefix.as_deref(),
|
||||
|
||||
+21
-4
@@ -2,13 +2,20 @@ use url::Url;
|
||||
|
||||
use bucket_paths::legacy::typified_paths::public::media_files::bucket_file_path::MediaFileBucketPath;
|
||||
use errors::AnyhowResult;
|
||||
use server_environment::ServerEnvironment;
|
||||
|
||||
use crate::http_server::common_responses::media::cdn_link;
|
||||
use crate::http_server::common_responses::media::media_domain::MediaDomain;
|
||||
|
||||
#[deprecated(note = "This is tied to GCP and is legacy.")]
|
||||
pub fn bucket_url_from_media_path(
|
||||
bucket_path: &MediaFileBucketPath,
|
||||
domain: MediaDomain,
|
||||
server_environment: ServerEnvironment,
|
||||
) -> AnyhowResult<Url> {
|
||||
let path = bucket_path.get_full_object_path_str();
|
||||
let url = format!("https://cdn-2.fakeyou.com{}", path);
|
||||
let host = cdn_link::get_cdn_host(domain, server_environment);
|
||||
let url = format!("{host}{path}");
|
||||
let url = Url::parse(&url)?;
|
||||
Ok(url)
|
||||
}
|
||||
@@ -18,14 +25,24 @@ mod tests {
|
||||
use url::Url;
|
||||
|
||||
use bucket_paths::legacy::typified_paths::public::media_files::bucket_file_path::MediaFileBucketPath;
|
||||
use server_environment::ServerEnvironment;
|
||||
|
||||
use crate::http_server::common_responses::media::media_domain::MediaDomain;
|
||||
use crate::http_server::web_utils::bucket_urls::bucket_url_from_media_path::bucket_url_from_media_path;
|
||||
|
||||
#[test]
|
||||
fn test() {
|
||||
fn test_production() {
|
||||
let bucket_path = MediaFileBucketPath::from_object_hash("test", Some("pre_"), Some(".ext"));
|
||||
|
||||
assert_eq!(bucket_url_from_media_path(&bucket_path).unwrap(),
|
||||
Url::parse("https://storage.googleapis.com/vocodes-public/media/t/e/s/test/pre_test.ext").unwrap());
|
||||
assert_eq!(bucket_url_from_media_path(&bucket_path, MediaDomain::FakeYou, ServerEnvironment::Production).unwrap(),
|
||||
Url::parse("https://cdn-2.fakeyou.com/media/t/e/s/test/pre_test.ext").unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_development() {
|
||||
let bucket_path = MediaFileBucketPath::from_object_hash("test", Some("pre_"), Some(".ext"));
|
||||
|
||||
assert_eq!(bucket_url_from_media_path(&bucket_path, MediaDomain::FakeYou, ServerEnvironment::Development).unwrap(),
|
||||
Url::parse("https://pub-c8a4a5bdbdb048f286b77bdf9f786ff2.r2.dev/media/t/e/s/test/pre_test.ext").unwrap());
|
||||
}
|
||||
}
|
||||
+19
-4
@@ -1,11 +1,18 @@
|
||||
use url::Url;
|
||||
|
||||
use errors::AnyhowResult;
|
||||
use server_environment::ServerEnvironment;
|
||||
|
||||
use crate::http_server::common_responses::media::cdn_link;
|
||||
use crate::http_server::common_responses::media::media_domain::MediaDomain;
|
||||
|
||||
pub fn bucket_url_from_str_path(
|
||||
bucket_path: &str,
|
||||
domain: MediaDomain,
|
||||
server_environment: ServerEnvironment,
|
||||
) -> AnyhowResult<Url> {
|
||||
let url = format!("https://cdn-2.fakeyou.com{}", bucket_path);
|
||||
let host = cdn_link::get_cdn_host(domain, server_environment);
|
||||
let url = format!("{host}{bucket_path}");
|
||||
let url = Url::parse(&url)?;
|
||||
Ok(url)
|
||||
}
|
||||
@@ -13,12 +20,20 @@ pub fn bucket_url_from_str_path(
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use url::Url;
|
||||
use server_environment::ServerEnvironment;
|
||||
|
||||
use crate::http_server::common_responses::media::media_domain::MediaDomain;
|
||||
use crate::http_server::web_utils::bucket_urls::bucket_url_from_str_path::bucket_url_from_str_path;
|
||||
|
||||
#[test]
|
||||
fn test() {
|
||||
assert_eq!(bucket_url_from_str_path("/foo/bar").unwrap(),
|
||||
Url::parse("https://storage.googleapis.com/vocodes-public/foo/bar").unwrap());
|
||||
fn test_production() {
|
||||
assert_eq!(bucket_url_from_str_path("/foo/bar", MediaDomain::FakeYou, ServerEnvironment::Production).unwrap(),
|
||||
Url::parse("https://cdn-2.fakeyou.com/foo/bar").unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_development() {
|
||||
assert_eq!(bucket_url_from_str_path("/foo/bar", MediaDomain::FakeYou, ServerEnvironment::Development).unwrap(),
|
||||
Url::parse("https://pub-c8a4a5bdbdb048f286b77bdf9f786ff2.r2.dev/foo/bar").unwrap());
|
||||
}
|
||||
}
|
||||
+21
-4
@@ -1,24 +1,41 @@
|
||||
use bucket_paths::legacy::typified_paths::public::media_files::bucket_file_path::MediaFileBucketPath;
|
||||
use server_environment::ServerEnvironment;
|
||||
|
||||
use crate::http_server::common_responses::media::cdn_link;
|
||||
use crate::http_server::common_responses::media::media_domain::MediaDomain;
|
||||
|
||||
/// An infallible version of `bucket_url_from_media_path` that returns a string.
|
||||
pub fn bucket_url_string_from_media_path(
|
||||
bucket_path: &MediaFileBucketPath,
|
||||
domain: MediaDomain,
|
||||
server_environment: ServerEnvironment,
|
||||
) -> String {
|
||||
let path = bucket_path.get_full_object_path_str();
|
||||
format!("https://cdn-2.fakeyou.com{}", path)
|
||||
let host = cdn_link::get_cdn_host(domain, server_environment);
|
||||
format!("{host}{path}")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use bucket_paths::legacy::typified_paths::public::media_files::bucket_file_path::MediaFileBucketPath;
|
||||
use server_environment::ServerEnvironment;
|
||||
|
||||
use crate::http_server::common_responses::media::media_domain::MediaDomain;
|
||||
use crate::http_server::web_utils::bucket_urls::bucket_url_string_from_media_path::bucket_url_string_from_media_path;
|
||||
|
||||
#[test]
|
||||
fn test() {
|
||||
fn test_production() {
|
||||
let bucket_path = MediaFileBucketPath::from_object_hash("test", Some("pre_"), Some(".ext"));
|
||||
|
||||
assert_eq!(&bucket_url_string_from_media_path(&bucket_path),
|
||||
"https://storage.googleapis.com/vocodes-public/media/t/e/s/test/pre_test.ext");
|
||||
assert_eq!(&bucket_url_string_from_media_path(&bucket_path, MediaDomain::FakeYou, ServerEnvironment::Production),
|
||||
"https://cdn-2.fakeyou.com/media/t/e/s/test/pre_test.ext");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_development() {
|
||||
let bucket_path = MediaFileBucketPath::from_object_hash("test", Some("pre_"), Some(".ext"));
|
||||
|
||||
assert_eq!(&bucket_url_string_from_media_path(&bucket_path, MediaDomain::FakeYou, ServerEnvironment::Development),
|
||||
"https://pub-c8a4a5bdbdb048f286b77bdf9f786ff2.r2.dev/media/t/e/s/test/pre_test.ext");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user