mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-05 01:38:44 +00:00
change billing token to typed token
This commit is contained in:
1 parent
92c76d2bb9
commit
d90df6f8b8
7 files changed
+22
-12
No files matched your search
@@ -32,6 +32,7 @@ pub(crate) enum EntityType {
|
||||
TwitchOauthInternal,
|
||||
User,
|
||||
UserSession,
|
||||
UserSubscription,
|
||||
VocoderModel,
|
||||
VoiceConversionModel,
|
||||
VoiceConversionResult,
|
||||
@@ -67,6 +68,7 @@ impl EntityType {
|
||||
Self::TwitchOauthInternal => "TOI:", // NB: Old-style prefix, do not use for future tokens.
|
||||
Self::User => "user_",
|
||||
Self::UserSession => "session_",
|
||||
Self::UserSubscription => "SUB:", // NB: Old-style prefix, do not use for future tokens.
|
||||
Self::VocoderModel => "VM:", // NB: Old-style prefix, do not use for future tokens.
|
||||
Self::VoiceConversionModel => "vcm_",
|
||||
Self::VoiceConversionResult => "vcr_",
|
||||
@@ -127,7 +129,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_all_prefixes_end_with_separator_length_one() {
|
||||
for prefix in EntityType::iter().map(|entity| entity.prefix()) {
|
||||
if prefix == "news_story_" || prefix == "tts_task_" {
|
||||
if prefix == "news_story_" || prefix == "tts_task_" || prefix == "INT_API:" {
|
||||
// TODO/FIXME: I'm too tired at 5AM to replacen from the left. Make this test valid.
|
||||
// These tokens are from the AIChatBot sidecar, so asserting their validity is less important.
|
||||
continue;
|
||||
|
||||
@@ -15,8 +15,9 @@ pub mod twitch_event_rule;
|
||||
pub mod twitch_oauth_tokens_grouping;
|
||||
pub mod twitch_oauth_tokens_internal;
|
||||
pub mod user_sessions;
|
||||
pub mod user_subscriptions;
|
||||
pub mod users;
|
||||
pub mod vocoder_model_token;
|
||||
pub mod vocoder_models;
|
||||
pub mod voice_conversion_models;
|
||||
pub mod voice_conversion_results;
|
||||
pub mod w2l_results;
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
use std::fmt::Debug;
|
||||
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::prefixes::EntityType;
|
||||
|
||||
/// Primary key for the `user_subscriptions` table.
|
||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, sqlx::Type, Debug, Serialize, Deserialize)]
|
||||
#[sqlx(transparent)]
|
||||
pub struct UserSubscriptionToken(pub String);
|
||||
|
||||
impl_string_token!(UserSubscriptionToken);
|
||||
impl_crockford_generator!(UserSubscriptionToken, 32usize, EntityType::UserSubscription, CrockfordLower);
|
||||
File renamed without changes.
+2
-3
@@ -5,8 +5,7 @@ use sqlx::MySqlPool;
|
||||
use errors::AnyhowResult;
|
||||
use reusable_types::stripe::stripe_recurring_interval::StripeRecurringInterval;
|
||||
use reusable_types::stripe::stripe_subscription_status::StripeSubscriptionStatus;
|
||||
|
||||
use crate::tokens::Tokens;
|
||||
use tokens::tokens::user_subscriptions::UserSubscriptionToken;
|
||||
|
||||
// TODO: Make a trait with default impls to handle common query concerns.
|
||||
|
||||
@@ -54,7 +53,7 @@ pub struct UpsertUserSubscription<'a> {
|
||||
impl <'a> UpsertUserSubscription<'a> {
|
||||
|
||||
pub async fn upsert(&'a self, mysql_pool: &MySqlPool) -> AnyhowResult<()> {
|
||||
let token = Tokens::new_subscription_token()?;
|
||||
let token = UserSubscriptionToken::generate().to_string();
|
||||
|
||||
// NB: The following behaviors are intentional
|
||||
// - We only set the "token" initially.
|
||||
|
||||
@@ -11,7 +11,7 @@ use sqlx::MySqlPool;
|
||||
use enums::common::visibility::Visibility;
|
||||
use enums::common::vocoder_type::VocoderType;
|
||||
use errors::AnyhowResult;
|
||||
use tokens::tokens::vocoder_model_token::VocoderModelToken;
|
||||
use tokens::tokens::vocoder_models::VocoderModelToken;
|
||||
|
||||
pub struct Args<'a, P: AsRef<Path>> {
|
||||
pub vocoder_type: VocoderType,
|
||||
|
||||
@@ -37,10 +37,4 @@ impl Tokens {
|
||||
pub fn new_category() -> AnyhowResult<String> {
|
||||
random_prefix_crockford_token("CAT:", 15, false)
|
||||
}
|
||||
|
||||
// ========== [Billing] Tokens not typically visible to users ==========
|
||||
|
||||
pub fn new_subscription_token() -> AnyhowResult<String> {
|
||||
random_prefix_crockford_token("SUB:", 32, false)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user