mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-06 02:00:46 +00:00
wallets -> credits routes instead
This commit is contained in:
1 parent
2de4d9d9e9
commit
4bb3f6af2d
16 files changed
+117
-90
No files matched your search
@@ -0,0 +1,20 @@
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use utoipa::ToSchema;
|
||||
|
||||
#[derive(Serialize, Deserialize, ToSchema)]
|
||||
pub struct GetSessionCreditsResponse {
|
||||
pub success: bool,
|
||||
|
||||
/// Any free credits the user might have
|
||||
/// We might support daily free credits.
|
||||
pub free_credits: u64,
|
||||
|
||||
/// Any monthly refilling credits the user might have
|
||||
pub monthly_credits: u64,
|
||||
|
||||
/// Any banked credits the user might have.
|
||||
pub banked_credits: u64,
|
||||
|
||||
/// All the credit amounts added together.
|
||||
pub sum_total_credits: u64,
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
pub mod get_session_credits;
|
||||
@@ -1,7 +1,7 @@
|
||||
pub mod common;
|
||||
pub mod credits;
|
||||
pub mod generate;
|
||||
pub mod jobs;
|
||||
pub mod media_file;
|
||||
pub mod prompts;
|
||||
pub mod stripe_artcraft;
|
||||
pub mod wallets;
|
||||
pub mod stripe_artcraft;
|
||||
@@ -1,20 +0,0 @@
|
||||
use enums::common::payments_namespace::PaymentsNamespace;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use tokens::tokens::wallets::WalletToken;
|
||||
use utoipa::ToSchema;
|
||||
|
||||
#[derive(Serialize, Deserialize, ToSchema)]
|
||||
pub struct GetPrimaryWalletForUserResponse {
|
||||
pub success: bool,
|
||||
|
||||
/// The primary wallet, if it exists.
|
||||
pub maybe_primary_wallet: Option<WalletDetails>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, ToSchema)]
|
||||
pub struct WalletDetails {
|
||||
pub token: WalletToken,
|
||||
pub namespace: PaymentsNamespace,
|
||||
pub banked_credits: u64,
|
||||
pub monthly_credits: u64,
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
pub mod get_primary_wallet_for_user;
|
||||
+4
-7
@@ -2,18 +2,15 @@ use crate::credentials::storyteller_credential_set::StorytellerCredentialSet;
|
||||
use crate::error::storyteller_error::StorytellerError;
|
||||
use crate::utils::api_host::ApiHost;
|
||||
use crate::utils::basic_json_get_request::basic_json_get_request;
|
||||
use crate::utils::basic_json_post_request::basic_json_post_request;
|
||||
use artcraft_api_defs::media_file::list_batch_generated_media_files::LIST_BATCH_GENERATED_REDUX_MEDIA_FILES_URL_PATH;
|
||||
use artcraft_api_defs::stripe_artcraft::create_credits_pack_checkout::{StripeArtcraftCreateCreditsPackCheckoutRequest, StripeArtcraftCreateCreditsPackCheckoutResponse, CREATE_CREDITS_PACK_CHECKOUT_URL_PATH};
|
||||
use artcraft_api_defs::wallets::get_primary_wallet_for_user::GetPrimaryWalletForUserResponse;
|
||||
use artcraft_api_defs::credits::get_session_credits::GetSessionCreditsResponse;
|
||||
use enums::common::payments_namespace::PaymentsNamespace;
|
||||
use log::debug;
|
||||
|
||||
pub async fn get_primary_wallet_for_user(
|
||||
pub async fn get_session_credits(
|
||||
api_host: &ApiHost,
|
||||
maybe_creds: Option<&StorytellerCredentialSet>,
|
||||
payments_namespace: PaymentsNamespace
|
||||
) -> Result<GetPrimaryWalletForUserResponse, StorytellerError> {
|
||||
) -> Result<GetSessionCreditsResponse, StorytellerError> {
|
||||
let url = get_url(api_host, payments_namespace);
|
||||
|
||||
debug!("Requesting {:?}", &url);
|
||||
@@ -29,6 +26,6 @@ pub async fn get_primary_wallet_for_user(
|
||||
fn get_url(api_host: &ApiHost, payments_namespace: PaymentsNamespace) -> String {
|
||||
let api_hostname_and_scheme = api_host.to_api_hostname_and_scheme();
|
||||
let payments_namespace = payments_namespace.to_str();
|
||||
format!("{}/v1/wallets/primary_wallet/{}", api_hostname_and_scheme, payments_namespace)
|
||||
format!("{}/v1/credits/{}", api_hostname_and_scheme, payments_namespace)
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
pub mod get_session_credits;
|
||||
@@ -1,6 +1,7 @@
|
||||
//! An API client for Storyteller / FakeYou
|
||||
|
||||
pub mod credentials;
|
||||
pub mod credits;
|
||||
pub mod error;
|
||||
pub mod generate;
|
||||
pub mod jobs;
|
||||
@@ -9,4 +10,3 @@ pub mod prompts;
|
||||
pub mod recipes;
|
||||
pub mod stripe_artcraft;
|
||||
pub mod utils;
|
||||
pub mod wallets;
|
||||
@@ -1 +0,0 @@
|
||||
pub mod get_primary_wallet_for_user;
|
||||
+31
-28
@@ -3,23 +3,12 @@ use std::sync::Arc;
|
||||
|
||||
use crate::http_server::common_responses::common_web_error::CommonWebError;
|
||||
use crate::http_server::common_responses::media::media_links_builder::MediaLinksBuilder;
|
||||
use crate::http_server::endpoints::media_files::helpers::get_media_domain::get_media_domain;
|
||||
use crate::http_server::web_utils::response_error_helpers::to_simple_json_error;
|
||||
use crate::state::server_state::ServerState;
|
||||
use actix_web::error::ResponseError;
|
||||
use actix_web::http::StatusCode;
|
||||
use actix_web::web::{Json, Path};
|
||||
use actix_web::{web, HttpMessage, HttpRequest, HttpResponse};
|
||||
use artcraft_api_defs::common::responses::media_links::MediaLinks;
|
||||
use artcraft_api_defs::wallets::get_primary_wallet_for_user::{GetPrimaryWalletForUserResponse, WalletDetails};
|
||||
use bucket_paths::legacy::typified_paths::public::media_files::bucket_file_path::MediaFileBucketPath;
|
||||
use artcraft_api_defs::credits::get_session_credits::GetSessionCreditsResponse;
|
||||
use chrono::{DateTime, Utc};
|
||||
use enums::by_table::prompt_context_items::prompt_context_semantic_type::PromptContextSemanticType;
|
||||
use enums::by_table::prompts::prompt_type::PromptType;
|
||||
use enums::common::generation_provider::GenerationProvider;
|
||||
use enums::common::model_type::ModelType;
|
||||
use enums::common::payments_namespace::PaymentsNamespace;
|
||||
use enums::no_table::style_transfer::style_transfer_name::StyleTransferName;
|
||||
use log::{error, warn};
|
||||
use mysql_queries::queries::prompt_context_items::list_prompt_context_items::list_prompt_context_items;
|
||||
use mysql_queries::queries::prompts::get_prompt::{get_prompt, get_prompt_from_connection};
|
||||
@@ -30,26 +19,26 @@ use utoipa::ToSchema;
|
||||
|
||||
/// For the URL PathInfo
|
||||
#[derive(Deserialize, ToSchema)]
|
||||
pub struct GetPrimaryWalletForUserPathInfo {
|
||||
pub struct GetSessionCreditsPathInfo {
|
||||
namespace: PaymentsNamespace,
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
tag = "Wallets",
|
||||
path = "/v1/wallets/primary_wallet/{namespace}",
|
||||
tag = "Credits",
|
||||
path = "/v1/credits/namespace/{namespace}",
|
||||
responses(
|
||||
(status = 200, description = "Success", body = GetPrimaryWalletForUserResponse),
|
||||
(status = 200, description = "Success", body = GetSessionCreditsResponse),
|
||||
),
|
||||
params(
|
||||
("path" = GetPromptPathInfo, description = "Path for Request")
|
||||
("path" = GetSessionCreditsPathInfo, description = "Path for Request")
|
||||
)
|
||||
)]
|
||||
pub async fn get_prompt_handler(
|
||||
pub async fn get_session_credits_handler(
|
||||
http_request: HttpRequest,
|
||||
path: Path<GetPrimaryWalletForUserPathInfo>,
|
||||
path: Path<GetSessionCreditsPathInfo>,
|
||||
server_state: web::Data<Arc<ServerState>>
|
||||
) -> Result<Json<GetPrimaryWalletForUserResponse>, CommonWebError>
|
||||
) -> Result<Json<GetSessionCreditsResponse>, CommonWebError>
|
||||
{
|
||||
let mut mysql_connection = server_state.mysql_pool
|
||||
.acquire()
|
||||
@@ -67,7 +56,7 @@ pub async fn get_prompt_handler(
|
||||
warn!("Session checker error: {:?}", e);
|
||||
CommonWebError::ServerError
|
||||
})?;
|
||||
|
||||
|
||||
let user_token = match maybe_user_session {
|
||||
Some(session) => session.user_token,
|
||||
None => return Err(CommonWebError::NotAuthorized),
|
||||
@@ -82,13 +71,27 @@ pub async fn get_prompt_handler(
|
||||
CommonWebError::ServerError
|
||||
})?;
|
||||
|
||||
Ok(Json(GetPrimaryWalletForUserResponse {
|
||||
let free_credits = 0u64;
|
||||
|
||||
let monthly_credits = maybe_wallet
|
||||
.as_ref()
|
||||
.map(|w| w.monthly_credits)
|
||||
.unwrap_or(0);
|
||||
|
||||
let banked_credits = maybe_wallet
|
||||
.as_ref()
|
||||
.map(|w| w.banked_credits)
|
||||
.unwrap_or(0);
|
||||
|
||||
let sum_total_credits = free_credits
|
||||
.saturating_add(monthly_credits)
|
||||
.saturating_add(banked_credits);
|
||||
|
||||
Ok(Json(GetSessionCreditsResponse {
|
||||
success: true,
|
||||
maybe_primary_wallet: maybe_wallet.map(|wallet| WalletDetails {
|
||||
token: wallet.token,
|
||||
namespace: wallet.namespace,
|
||||
banked_credits: wallet.banked_credits,
|
||||
monthly_credits: wallet.monthly_credits,
|
||||
})
|
||||
free_credits,
|
||||
monthly_credits,
|
||||
banked_credits,
|
||||
sum_total_credits,
|
||||
}))
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
pub mod get_session_credits_handler;
|
||||
@@ -2,6 +2,7 @@ pub mod analytics;
|
||||
pub mod app_state;
|
||||
pub mod beta_keys;
|
||||
pub mod comments;
|
||||
pub mod credits;
|
||||
pub mod download_job;
|
||||
pub mod featured_items;
|
||||
pub mod generate;
|
||||
@@ -25,6 +26,5 @@ pub mod users;
|
||||
pub mod voice_clone_requests;
|
||||
pub mod voice_conversion;
|
||||
pub mod voice_designer;
|
||||
pub mod wallets;
|
||||
pub mod webhooks;
|
||||
pub mod weights;
|
||||
@@ -1 +0,0 @@
|
||||
pub mod get_primary_wallet_for_user_handler;
|
||||
@@ -0,0 +1,24 @@
|
||||
use crate::http_server::endpoints::credits::get_session_credits_handler::get_session_credits_handler;
|
||||
use actix_http::body::MessageBody;
|
||||
use actix_service::ServiceFactory;
|
||||
use actix_web::dev::{ServiceRequest, ServiceResponse};
|
||||
use actix_web::{web, App, Error, HttpResponse};
|
||||
|
||||
pub fn add_credits_routes<T, B> (app: App<T>) -> App<T>
|
||||
where
|
||||
B: MessageBody,
|
||||
T: ServiceFactory<
|
||||
ServiceRequest,
|
||||
Config = (),
|
||||
Response = ServiceResponse<B>,
|
||||
Error = Error,
|
||||
InitError = (),
|
||||
>,
|
||||
{
|
||||
app.service(web::scope("/v1/credits")
|
||||
.service(web::resource("/namespace/{namespace}")
|
||||
.route(web::post().to(get_session_credits_handler))
|
||||
.route(web::head().to(|| HttpResponse::Ok()))
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -125,6 +125,7 @@ use crate::http_server::endpoints::voice_designer::voices::list_voices_by_user::
|
||||
use crate::http_server::endpoints::voice_designer::voices::search_voices::search_voices;
|
||||
use crate::http_server::endpoints::voice_designer::voices::update_voice::update_voice_handler;
|
||||
use crate::http_server::routes::add_control_plane_routes::add_control_plane_routes;
|
||||
use crate::http_server::routes::add_credits_routes::add_credits_routes;
|
||||
use crate::http_server::routes::add_generate_routes::add_generate_routes;
|
||||
use crate::http_server::routes::add_image_studio_routes::add_image_studio_routes;
|
||||
use crate::http_server::routes::add_stripe_artcraft_routes::add_stripe_artcraft_routes;
|
||||
@@ -151,39 +152,40 @@ pub fn add_routes<T, B> (app: App<T>, server_environment: ServerEnvironment) ->
|
||||
InitError = (),
|
||||
>,
|
||||
{
|
||||
let mut app = add_moderator_routes(app); /* /moderation */
|
||||
let mut app = add_moderator_routes(app); // /moderation
|
||||
app = add_user_routes(app); // /create_account, /session, /login, /logout, etc.
|
||||
app = add_tts_routes(app); /* /tts */
|
||||
app = add_w2l_routes(app); /* /w2l */
|
||||
app = add_web_vc_routes(app); /* /v1/voice_conversion */
|
||||
app = add_vocoder_routes(app); /* /vocoder */
|
||||
app = add_remote_download_routes(app); /* /v1/remote_downloads (prev. /retrieval, aka. "generic_download_jobs") */
|
||||
app = add_category_routes(app); /* /category */
|
||||
app = add_api_token_routes(app); /* /api_tokens */
|
||||
app = add_voice_clone_request_routes(app); /* /voice_clone_requests */
|
||||
app = add_investor_demo_routes(app); /* /demo_mode */ // TODO: DEFINITELY TEMPORARY
|
||||
app = add_flag_routes(app); /* /flag */
|
||||
app = add_desktop_app_routes(app); /* /v1/vc/... */
|
||||
app = add_media_file_routes(app); /* /v1/media_files/... */
|
||||
app = add_media_upload_routes(app); /* /v1/media_upload/... */
|
||||
app = add_trending_routes(app); /* /v1/trending/... */
|
||||
app = add_user_rating_routes(app); /* /v1/user_rating/... */
|
||||
app = add_featured_item_routes(app); /* /v1/featured_item/... */
|
||||
app = add_subscription_routes(app); /* /v1/subscriptions/... */
|
||||
app = add_voice_designer_routes(app); /* /v1/voice_designer */
|
||||
app = add_beta_key_routes(app); /* /v1/beta_keys */
|
||||
app = add_tts_routes(app); // /tts
|
||||
app = add_w2l_routes(app); // /w2l
|
||||
app = add_web_vc_routes(app); // /v1/voice_conversion
|
||||
app = add_vocoder_routes(app); // /vocoder
|
||||
app = add_remote_download_routes(app); // /v1/remote_downloads (prev. /retrieval, aka. "generic_download_jobs")
|
||||
app = add_category_routes(app); // /category
|
||||
app = add_api_token_routes(app); // /api_tokens
|
||||
app = add_voice_clone_request_routes(app); // /voice_clone_requests
|
||||
app = add_investor_demo_routes(app); // /demo_mode // TODO: DEFINITELY TEMPORARY
|
||||
app = add_flag_routes(app); // /flag
|
||||
app = add_desktop_app_routes(app); // /v1/vc/...
|
||||
app = add_media_file_routes(app); // /v1/media_files/...
|
||||
app = add_media_upload_routes(app); // /v1/media_upload/...
|
||||
app = add_trending_routes(app); // /v1/trending/...
|
||||
app = add_user_rating_routes(app); // /v1/user_rating/...
|
||||
app = add_featured_item_routes(app); // /v1/featured_item/...
|
||||
app = add_subscription_routes(app); // /v1/subscriptions/...
|
||||
app = add_voice_designer_routes(app); // /v1/voice_designer
|
||||
app = add_beta_key_routes(app); // /v1/beta_keys
|
||||
app = add_weights_routes(app);
|
||||
app = add_tag_routes(app); /* /v1/tags */
|
||||
app = add_tag_routes(app); // /v1/tags
|
||||
app = add_model_download_routes(app);
|
||||
app = add_workflow_routes(app);
|
||||
app = add_studio_gen2_routes(app);
|
||||
app = add_image_studio_routes(app);
|
||||
app = add_job_routes(app);
|
||||
app = add_engine_routes(app); /* /v1/engine/... */
|
||||
app = add_control_plane_routes(app); /* /v1/control_plane/... */
|
||||
app = add_generate_routes(app); /* /v1/generate/... */
|
||||
app = add_webhook_routes(app); /* /v1/webhooks/... */
|
||||
app = add_stripe_artcraft_routes(app); /* /v1/stripe_artcraft/... */
|
||||
app = add_engine_routes(app); // /v1/engine/...
|
||||
app = add_control_plane_routes(app); // /v1/control_plane/...
|
||||
app = add_generate_routes(app); // /v1/generate/...
|
||||
app = add_webhook_routes(app); // /v1/webhooks/...
|
||||
app = add_stripe_artcraft_routes(app); // /v1/stripe_artcraft/...
|
||||
app = add_credits_routes(app); // /v1/credits/...
|
||||
|
||||
// app = add_image_gen_routes(app);
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
mod add_control_plane_routes;
|
||||
mod add_credits_routes;
|
||||
mod add_generate_routes;
|
||||
mod add_image_studio_routes;
|
||||
mod add_stripe_artcraft_routes;
|
||||
mod add_studio_gen2_routes;
|
||||
mod add_webhook_routes;
|
||||
mod beta_key_routes;
|
||||
@@ -12,5 +14,4 @@ mod tag_routes;
|
||||
mod user_routes;
|
||||
mod weights_routes;
|
||||
mod workflow_routes;
|
||||
pub mod add_routes;
|
||||
mod add_stripe_artcraft_routes;
|
||||
pub mod add_routes;
|
||||
Reference in new issue
Block a user