mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-05 01:38:44 +00:00
get rid of more legacy tokens
This commit is contained in:
1 parent
9b5bb16358
commit
92c76d2bb9
17 files changed
+104
-53
No files matched your search
@@ -14,6 +14,8 @@ use strum::EnumIter;
|
||||
#[cfg_attr(test, derive(EnumIter, EnumCount))]
|
||||
pub(crate) enum EntityType {
|
||||
AnonymousVisitorTracking, // AVTs are not stored as primary keys in any table, but an index in many tables.
|
||||
ApiTokenExternal,
|
||||
ApiTokenInternal,
|
||||
AuditLog,
|
||||
Comment,
|
||||
DownloadJob,
|
||||
@@ -24,13 +26,16 @@ pub(crate) enum EntityType {
|
||||
NewsStory, // NB: aichatbot / sqlite
|
||||
TtsModel,
|
||||
TtsRenderTask, // NB: aichatbot / sqlite
|
||||
TtsResult,
|
||||
TwitchEventRule,
|
||||
TwitchOauthGrouping,
|
||||
TwitchOauthInternal,
|
||||
User,
|
||||
UserSession,
|
||||
VocoderModel,
|
||||
VoiceConversionModel,
|
||||
VoiceConversionResult,
|
||||
W2lResult,
|
||||
W2lTemplate,
|
||||
ZsVoice,
|
||||
ZsVoiceDataset,
|
||||
@@ -44,6 +49,8 @@ impl EntityType {
|
||||
pub fn prefix(self) -> &'static str {
|
||||
match self {
|
||||
Self::AnonymousVisitorTracking => "avt_",
|
||||
Self::ApiTokenExternal => "API:", // NB: Old-style prefix, do not use for future tokens.
|
||||
Self::ApiTokenInternal => "INT_API:", // NB: Old-style prefix, do not use for future tokens.
|
||||
Self::AuditLog => "audit_",
|
||||
Self::Comment => "comment_",
|
||||
Self::DownloadJob => "jdown_", // NB: Was "JGUP:"
|
||||
@@ -54,13 +61,16 @@ impl EntityType {
|
||||
Self::NewsStory => "news_story_",
|
||||
Self::TtsModel => "TM:", // NB: Old-style prefix, do not use for future tokens.
|
||||
Self::TtsRenderTask => "tts_task_",
|
||||
Self::TtsResult => "TR:", // NB: Old-style prefix, do not use for future tokens.
|
||||
Self::TwitchEventRule => "TER:", // NB: Old-style prefix, do not use for future tokens.
|
||||
Self::TwitchOauthGrouping => "OG:", // NB: Old-style prefix, do not use for future tokens.
|
||||
Self::TwitchOauthInternal => "TOI:", // NB: Old-style prefix, do not use for future tokens.
|
||||
Self::User => "user_",
|
||||
Self::UserSession => "session_",
|
||||
Self::VocoderModel => "VM:", // NB: Old-style prefix, do not use for future tokens.
|
||||
Self::VoiceConversionModel => "vcm_",
|
||||
Self::VoiceConversionResult => "vcr_",
|
||||
Self::W2lResult => "WR:", // NB: Old-style prefix, do not use for future tokens.
|
||||
Self::W2lTemplate => "WT:", // NB: Old-style prefix, do not use for future tokens.
|
||||
Self::ZsVoice => "zsv_",
|
||||
Self::ZsVoiceDataset => "zsd_",
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
use std::fmt::Debug;
|
||||
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::prefixes::EntityType;
|
||||
|
||||
/// External-facing key for the `api_tokens` table.
|
||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, sqlx::Type, Debug, Serialize, Deserialize)]
|
||||
#[sqlx(transparent)]
|
||||
pub struct ApiTokenExternal(pub String);
|
||||
|
||||
impl_string_token!(ApiTokenExternal);
|
||||
impl_crockford_generator!(ApiTokenExternal, 32usize, EntityType::ApiTokenExternal, CrockfordUpper);
|
||||
@@ -0,0 +1,14 @@
|
||||
use std::fmt::Debug;
|
||||
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::prefixes::EntityType;
|
||||
|
||||
/// Internal token for the `api_tokens` table.
|
||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, sqlx::Type, Debug, Serialize, Deserialize)]
|
||||
#[sqlx(transparent)]
|
||||
pub struct ApiTokenInternal(pub String);
|
||||
|
||||
impl_string_token!(ApiTokenInternal);
|
||||
impl_crockford_generator!(ApiTokenInternal, 32usize, EntityType::ApiTokenInternal, CrockfordLower);
|
||||
@@ -1,4 +1,6 @@
|
||||
pub mod anonymous_visitor_tracking;
|
||||
pub mod api_tokens_external;
|
||||
pub mod api_tokens_internal;
|
||||
pub mod audit_logs;
|
||||
pub mod comments;
|
||||
pub mod generic_download_jobs;
|
||||
@@ -8,13 +10,16 @@ pub mod media_uploads;
|
||||
pub mod model_categories;
|
||||
pub mod sqlite;
|
||||
pub mod tts_models;
|
||||
pub mod tts_results;
|
||||
pub mod twitch_event_rule;
|
||||
pub mod twitch_oauth_tokens_grouping;
|
||||
pub mod twitch_oauth_tokens_internal;
|
||||
pub mod user_sessions;
|
||||
pub mod users;
|
||||
pub mod vocoder_model_token;
|
||||
pub mod voice_conversion_models;
|
||||
pub mod voice_conversion_results;
|
||||
pub mod w2l_results;
|
||||
pub mod w2l_templates;
|
||||
pub mod zs_voice_dataset_samples;
|
||||
pub mod zs_voice_datasets;
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
use std::fmt::Debug;
|
||||
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::prefixes::EntityType;
|
||||
|
||||
/// Primary key for the `tts_results` table.
|
||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, sqlx::Type, Debug, Serialize, Deserialize)]
|
||||
#[sqlx(transparent)]
|
||||
pub struct TtsResultToken(pub String);
|
||||
|
||||
impl_string_token!(TtsResultToken);
|
||||
impl_crockford_generator!(TtsResultToken, 32usize, EntityType::TtsResult, CrockfordLower);
|
||||
@@ -0,0 +1,14 @@
|
||||
use std::fmt::Debug;
|
||||
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::prefixes::EntityType;
|
||||
|
||||
/// The primary key for the `vocoder_models` table
|
||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, sqlx::Type, Debug, Serialize, Deserialize)]
|
||||
#[sqlx(transparent)]
|
||||
pub struct VocoderModelToken(pub String);
|
||||
|
||||
impl_string_token!(VocoderModelToken);
|
||||
impl_crockford_generator!(VocoderModelToken, 15usize, EntityType::VocoderModel, CrockfordLower);
|
||||
@@ -0,0 +1,14 @@
|
||||
use std::fmt::Debug;
|
||||
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::prefixes::EntityType;
|
||||
|
||||
/// Primary key for the `w2l_results` table.
|
||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, sqlx::Type, Debug, Serialize, Deserialize)]
|
||||
#[sqlx(transparent)]
|
||||
pub struct W2lResultToken(pub String);
|
||||
|
||||
impl_string_token!(W2lResultToken);
|
||||
impl_crockford_generator!(W2lResultToken, 32usize, EntityType::W2lResult, CrockfordLower);
|
||||
@@ -3,9 +3,10 @@ use sqlx;
|
||||
use sqlx::MySqlPool;
|
||||
|
||||
use errors::AnyhowResult;
|
||||
use tokens::tokens::api_tokens_external::ApiTokenExternal;
|
||||
use tokens::tokens::api_tokens_internal::ApiTokenInternal;
|
||||
|
||||
use crate::queries::api_tokens::list_available_api_tokens_for_user::list_available_api_tokens_for_user;
|
||||
use crate::tokens::Tokens;
|
||||
|
||||
/// Create a new API token for the user.
|
||||
/// If the user has more than five tokens, delete the least recent.
|
||||
@@ -18,8 +19,8 @@ pub async fn create_api_token_for_user(
|
||||
|
||||
// TODO: Database transaction.
|
||||
|
||||
let internal_token = Tokens::new_api_token_internal_token()?;
|
||||
let api_token = Tokens::new_api_token()?;
|
||||
let internal_token = ApiTokenInternal::generate().to_string();
|
||||
let api_token = ApiTokenExternal::generate().to_string();
|
||||
|
||||
let query = sqlx::query!(
|
||||
r#"
|
||||
|
||||
+2
-3
@@ -5,8 +5,7 @@ use chrono::Utc;
|
||||
use sqlx::MySqlPool;
|
||||
|
||||
use errors::AnyhowResult;
|
||||
|
||||
use crate::tokens::Tokens;
|
||||
use tokens::tokens::tts_models::TtsModelToken;
|
||||
|
||||
/// table: tts_model_upload_jobs
|
||||
#[derive(Debug)]
|
||||
@@ -204,7 +203,7 @@ pub async fn insert_tts_model<P: AsRef<Path>>(
|
||||
file_size_bytes: u64
|
||||
) -> AnyhowResult<(u64, String)> {
|
||||
|
||||
let model_token = Tokens::new_tts_model()?;
|
||||
let model_token = TtsModelToken::generate().to_string();
|
||||
|
||||
let private_bucket_object_name = &private_bucket_object_name
|
||||
.as_ref()
|
||||
|
||||
+2
-3
@@ -6,8 +6,7 @@ use sqlx::MySqlPool;
|
||||
use enums::by_table::tts_models::tts_model_type::TtsModelType;
|
||||
use enums::common::visibility::Visibility;
|
||||
use errors::AnyhowResult;
|
||||
|
||||
use crate::tokens::Tokens;
|
||||
use tokens::tokens::tts_models::TtsModelToken;
|
||||
|
||||
pub struct InsertTtsModelFromDownloadJobArgs<'a, P: AsRef<Path>> {
|
||||
pub tts_model_type: TtsModelType,
|
||||
@@ -33,7 +32,7 @@ pub async fn insert_tts_model_from_download_job<P: AsRef<Path>>(
|
||||
args: InsertTtsModelFromDownloadJobArgs<'_, P>,
|
||||
) -> AnyhowResult<(u64, String)> {
|
||||
|
||||
let model_token = Tokens::new_tts_model()?;
|
||||
let model_token = TtsModelToken::generate().to_string();
|
||||
|
||||
let private_bucket_object_name = &args.private_bucket_object_name
|
||||
.as_ref()
|
||||
|
||||
@@ -6,11 +6,11 @@ use sqlx;
|
||||
use sqlx::MySqlPool;
|
||||
|
||||
use errors::AnyhowResult;
|
||||
use tokens::tokens::tts_results::TtsResultToken;
|
||||
|
||||
use crate::column_types::vocoder_type::VocoderType;
|
||||
use crate::queries::generic_inference::job::list_available_generic_inference_jobs::AvailableInferenceJob;
|
||||
use crate::queries::tts::tts_inference_jobs::list_available_tts_inference_jobs::AvailableTtsInferenceJob;
|
||||
use crate::tokens::Tokens;
|
||||
|
||||
/// Used to give user-facing order to logged in user inference requests
|
||||
pub struct SyntheticIdRecord {
|
||||
@@ -37,7 +37,7 @@ pub async fn insert_tts_result<P: AsRef<Path>>(
|
||||
is_debug_worker: bool,
|
||||
) -> AnyhowResult<(u64, String)>
|
||||
{
|
||||
let inference_result_token = Tokens::new_tts_result()?;
|
||||
let inference_result_token = TtsResultToken::generate().to_string();
|
||||
|
||||
let bucket_audio_result_path = &bucket_audio_results_path
|
||||
.as_ref()
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ impl InsertTwitchEventRuleBuilder {
|
||||
/// Returns the newly generated token.
|
||||
pub async fn insert(&self, mysql_pool: &MySqlPool) -> AnyhowResult<String> {
|
||||
|
||||
let token = TwitchEventRuleToken::generate();
|
||||
let token = TwitchEventRuleToken::generate().to_string();
|
||||
|
||||
let query = sqlx::query!(
|
||||
r#"
|
||||
|
||||
@@ -8,7 +8,7 @@ use tokens::tokens::user_sessions::UserSessionToken;
|
||||
pub async fn create_user_session(user_token: &str, ip_address: &str, mysql_pool: &MySqlPool)
|
||||
-> AnyhowResult<String>
|
||||
{
|
||||
let session_token = UserSessionToken::generate();
|
||||
let session_token = UserSessionToken::generate().to_string();
|
||||
|
||||
let query_result = sqlx::query!(
|
||||
r#"
|
||||
@@ -20,7 +20,7 @@ INSERT INTO user_sessions (
|
||||
)
|
||||
VALUES ( ?, ?, ?, NOW() + interval 1 year )
|
||||
"#,
|
||||
session_token.to_string(),
|
||||
session_token,
|
||||
user_token.to_string(),
|
||||
ip_address.to_string(),
|
||||
)
|
||||
|
||||
@@ -11,8 +11,7 @@ use sqlx::MySqlPool;
|
||||
use enums::common::visibility::Visibility;
|
||||
use enums::common::vocoder_type::VocoderType;
|
||||
use errors::AnyhowResult;
|
||||
|
||||
use crate::tokens::Tokens;
|
||||
use tokens::tokens::vocoder_model_token::VocoderModelToken;
|
||||
|
||||
pub struct Args<'a, P: AsRef<Path>> {
|
||||
pub vocoder_type: VocoderType,
|
||||
@@ -37,7 +36,7 @@ pub async fn insert_vocoder_model<P: AsRef<Path>>(
|
||||
args: Args<'_, P>,
|
||||
) -> AnyhowResult<(u64, String)> {
|
||||
|
||||
let model_token = Tokens::new_vocoder_model()?;
|
||||
let model_token = VocoderModelToken::generate().to_string();
|
||||
|
||||
let private_bucket_object_name = &args.private_bucket_object_name
|
||||
.as_ref()
|
||||
|
||||
+2
-3
@@ -7,8 +7,7 @@ use chrono::Utc;
|
||||
use sqlx::MySqlPool;
|
||||
|
||||
use errors::AnyhowResult;
|
||||
|
||||
use crate::tokens::Tokens;
|
||||
use tokens::tokens::w2l_templates::W2lTemplateToken;
|
||||
|
||||
// TODO(2022-08-04): These were moved into the 'mysql_queries' crate, but they need
|
||||
// to be split up into several modules for better maintainability. cf the already moved
|
||||
@@ -243,7 +242,7 @@ pub async fn insert_w2l_template(
|
||||
duration_millis: u64
|
||||
) -> AnyhowResult<(u64, String)> {
|
||||
|
||||
let model_token = Tokens::new_w2l_template()?;
|
||||
let model_token = W2lTemplateToken::generate().to_string();
|
||||
|
||||
let query_result = sqlx::query!(
|
||||
r#"
|
||||
|
||||
+2
-3
@@ -11,8 +11,7 @@ use sqlx::MySqlPool;
|
||||
|
||||
use enums::common::visibility::Visibility;
|
||||
use errors::AnyhowResult;
|
||||
|
||||
use crate::tokens::Tokens;
|
||||
use tokens::tokens::w2l_results::W2lResultToken;
|
||||
|
||||
// TODO(2022-08-04): These were moved into the 'mysql_queries' crate, but they need
|
||||
// to be split up into several modules for better maintainability. cf the already moved
|
||||
@@ -264,7 +263,7 @@ pub async fn insert_w2l_result<P: AsRef<Path>>(
|
||||
duration_millis: u64
|
||||
) -> AnyhowResult<(u64, String)>
|
||||
{
|
||||
let inference_result_token = Tokens::new_w2l_result()?;
|
||||
let inference_result_token = W2lResultToken::generate().to_string();
|
||||
|
||||
let bucket_video_result_path = &bucket_video_results_path
|
||||
.as_ref()
|
||||
|
||||
@@ -8,32 +8,6 @@ pub struct Tokens;
|
||||
|
||||
impl Tokens {
|
||||
|
||||
// ========== Tokens with high visibility (make these nice) ==========
|
||||
|
||||
pub fn new_tts_model() -> AnyhowResult<String> {
|
||||
random_prefix_crockford_token("TM:", 15, false)
|
||||
}
|
||||
|
||||
pub fn new_vocoder_model() -> AnyhowResult<String> {
|
||||
random_prefix_crockford_token("VM:", 15, false)
|
||||
}
|
||||
|
||||
pub fn new_tts_result() -> AnyhowResult<String> {
|
||||
random_prefix_crockford_token("TR:", 32, false)
|
||||
}
|
||||
|
||||
pub fn new_w2l_template() -> AnyhowResult<String> {
|
||||
random_prefix_crockford_token("WT:", 32, false)
|
||||
}
|
||||
|
||||
pub fn new_w2l_result() -> AnyhowResult<String> {
|
||||
random_prefix_crockford_token("WR:", 32, false)
|
||||
}
|
||||
|
||||
pub fn new_api_token() -> AnyhowResult<String> {
|
||||
random_prefix_crockford_token("API:", 32, true)
|
||||
}
|
||||
|
||||
// ========== Tokens not typically visible to users ==========
|
||||
|
||||
pub fn new_tts_model_upload_job() -> AnyhowResult<String> {
|
||||
@@ -64,10 +38,6 @@ impl Tokens {
|
||||
random_prefix_crockford_token("CAT:", 15, false)
|
||||
}
|
||||
|
||||
pub fn new_api_token_internal_token() -> AnyhowResult<String> {
|
||||
random_prefix_crockford_token("INT_API:", 32, false)
|
||||
}
|
||||
|
||||
// ========== [Billing] Tokens not typically visible to users ==========
|
||||
|
||||
pub fn new_subscription_token() -> AnyhowResult<String> {
|
||||
|
||||
Reference in new issue
Block a user