diff --git a/_migrations/2022-08-05-202017_generic_download_jobs/up.sql b/_migrations/2022-08-05-202017_generic_download_jobs/up.sql index fe7ef0feb4..17a883e0a6 100644 --- a/_migrations/2022-08-05-202017_generic_download_jobs/up.sql +++ b/_migrations/2022-08-05-202017_generic_download_jobs/up.sql @@ -30,17 +30,17 @@ CREATE TABLE generic_download_jobs ( -- The first upload type will be "hifigan_model" download_type VARCHAR(32) NOT NULL, + -- Assume the same URL can be uploaded more than once (in case of errors or + -- people sharing models) + + download_url VARCHAR(512) NOT NULL, + -- The user-supplied title of the upload -- This might have different meanings for different upload types -- The "name" of the voice model, which might be complicated. -- If maybe_subject_token (etc.) is set, then it's authoritative instead. title VARCHAR(255) NOT NULL, - -- Assume the same URL can be uploaded more than once (in case of errors or - -- people sharing models) - - download_url VARCHAR(512) NOT NULL, - -- ========== CREATOR DETAILS AND PREFERENCES ========== -- Foreign key to user diff --git a/crates/lib/database_queries/src/queries/generic_download/insert_generic_download_job.rs b/crates/lib/database_queries/src/queries/generic_download/insert_generic_download_job.rs index cd3761a3f8..ed9c936022 100644 --- a/crates/lib/database_queries/src/queries/generic_download/insert_generic_download_job.rs +++ b/crates/lib/database_queries/src/queries/generic_download/insert_generic_download_job.rs @@ -34,12 +34,12 @@ SET "#, args.job_token, args.uuid_idempotency_token, - args.download_type, + args.download_type.to_str(), args.download_url, args.title, args.creator_user_token, args.creator_ip_address, - args.creator_set_visibility, + args.creator_set_visibility.to_str(), ); let query_result = query.execute(args.mysql_pool) diff --git a/crates/lib/database_queries/src/queries/vocoder/insert_vocoder_model.rs b/crates/lib/database_queries/src/queries/vocoder/insert_vocoder_model.rs index 5271438793..faa89b1a25 100644 --- a/crates/lib/database_queries/src/queries/vocoder/insert_vocoder_model.rs +++ b/crates/lib/database_queries/src/queries/vocoder/insert_vocoder_model.rs @@ -56,7 +56,7 @@ SET private_bucket_object_name = ? "#, &model_token, - args.vocoder_type, + args.vocoder_type.to_str(), &args.title, &args.original_download_url, &args.original_filename, @@ -64,7 +64,7 @@ SET &args.creator_user_token, &args.creator_ip_address, &args.creator_ip_address, - args.creator_set_visibility, + args.creator_set_visibility.to_str(), args.private_bucket_hash, private_bucket_object_name, ) diff --git a/crates/lib/database_queries/src/tokens.rs b/crates/lib/database_queries/src/tokens.rs index 9c147d39f0..2b8ed58e04 100644 --- a/crates/lib/database_queries/src/tokens.rs +++ b/crates/lib/database_queries/src/tokens.rs @@ -59,6 +59,10 @@ impl Tokens { random_prefix_crockford_token("JWINF:", 32, false) } + pub fn new_generic_upload_job() -> AnyhowResult { + random_prefix_crockford_token("JGUP:", 32, false) + } + pub fn new_firehose_event() -> AnyhowResult { random_prefix_crockford_token("EV:", 32, false) } diff --git a/crates/lib/reusable_types/src/generic_download_type.rs b/crates/lib/reusable_types/src/generic_download_type.rs index 23c179bd6a..d5dfaf7928 100644 --- a/crates/lib/reusable_types/src/generic_download_type.rs +++ b/crates/lib/reusable_types/src/generic_download_type.rs @@ -10,6 +10,22 @@ pub enum GenericDownloadType { HifiGan, } +/// NB: Legacy API for older code. +impl GenericDownloadType { + pub fn to_str(&self) -> &'static str { + match self { + Self::HifiGan=> "hifigan", + } + } + + pub fn from_str(value: &str) -> Result { + match value { + "hifigan" => Ok(Self::HifiGan), + _ => Err(format!("invalid value: {:?}", value)), + } + } +} + #[cfg(test)] mod tests { use crate::generic_download_type::GenericDownloadType; diff --git a/crates/lib/reusable_types/src/vocoder_type.rs b/crates/lib/reusable_types/src/vocoder_type.rs index 9821ca5fa2..1581c99903 100644 --- a/crates/lib/reusable_types/src/vocoder_type.rs +++ b/crates/lib/reusable_types/src/vocoder_type.rs @@ -5,6 +5,22 @@ pub enum VocoderType { HifiGan, } +/// NB: Legacy API for older code. +impl VocoderType { + pub fn to_str(&self) -> &'static str { + match self { + Self::HifiGan=> "hifigan", + } + } + + pub fn from_str(value: &str) -> Result { + match value { + "hifigan" => Ok(Self::HifiGan), + _ => Err(format!("invalid value: {:?}", value)), + } + } +} + #[cfg(test)] mod tests { use crate::test_helpers::assert_serialization; diff --git a/crates/service/storyteller_web/src/http_server/endpoints/download_job/enqueue_generic_download.rs b/crates/service/storyteller_web/src/http_server/endpoints/download_job/enqueue_generic_download.rs index 35ff9e82e8..d825bf5658 100644 --- a/crates/service/storyteller_web/src/http_server/endpoints/download_job/enqueue_generic_download.rs +++ b/crates/service/storyteller_web/src/http_server/endpoints/download_job/enqueue_generic_download.rs @@ -130,7 +130,7 @@ pub async fn enqueue_generic_download_handler( } // This token is returned to the client. - let job_token = Tokens::new_tts_model_upload_job() + let job_token = Tokens::new_generic_upload_job() .map_err(|e| { warn!("Error creating token"); EnqueueGenericDownloadError::ServerError