more concrete types for "enum"-like fields, remove unnecessary updates

This commit is contained in:
Brandon Thomas
2023-10-25 23:39:42 -04:00
parent b11ad51d8e
commit 50a0cb298d
16 changed files with 451 additions and 92 deletions
@@ -58,8 +58,8 @@ CREATE TABLE zs_voices (
-- to deal with.
--
-- Example values:
-- * 'spectrogram'
-- * 'encodec'
-- * 'spectrogram' (for example; not yet used)
-- * (Since this isn't an enum, the list of values can be expanded.)
encoding_type VARCHAR(16) NOT NULL,
@@ -1,5 +1,5 @@
use serde::Deserialize;
use serde::Serialize;
use std::collections::BTreeSet;
#[cfg(test)]
use strum::EnumCount;
#[cfg(test)]
@@ -9,7 +9,7 @@ use strum::EnumIter;
///
/// DO NOT CHANGE VALUES WITHOUT A MIGRATION STRATEGY.
#[cfg_attr(test, derive(EnumIter, EnumCount))]
#[derive(Clone, Copy, Eq, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Deserialize, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum MediaFileType {
/// Audio files: wav, mp3, etc.
@@ -44,6 +44,16 @@ impl MediaFileType {
_ => Err(format!("invalid value: {:?}", value)),
}
}
pub fn all_variants() -> BTreeSet<Self> {
// NB: BTreeSet is sorted
// NB: BTreeSet::from() isn't const, but not worth using LazyStatic, etc.
BTreeSet::from([
Self::Audio,
Self::Image,
Self::Video,
])
}
}
#[cfg(test)]
@@ -51,25 +61,66 @@ mod tests {
use crate::by_table::media_files::media_file_type::MediaFileType;
use crate::test_helpers::assert_serialization;
#[test]
fn test_serialization() {
assert_serialization(MediaFileType::Audio, "audio");
assert_serialization(MediaFileType::Image, "image");
assert_serialization(MediaFileType::Video, "video");
mod serde {
use super::*;
#[test]
fn test_serialization() {
assert_serialization(MediaFileType::Audio, "audio");
assert_serialization(MediaFileType::Image, "image");
assert_serialization(MediaFileType::Video, "video");
}
}
#[test]
fn test_to_str() {
assert_eq!(MediaFileType::Audio.to_str(), "audio");
assert_eq!(MediaFileType::Image.to_str(), "image");
assert_eq!(MediaFileType::Video.to_str(), "video");
mod impl_methods {
use super::*;
#[test]
fn to_str() {
assert_eq!(MediaFileType::Audio.to_str(), "audio");
assert_eq!(MediaFileType::Image.to_str(), "image");
assert_eq!(MediaFileType::Video.to_str(), "video");
}
#[test]
fn from_str() {
assert_eq!(MediaFileType::from_str("audio").unwrap(), MediaFileType::Audio);
assert_eq!(MediaFileType::from_str("image").unwrap(), MediaFileType::Image);
assert_eq!(MediaFileType::from_str("video").unwrap(), MediaFileType::Video);
assert!(MediaFileType::from_str("foo").is_err());
}
}
#[test]
fn test_from_str() {
assert_eq!(MediaFileType::from_str("audio").unwrap(), MediaFileType::Audio);
assert_eq!(MediaFileType::from_str("image").unwrap(), MediaFileType::Image);
assert_eq!(MediaFileType::from_str("video").unwrap(), MediaFileType::Video);
assert!(MediaFileType::from_str("foo").is_err());
mod manual_variant_checks {
use super::*;
#[test]
fn all_variants() {
let mut variants = MediaFileType::all_variants();
assert_eq!(variants.len(), 3);
assert_eq!(variants.pop_first(), Some(MediaFileType::Audio));
assert_eq!(variants.pop_first(), Some(MediaFileType::Image));
assert_eq!(variants.pop_first(), Some(MediaFileType::Video));
assert_eq!(variants.pop_first(), None);
}
}
mod mechanical_checks {
use super::*;
#[test]
fn variant_length() {
use strum::IntoEnumIterator;
assert_eq!(MediaFileType::all_variants().len(), MediaFileType::iter().len());
}
#[test]
fn round_trip() {
for variant in MediaFileType::all_variants() {
assert_eq!(variant, MediaFileType::from_str(variant.to_str()).unwrap());
assert_eq!(variant, MediaFileType::from_str(&format!("{}", variant)).unwrap());
assert_eq!(variant, MediaFileType::from_str(&format!("{:?}", variant)).unwrap());
}
}
}
}
+1
View File
@@ -12,6 +12,7 @@ pub mod tts_models;
pub mod user_ratings;
pub mod voice_conversion_models;
pub mod voice_conversion_results;
pub mod zs_voices;
// ===== Sqlite =====
pub mod tts_render_tasks;
@@ -0,0 +1,108 @@
use std::collections::BTreeSet;
#[cfg(test)]
use strum::EnumCount;
#[cfg(test)]
use strum::EnumIter;
/// Used in the `zs_voices` table in a `VARCHAR(16)` field named `encoding_type`.
///
/// This indicates what type of features are used in the embeddings.
///
/// DO NOT CHANGE VALUES WITHOUT A MIGRATION STRATEGY.
#[cfg_attr(test, derive(EnumIter, EnumCount))]
#[derive(Clone, Copy, Eq, PartialEq, Hash, Ord, PartialOrd, Deserialize, Serialize)]
pub enum ZsVoiceEncodingType {
/// Encodec features
#[serde(rename = "encodec")]
Encodec,
}
// TODO(bt, 2023-01-17): This desperately needs MySQL integration tests!
impl_enum_display_and_debug_using_to_str!(ZsVoiceEncodingType);
impl_mysql_enum_coders!(ZsVoiceEncodingType);
/// NB: Legacy API for older code.
impl ZsVoiceEncodingType {
pub fn to_str(&self) -> &'static str {
match self {
Self::Encodec => "encodec",
}
}
pub fn from_str(value: &str) -> Result<Self, String> {
match value {
"encodec" => Ok(Self::Encodec),
_ => Err(format!("invalid value: {:?}", value)),
}
}
pub fn all_variants() -> BTreeSet<Self> {
// NB: BTreeSet is sorted
// NB: BTreeSet::from() isn't const, but not worth using LazyStatic, etc.
BTreeSet::from([
Self::Encodec,
])
}
}
#[cfg(test)]
mod tests {
use crate::by_table::zs_voices::encoding_type::ZsVoiceEncodingType;
use crate::test_helpers::assert_serialization;
mod serde {
use super::*;
#[test]
fn test_serialization() {
assert_serialization(ZsVoiceEncodingType::Encodec, "encodec");
}
}
mod impl_methods {
use super::*;
#[test]
fn to_str() {
assert_eq!(ZsVoiceEncodingType::Encodec.to_str(), "encodec");
}
#[test]
fn from_str() {
assert_eq!(ZsVoiceEncodingType::from_str("encodec").unwrap(), ZsVoiceEncodingType::Encodec);
assert!(ZsVoiceEncodingType::from_str("foo").is_err());
}
}
mod manual_variant_checks {
use super::*;
#[test]
fn all_variants() {
let mut variants = ZsVoiceEncodingType::all_variants();
assert_eq!(variants.len(), 1);
assert_eq!(variants.pop_first(), Some(ZsVoiceEncodingType::Encodec));
assert_eq!(variants.pop_first(), None);
}
}
mod mechanical_checks {
use super::*;
#[test]
fn variant_length() {
use strum::IntoEnumIterator;
assert_eq!(ZsVoiceEncodingType::all_variants().len(), ZsVoiceEncodingType::iter().len());
}
#[test]
fn round_trip() {
for variant in ZsVoiceEncodingType::all_variants() {
assert_eq!(variant, ZsVoiceEncodingType::from_str(variant.to_str()).unwrap());
assert_eq!(variant, ZsVoiceEncodingType::from_str(&format!("{}", variant)).unwrap());
assert_eq!(variant, ZsVoiceEncodingType::from_str(&format!("{:?}", variant)).unwrap());
}
}
}
}
@@ -0,0 +1,3 @@
pub mod encoding_type;
pub mod model_category;
pub mod model_type;
@@ -0,0 +1,108 @@
use std::collections::BTreeSet;
#[cfg(test)]
use strum::EnumCount;
#[cfg(test)]
use strum::EnumIter;
/// Used in the `zs_voices` table in a `VARCHAR(16)` field named `model_category`.
///
/// This indicates what type of features are used in the embeddings.
///
/// DO NOT CHANGE VALUES WITHOUT A MIGRATION STRATEGY.
#[cfg_attr(test, derive(EnumIter, EnumCount))]
#[derive(Clone, Copy, Eq, PartialEq, Hash, Ord, PartialOrd, Deserialize, Serialize)]
pub enum ZsVoiceModelCategory {
/// TTS-type zero shot models
#[serde(rename = "tts")]
Tts,
}
// TODO(bt, 2023-01-17): This desperately needs MySQL integration tests!
impl_enum_display_and_debug_using_to_str!(ZsVoiceModelCategory);
impl_mysql_enum_coders!(ZsVoiceModelCategory);
/// NB: Legacy API for older code.
impl ZsVoiceModelCategory {
pub fn to_str(&self) -> &'static str {
match self {
Self::Tts => "tts",
}
}
pub fn from_str(value: &str) -> Result<Self, String> {
match value {
"tts" => Ok(Self::Tts),
_ => Err(format!("invalid value: {:?}", value)),
}
}
pub fn all_variants() -> BTreeSet<Self> {
// NB: BTreeSet is sorted
// NB: BTreeSet::from() isn't const, but not worth using LazyStatic, etc.
BTreeSet::from([
Self::Tts,
])
}
}
#[cfg(test)]
mod tests {
use crate::test_helpers::assert_serialization;
use crate::by_table::zs_voices::model_category::ZsVoiceModelCategory;
mod serde {
use super::*;
#[test]
fn test_serialization() {
assert_serialization(ZsVoiceModelCategory::Tts, "tts");
}
}
mod impl_methods {
use super::*;
#[test]
fn to_str() {
assert_eq!(ZsVoiceModelCategory::Tts.to_str(), "tts");
}
#[test]
fn from_str() {
assert_eq!(ZsVoiceModelCategory::from_str("tts").unwrap(), ZsVoiceModelCategory::Tts);
assert!(ZsVoiceModelCategory::from_str("foo").is_err());
}
}
mod manual_variant_checks {
use super::*;
#[test]
fn all_variants() {
let mut variants = ZsVoiceModelCategory::all_variants();
assert_eq!(variants.len(), 1);
assert_eq!(variants.pop_first(), Some(ZsVoiceModelCategory::Tts));
assert_eq!(variants.pop_first(), None);
}
}
mod mechanical_checks {
use super::*;
#[test]
fn variant_length() {
use strum::IntoEnumIterator;
assert_eq!(ZsVoiceModelCategory::all_variants().len(), ZsVoiceModelCategory::iter().len());
}
#[test]
fn round_trip() {
for variant in ZsVoiceModelCategory::all_variants() {
assert_eq!(variant, ZsVoiceModelCategory::from_str(variant.to_str()).unwrap());
assert_eq!(variant, ZsVoiceModelCategory::from_str(&format!("{}", variant)).unwrap());
assert_eq!(variant, ZsVoiceModelCategory::from_str(&format!("{:?}", variant)).unwrap());
}
}
}
}
@@ -0,0 +1,108 @@
use std::collections::BTreeSet;
#[cfg(test)]
use strum::EnumCount;
#[cfg(test)]
use strum::EnumIter;
/// Used in the `zs_voices` table in a `VARCHAR(16)` field named `model_type`.
///
/// This indicates what type of features are used in the embeddings.
///
/// DO NOT CHANGE VALUES WITHOUT A MIGRATION STRATEGY.
#[cfg_attr(test, derive(EnumIter, EnumCount))]
#[derive(Clone, Copy, Eq, PartialEq, Hash, Ord, PartialOrd, Deserialize, Serialize)]
pub enum ZsVoiceModelType {
/// TTS-type zero shot models
#[serde(rename = "vall-e-x")]
VallEX,
}
// TODO(bt, 2023-01-17): This desperately needs MySQL integration tests!
impl_enum_display_and_debug_using_to_str!(ZsVoiceModelType);
impl_mysql_enum_coders!(ZsVoiceModelType);
/// NB: Legacy API for older code.
impl ZsVoiceModelType {
pub fn to_str(&self) -> &'static str {
match self {
Self::VallEX=> "vall-e-x",
}
}
pub fn from_str(value: &str) -> Result<Self, String> {
match value {
"vall-e-x" => Ok(Self::VallEX),
_ => Err(format!("invalid value: {:?}", value)),
}
}
pub fn all_variants() -> BTreeSet<Self> {
// NB: BTreeSet is sorted
// NB: BTreeSet::from() isn't const, but not worth using LazyStatic, etc.
BTreeSet::from([
Self::VallEX,
])
}
}
#[cfg(test)]
mod tests {
use crate::test_helpers::assert_serialization;
use crate::by_table::zs_voices::model_type::ZsVoiceModelType;
mod serde {
use super::*;
#[test]
fn test_serialization() {
assert_serialization(ZsVoiceModelType::VallEX, "vall-e-x");
}
}
mod impl_methods {
use super::*;
#[test]
fn to_str() {
assert_eq!(ZsVoiceModelType::VallEX.to_str(), "vall-e-x");
}
#[test]
fn from_str() {
assert_eq!(ZsVoiceModelType::from_str("vall-e-x").unwrap(), ZsVoiceModelType::VallEX);
assert!(ZsVoiceModelType::from_str("foo").is_err());
}
}
mod manual_variant_checks {
use super::*;
#[test]
fn all_variants() {
let mut variants = ZsVoiceModelType::all_variants();
assert_eq!(variants.len(), 1);
assert_eq!(variants.pop_first(), Some(ZsVoiceModelType::VallEX));
assert_eq!(variants.pop_first(), None);
}
}
mod mechanical_checks {
use super::*;
#[test]
fn variant_length() {
use strum::IntoEnumIterator;
assert_eq!(ZsVoiceModelType::all_variants().len(), ZsVoiceModelType::iter().len());
}
#[test]
fn round_trip() {
for variant in ZsVoiceModelType::all_variants() {
assert_eq!(variant, ZsVoiceModelType::from_str(variant.to_str()).unwrap());
assert_eq!(variant, ZsVoiceModelType::from_str(&format!("{}", variant)).unwrap());
assert_eq!(variant, ZsVoiceModelType::from_str(&format!("{:?}", variant)).unwrap());
}
}
}
}
@@ -5,6 +5,9 @@ use buckets::public::media_files::original_file::MediaFileBucketPath;
use cloud_storage::bucket_client::BucketClient;
use enums::by_table::media_files::media_file_origin_category::MediaFileOriginCategory;
use enums::by_table::media_uploads::media_upload_type::MediaUploadType;
use enums::by_table::zs_voices::encoding_type::ZsVoiceEncodingType;
use enums::by_table::zs_voices::model_category::ZsVoiceModelCategory;
use enums::by_table::zs_voices::model_type::ZsVoiceModelType;
use enums::common::visibility::Visibility;
use errors::{anyhow, AnyhowResult};
use filesys::file_read_bytes::file_read_bytes;
@@ -115,10 +118,10 @@ async fn create_voice_records(
let voice_token = create_voice(CreateVoiceArgs {
dataset_token: &dataset_token,
model_category: "vc",
model_type: "vall-e-x",
model_category: ZsVoiceModelCategory::Tts,
model_type: ZsVoiceModelType::VallEX,
model_version: 0,
model_encoding_type: "encodec",
model_encoding_type: ZsVoiceEncodingType::Encodec,
voice_title: &voice_name,
bucket_hash: &bucket_hash,
maybe_creator_user_token: Some(&creator_user_token),
@@ -2,22 +2,24 @@ use anyhow::anyhow;
use sqlx::MySqlPool;
use enums::by_table::generic_synthetic_ids::id_category::IdCategory;
use enums::by_table::zs_voices::encoding_type::ZsVoiceEncodingType;
use enums::by_table::zs_voices::model_category::ZsVoiceModelCategory;
use enums::by_table::zs_voices::model_type::ZsVoiceModelType;
use enums::common::visibility::Visibility;
use errors::AnyhowResult;
use tokens::tokens::users::UserToken;
use tokens::tokens::zs_voice_datasets::ZsVoiceDatasetToken;
use tokens::tokens::zs_voices::ZsVoiceToken;
use tokens::tokens::users::UserToken;
use crate::queries::generic_synthetic_ids::transactional_increment_generic_synthetic_id::transactional_increment_generic_synthetic_id;
pub struct CreateVoiceArgs<'a> {
pub dataset_token: &'a ZsVoiceDatasetToken,
// TODO(bt,2023-10-06): These should be *Rust Enums* to limit their possible range of values.
pub model_category: &'a str,
pub model_type: &'a str,
pub model_category: ZsVoiceModelCategory,
pub model_type: ZsVoiceModelType,
pub model_version: u64,
pub model_encoding_type: &'a str,
pub model_encoding_type: ZsVoiceEncodingType,
pub voice_title: &'a str,
// TODO(Kasisnu): Is this a create/update field?
@@ -41,7 +43,7 @@ pub async fn create_voice(args: CreateVoiceArgs<'_>) -> AnyhowResult<ZsVoiceToke
if let Some(creator_user_token) = args.maybe_creator_user_token.as_deref() {
let next_zs_dataset_synthetic_id = transactional_increment_generic_synthetic_id(
creator_user_token,
IdCategory::ZeroShotVoiceDataset,
IdCategory::ZeroShotVoiceEmbedding,
&mut transaction
).await?;
@@ -66,9 +68,9 @@ pub async fn create_voice(args: CreateVoiceArgs<'_>) -> AnyhowResult<ZsVoiceToke
"#,
voice_token.as_str(),
args.dataset_token,
args.model_category,
args.model_type,
args.model_encoding_type,
args.model_category.to_str(),
args.model_type.to_str(),
args.model_encoding_type.to_str(),
args.voice_title,
args.bucket_hash,
args.maybe_creator_user_token,
@@ -84,4 +86,4 @@ pub async fn create_voice(args: CreateVoiceArgs<'_>) -> AnyhowResult<ZsVoiceToke
Ok(_) => Ok(voice_token),
Err(err) => Err(anyhow!("zs voice creation error: {:?}", err)),
}
}
}
@@ -5,6 +5,7 @@ use sqlx::pool::PoolConnection;
use enums::common::visibility::Visibility;
use errors::AnyhowResult;
use tokens::tokens::users::UserToken;
use tokens::tokens::zs_voices::ZsVoiceToken;
pub struct ZsVoice {
@@ -13,7 +14,7 @@ pub struct ZsVoice {
pub ietf_language_tag: String,
pub ietf_primary_language_subtag: String,
pub bucket_hash: String,
pub maybe_creator_user_token: Option<String>
pub maybe_creator_user_token: Option<UserToken>
}
pub async fn get_voice_by_token(
@@ -86,7 +87,7 @@ async fn select_include_deleted(
zv.title,
zv.ietf_language_tag,
zv.ietf_primary_language_subtag,
zv.maybe_creator_user_token,
zv.maybe_creator_user_token as `maybe_creator_user_token: tokens::tokens::users::UserToken`,
zv.bucket_hash,
zv.creator_set_visibility as `creator_set_visibility: enums::common::visibility::Visibility`
FROM zs_voices as zv
@@ -110,7 +111,7 @@ async fn select_without_deleted(
zv.title,
zv.ietf_language_tag,
zv.ietf_primary_language_subtag,
zv.maybe_creator_user_token,
zv.maybe_creator_user_token as `maybe_creator_user_token: tokens::tokens::users::UserToken`,
zv.bucket_hash,
zv.creator_set_visibility as `creator_set_visibility: enums::common::visibility::Visibility`
FROM zs_voices as zv
@@ -129,7 +130,7 @@ pub struct RawVoice {
title: String,
ietf_language_tag: String,
ietf_primary_language_subtag: String,
maybe_creator_user_token: Option<String>,
maybe_creator_user_token: Option<UserToken>,
bucket_hash: String,
creator_set_visibility: Visibility,
}
@@ -6,19 +6,19 @@ use sqlx::pool::PoolConnection;
use enums::common::visibility::Visibility;
use errors::AnyhowResult;
use tokens::tokens::users::UserToken;
use tokens::tokens::zs_voices::ZsVoiceToken;
// FIXME: This is the old style of query scoping and shouldn't be copied.
#[derive(Serialize)]
pub struct VoiceRecordForList {
pub voice_token: String,
pub voice_token: ZsVoiceToken,
pub title: String,
pub creator_set_visibility: Visibility,
pub ietf_language_tag: String,
pub ietf_primary_language_subtag: String,
pub creator_user_token: String,
pub creator_user_token: UserToken,
pub creator_username: String,
pub created_at: DateTime<Utc>,
@@ -61,7 +61,7 @@ pub async fn list_voices_with_connection(
Ok(voices.into_iter()
.map(|voice| {
VoiceRecordForList{
voice_token: voice.token.to_string(),
voice_token: voice.token,
title: voice.title,
creator_set_visibility: voice.creator_set_visibility,
ietf_language_tag: voice.ietf_language_tag,
@@ -97,7 +97,7 @@ async fn list_voices_by_creator_username(
zv.title,
zv.ietf_language_tag,
zv.ietf_primary_language_subtag,
users.token as creator_user_token,
users.token as `creator_user_token: tokens::tokens::users::UserToken`,
users.username as creator_username,
zv.creator_set_visibility as `creator_set_visibility: enums::common::visibility::Visibility`,
zv.created_at,
@@ -124,7 +124,7 @@ async fn list_voices_by_creator_username(
zv.title,
zv.ietf_language_tag,
zv.ietf_primary_language_subtag,
users.token as creator_user_token,
users.token as `creator_user_token: tokens::tokens::users::UserToken`,
users.username as creator_username,
zv.creator_set_visibility as `creator_set_visibility: enums::common::visibility::Visibility`,
zv.created_at,
@@ -148,7 +148,7 @@ struct InternalRawVoiceRecordForList {
title: String,
ietf_language_tag: String,
ietf_primary_language_subtag: String,
creator_user_token: String,
creator_user_token: UserToken,
creator_username: String,
creator_set_visibility: Visibility,
created_at: DateTime<Utc>,
@@ -1,18 +1,13 @@
use anyhow::anyhow;
use sqlx::MySqlPool;
use enums::common::visibility::Visibility;
use enums::by_table::generic_synthetic_ids::id_category::IdCategory;
use enums::common::visibility::Visibility;
use errors::AnyhowResult;
use tokens::tokens::zs_voices::ZsVoiceToken;
use tokens::tokens::users::UserToken;
use crate::queries::generic_synthetic_ids::transactional_increment_generic_synthetic_id::transactional_increment_generic_synthetic_id;
pub struct UpdateVoiceArgs<'a> {
pub voice_token: &'a ZsVoiceToken,
pub voice_title: Option<&'a str>,
pub maybe_creator_user_token: Option<&'a str>,
pub creator_ip_address: &'a str,
pub creator_set_visibility: &'a Visibility,
pub maybe_mod_user_token: Option<&'a str>,
pub ietf_language_tag: Option<&'a str>,
@@ -21,54 +16,34 @@ pub struct UpdateVoiceArgs<'a> {
}
pub async fn update_voice(args: UpdateVoiceArgs<'_>) -> AnyhowResult<()>{
// TODO: enforce checks for idempotency token
let mut maybe_creator_synthetic_id : Option<u64> = None;
let mut transaction = args.mysql_pool.begin().await?;
if let Some(creator_user_token) = args.maybe_creator_user_token.as_deref() {
let user_token = UserToken::new_from_str(creator_user_token);
let next_zs_voice_synthetic_id = transactional_increment_generic_synthetic_id(
&user_token,
IdCategory::ZeroShotVoiceEmbedding,
&mut transaction
).await?;
maybe_creator_synthetic_id = Some(next_zs_voice_synthetic_id);
}
let query_result = sqlx::query!(
r#"
UPDATE zs_voices
SET
title = ?,
maybe_creator_user_token = ?,
creator_ip_address = ?,
creator_set_visibility = ?,
maybe_mod_user_token = ?,
maybe_creator_synthetic_id = ?,
ietf_language_tag = ?,
ietf_primary_language_subtag = ?,
version = version + 1
WHERE token = ?
LIMIT 1
"#,
args.voice_title,
args.maybe_creator_user_token,
args.creator_ip_address,
args.creator_set_visibility.to_str(),
args.maybe_mod_user_token,
maybe_creator_synthetic_id,
args.ietf_language_tag,
args.ietf_primary_language_subtag,
args.voice_token.as_str(),
).execute(args.mysql_pool).await;
// TODO(Kasisnu): This should probably rollback
transaction.commit().await?;
match query_result {
Ok(_) => Ok(()),
Err(err) => Err(anyhow!("zs voice update error: {:?}", err)),
}
}
}
@@ -8,6 +8,9 @@ use buckets::public::media_files::original_file::MediaFileBucketPath;
use cloud_storage::bucket_client::BucketClient;
use cloud_storage::bucket_path_unifier::BucketPathUnifier;
use enums::by_table::generic_inference_jobs::inference_result_type::InferenceResultType;
use enums::by_table::zs_voices::encoding_type::ZsVoiceEncodingType;
use enums::by_table::zs_voices::model_category::ZsVoiceModelCategory;
use enums::by_table::zs_voices::model_type::ZsVoiceModelType;
use enums::common::visibility::Visibility;
use filesys::file_size::file_size;
use hashing::sha256::sha256_hash_file::sha256_hash_file;
@@ -314,10 +317,10 @@ pub async fn process_create_voice(
// insert record
let voice_token = create_voice(CreateVoiceArgs {
dataset_token: &voice_dataset_token,
model_category: "vc",
model_type: "vall-e-x",
model_category: ZsVoiceModelCategory::Tts,
model_type: ZsVoiceModelType::VallEX,
model_version: 0,
model_encoding_type: "encodec",
model_encoding_type: ZsVoiceEncodingType::Encodec,
voice_title: &voice_name,
bucket_hash,
maybe_creator_user_token: Some(&creator_user_token),
@@ -110,8 +110,8 @@ pub async fn delete_voice_handler(
}
};
let is_creator = voice.maybe_creator_user_token.as_deref()
.map(|creator_user_token| creator_user_token == &user_session.user_token)
let is_creator = voice.maybe_creator_user_token.as_ref()
.map(|creator_user_token| creator_user_token == &user_session.user_token_typed)
.unwrap_or(false);
if !is_creator && !is_mod {
@@ -1,6 +1,4 @@
use std::fmt;
use std::fmt::{Formatter};
use std::sync::Arc;
use actix_web::{HttpRequest, HttpResponse, web};
@@ -8,20 +6,22 @@ use actix_web::error::ResponseError;
use actix_web::http::StatusCode;
use actix_web::web::Path;
use chrono::{DateTime, Utc};
use log::warn;
use log::{info, warn};
use mysql_queries::queries::voice_designer::voices::list_voices::list_voices_by_user_token;
use tokens::tokens::users::UserToken;
use tokens::tokens::zs_voices::ZsVoiceToken;
use crate::server_state::ServerState;
#[derive(Serialize, Clone)]
pub struct ZsVoiceRecordForResponse {
voice_token: String,
voice_token: ZsVoiceToken,
title: String,
creator_set_visibility: String,
ietf_language_tag: String,
ietf_primary_language_subtag: String,
creator_user_token: String,
creator_user_token: UserToken,
creator_username: String,
created_at: DateTime<Utc>,
@@ -5,13 +5,11 @@ use actix_web::{HttpRequest, HttpResponse, web};
use actix_web::error::ResponseError;
use actix_web::http::StatusCode;
use actix_web::web::Path;
use log::{error, log, warn};
use enums::common::visibility::Visibility;
use log::{error, warn};
use http_server_common::request::get_request_ip::get_request_ip;
use enums::common::visibility::Visibility;
use http_server_common::response::response_success_helpers::simple_json_success;
use http_server_common::response::serialize_as_json_error::serialize_as_json_error;
use mysql_queries::queries::voice_designer::voices::create_voice::{create_voice, CreateVoiceArgs};
use mysql_queries::queries::voice_designer::voices::get_voice::get_voice_by_token;
use mysql_queries::queries::voice_designer::voices::update_voice::{update_voice, UpdateVoiceArgs};
use tokens::tokens::zs_voices::ZsVoiceToken;
@@ -119,8 +117,8 @@ pub async fn update_voice_handler(
};
// let is_creator = voice.maybe_creator_user_token == Some(user_session.user_token);
let is_creator = voice.maybe_creator_user_token.as_deref()
.map(|creator_user_token| creator_user_token == &user_session.user_token)
let is_creator = voice.maybe_creator_user_token.as_ref()
.map(|creator_user_token| creator_user_token == &user_session.user_token_typed)
.unwrap_or(false);
if !is_creator && !is_mod {
@@ -170,18 +168,16 @@ pub async fn update_voice_handler(
}
let ip_address = get_request_ip(&http_request);
let mut maybe_mod_user_token = None;
if is_mod {
maybe_mod_user_token = Some(user_session.user_token.clone());
}
let query_result = update_voice(
UpdateVoiceArgs {
voice_token: &ZsVoiceToken::new(voice_token.clone()),
voice_title: title.as_deref(),
maybe_creator_user_token: Some(user_session.user_token.clone().as_ref()),
creator_ip_address: ip_address.as_ref(),
creator_set_visibility: &creator_set_visibility,
maybe_mod_user_token: maybe_mod_user_token.as_deref(),
ietf_language_tag: ietf_language_tag.as_deref(),