mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-03 08:57:54 +00:00
fix routes generics / upgrade generics on routing pieces
This commit is contained in:
1 parent
9dd91ce7cc
commit
039e61499f
11 files changed
+71
-590
No files matched your search
Generated
-77
@@ -3586,83 +3586,6 @@ dependencies = [
|
||||
"unicode-normalization",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "image-generation-service"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"actix",
|
||||
"actix-cors 0.6.4",
|
||||
"actix-files",
|
||||
"actix-http 3.3.0",
|
||||
"actix-multipart",
|
||||
"actix-rt 2.7.0",
|
||||
"actix-service 2.0.1",
|
||||
"actix-utils 3.0.0",
|
||||
"actix-web 4.0.1",
|
||||
"actix-web-actors",
|
||||
"anyhow",
|
||||
"base64 0.13.0",
|
||||
"bcrypt",
|
||||
"chrono",
|
||||
"cloud_storage",
|
||||
"config",
|
||||
"container_common",
|
||||
"data-encoding",
|
||||
"derive_more",
|
||||
"diesel",
|
||||
"dotenv",
|
||||
"easyenv",
|
||||
"errors",
|
||||
"futures 0.1.31",
|
||||
"futures 0.3.26",
|
||||
"futures-util",
|
||||
"google_drive_common",
|
||||
"hex",
|
||||
"hmac 0.10.1",
|
||||
"hostname",
|
||||
"http_server_common",
|
||||
"hyper 0.14.24",
|
||||
"infer 0.5.0",
|
||||
"jobs_common",
|
||||
"jwt",
|
||||
"language-tags 0.3.2",
|
||||
"lazy_static",
|
||||
"lexical-sort",
|
||||
"lfu",
|
||||
"limitation",
|
||||
"log",
|
||||
"lru_time_cache",
|
||||
"magic-crypt",
|
||||
"md-5",
|
||||
"memory_caching",
|
||||
"mysql_queries",
|
||||
"native-tls",
|
||||
"once_cell",
|
||||
"pulldown-cmark",
|
||||
"r2d2_redis",
|
||||
"rand 0.8.5",
|
||||
"redis_common",
|
||||
"regex",
|
||||
"reqwest",
|
||||
"reusable_types",
|
||||
"ring 0.17.0-alpha.11",
|
||||
"rust-s3",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"sha2 0.9.5",
|
||||
"sqlx",
|
||||
"subprocess",
|
||||
"tempdir",
|
||||
"time 0.2.26",
|
||||
"tokio 1.25.0",
|
||||
"toml",
|
||||
"tts_common",
|
||||
"twitch_common",
|
||||
"user_input_common",
|
||||
"uuid 0.8.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.9.2"
|
||||
|
||||
@@ -61,7 +61,6 @@ members = [
|
||||
"crates/service/job/w2l_inference_job",
|
||||
"crates/service/other/twitch_pubsub_subscriber",
|
||||
"crates/service/web/dummy_service",
|
||||
"crates/service/web/image_generation_service",
|
||||
"crates/service/web/storyteller_web",
|
||||
"crates/service/web/websocket_gateway",
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use actix_http::body::MessageBody;
|
||||
use actix_service::ServiceFactory;
|
||||
use actix_web::dev::{Handler, ServiceRequest, ServiceResponse};
|
||||
use actix_web::error::Error;
|
||||
@@ -8,12 +9,13 @@ use actix_web::{App, web, HttpResponse, FromRequest, Responder};
|
||||
// TODO: Add tests.
|
||||
|
||||
/// Build routes more concisely.
|
||||
pub struct RouteBuilder<T>
|
||||
pub struct RouteBuilder<T, B>
|
||||
where
|
||||
B: MessageBody,
|
||||
T: ServiceFactory<
|
||||
ServiceRequest,
|
||||
Config = (),
|
||||
Response = ServiceResponse,
|
||||
Response = ServiceResponse<B>,
|
||||
Error = Error,
|
||||
InitError = (),
|
||||
>,
|
||||
@@ -21,12 +23,13 @@ where
|
||||
app: App<T>,
|
||||
}
|
||||
|
||||
impl <T> RouteBuilder<T>
|
||||
impl <T, B> RouteBuilder<T, B>
|
||||
where
|
||||
B: MessageBody,
|
||||
T: ServiceFactory<
|
||||
ServiceRequest,
|
||||
Config = (),
|
||||
Response = ServiceResponse,
|
||||
Response = ServiceResponse<B>,
|
||||
Error = Error,
|
||||
InitError = (),
|
||||
>,
|
||||
|
||||
@@ -11,12 +11,13 @@ use crate::stripe::http_endpoints::customer_portal::stripe_create_customer_porta
|
||||
use crate::stripe::http_endpoints::webhook::stripe_webhook_handler::stripe_webhook_handler;
|
||||
use crate::users::http_endpoints::list_active_user_subscriptions_handler::list_active_user_subscriptions_handler;
|
||||
|
||||
pub fn add_suggested_stripe_billing_routes<T> (app: App<T>) -> App<T>
|
||||
pub fn add_suggested_stripe_billing_routes<T, B> (app: App<T>) -> App<T>
|
||||
where
|
||||
B: MessageBody,
|
||||
T: ServiceFactory<
|
||||
ServiceRequest,
|
||||
Config = (),
|
||||
Response = ServiceResponse,
|
||||
Response = ServiceResponse<B>,
|
||||
Error = Error,
|
||||
InitError = (),
|
||||
>,
|
||||
|
||||
@@ -11,12 +11,13 @@ use crate::endpoints::session_info_handler::session_info_handler;
|
||||
// NB: This does not include the user edit endpoints since FakeYou's API mounts them alongside other things.
|
||||
// A 'v2' API would mount under a v2 prefix and the entity type.
|
||||
|
||||
pub fn add_suggested_api_v1_account_creation_and_session_routes<T> (app: App<T>) -> App<T>
|
||||
pub fn add_suggested_api_v1_account_creation_and_session_routes<T, B> (app: App<T>) -> App<T>
|
||||
where
|
||||
B: MessageBody,
|
||||
T: ServiceFactory<
|
||||
ServiceRequest,
|
||||
Config = (),
|
||||
Response = ServiceResponse,
|
||||
Response = ServiceResponse<B>,
|
||||
Error = Error,
|
||||
InitError = (),
|
||||
>,
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
[package]
|
||||
publish = false
|
||||
name = "image-generation-service"
|
||||
edition = "2018"
|
||||
version = "0.0.1"
|
||||
authors = [
|
||||
"Brandon Thomas <bt@brand.io>",
|
||||
"Brandon Thomas <echelon@gmail.com>",
|
||||
]
|
||||
|
||||
# Main server monolith
|
||||
[[bin]]
|
||||
name = "image-generation-service"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
|
||||
# Internal
|
||||
cloud_storage = { path = "../../../lib/api_clients/cloud_storage" }
|
||||
config = { path = "../../../lib/deprecated/config" }
|
||||
container_common = { path = "../../../lib/deprecated/container_common" }
|
||||
errors = { path = "../../../lib/errors" }
|
||||
google_drive_common = { path = "../../../lib/api_clients/google_drive_common" }
|
||||
http_server_common = { path = "../../../lib/deprecated/http_server_common" }
|
||||
jobs_common = { path = "../../../lib/jobs_common" }
|
||||
memory_caching = { path = "../../../lib/caching/memory_caching" }
|
||||
mysql_queries = { path = "../../../lib/mysql_queries" }
|
||||
redis_common = { path = "../../../lib/redis_common" }
|
||||
reusable_types = { path = "../../../_types/reusable_types" }
|
||||
tts_common = { path = "../../../lib/tts_common" }
|
||||
twitch_common = { path = "../../../lib/api_clients/twitch_common" }
|
||||
user_input_common = { path = "../../../lib/user_input_common" }
|
||||
|
||||
# External
|
||||
anyhow = "1.0.40"
|
||||
base64 = "0.13.0"
|
||||
chrono = { version = "0.4.19", features = ["serde"] }
|
||||
derive_more = "0.99.14"
|
||||
dotenv = "0.15.0"
|
||||
easyenv = "0.0.9"
|
||||
hex = "0.4.3"
|
||||
hostname = "0.3.1"
|
||||
lazy_static = "1.4.0"
|
||||
lexical-sort = "0.3.1"
|
||||
lfu = "0.2.5"
|
||||
log = "0.4.14"
|
||||
once_cell = "1.9.0"
|
||||
rand = "0.8.3"
|
||||
regex = "1.5.4"
|
||||
time = "0.2.26"
|
||||
uuid = { version = "0.8.2", features = ["v4"] }
|
||||
|
||||
# Language tag parsing
|
||||
# TODO: Move to language support crate
|
||||
language-tags = "0.3.2" # Parsing single tags richly
|
||||
|
||||
# HTTP
|
||||
# TODO/NB: This is just for Twitch, but we might need it later.
|
||||
reqwest = { version = "0.11.4" }
|
||||
native-tls = "0.2.8"
|
||||
|
||||
# Runtime
|
||||
# NB: We switched to Tokio from `async-std` for broader ecosystem support.
|
||||
tokio = { version = "1.6.0", features = ["macros"] }
|
||||
|
||||
# Futures
|
||||
futures = { version = "0.3.17", features = ["thread-pool"] } # feature for ThreadPool
|
||||
futures-util = "0.3.9"
|
||||
futures_old_for_limiter = { package = "futures", version = "0.1.29" } # Older version of futures for `limiter` crate
|
||||
|
||||
# MySql Database
|
||||
# "offline" supports typesafe builds without a live database
|
||||
# "rustls" doesn't appear to work with IP addresses, per:
|
||||
# https://github.com/launchbadge/sqlx/issues/1095#issuecomment-798050828
|
||||
sqlx = { version = "0.6.2", features = [ "mysql", "runtime-actix-native-tls", "offline", "chrono" ] }
|
||||
|
||||
# Redis Database
|
||||
limitation = "0.1.1" # Redis rate limiter
|
||||
r2d2_redis = "0.14.0"
|
||||
|
||||
# In-memory caching
|
||||
lru_time_cache = "0.11.11"
|
||||
|
||||
# Files
|
||||
data-encoding = "2.3.2"
|
||||
ring = "0.17.0-alpha.10"
|
||||
infer = "0.5.0"
|
||||
|
||||
# The "never-encode-slash" feature seems to have been removed:
|
||||
# https://github.com/durch/rust-s3/pull/254
|
||||
rust-s3 = { version = "0.32.3" }
|
||||
|
||||
subprocess = "0.2.6"
|
||||
tempdir = "0.3.7"
|
||||
|
||||
actix = "0.12.0"
|
||||
actix-cors = "0.6.0-beta.3"
|
||||
actix-files= "0.6.0-beta.8"
|
||||
actix-http = "3.0.0-beta.11"
|
||||
actix-multipart = "0.4.0-beta.7"
|
||||
actix-rt = "2.4.0"
|
||||
actix-service = "2.0.1"
|
||||
actix-utils = "3.0.0"
|
||||
actix-web = "4.0.0-beta.10"
|
||||
actix-web-actors = "4.0.0-beta.7"
|
||||
jwt = "0.13.0"
|
||||
|
||||
# NB: Hyper is just for HTTP client use in jobs. I'd use Actix client, but I need tokio runtime
|
||||
# NB: Furthermore, the Tokio runtime is old, so I have to use an older Hyper.
|
||||
hyper = { version = "0.14.14" }
|
||||
|
||||
# Crypto
|
||||
bcrypt = "0.8" # password hashes
|
||||
hmac = "0.10.0" # cookies
|
||||
magic-crypt = "3.1.8" # encrypting sort IDs for the frontend so we don't leak info
|
||||
md-5 = "0.9.1" # gravatar
|
||||
sha2 = "0.9.5" # file hashes, inference text hashes, etc.
|
||||
|
||||
# Serialization
|
||||
serde = "1.0.125"
|
||||
serde_derive = "1.0.125"
|
||||
serde_json = "1.0.64"
|
||||
toml = "0.5.8"
|
||||
|
||||
# Text processing
|
||||
pulldown-cmark = "0.8.0"
|
||||
|
||||
[build-dependencies]
|
||||
# NB: Only using diesel for migrations support
|
||||
diesel = { version = "1.4.6", features = ["mysql"] }
|
||||
@@ -1,247 +0,0 @@
|
||||
// Never allow these
|
||||
#![forbid(private_in_public)]
|
||||
#![forbid(unused_must_use)] // NB: It's unsafe to not close/check some things
|
||||
|
||||
// Okay to toggle
|
||||
//#![forbid(warnings)]
|
||||
#![allow(unreachable_patterns)]
|
||||
#![allow(unused_imports)]
|
||||
#![allow(unused_mut)]
|
||||
#![allow(unused_variables)]
|
||||
|
||||
// Always allow
|
||||
#![allow(dead_code)]
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
#[macro_use] extern crate lazy_static;
|
||||
#[macro_use] extern crate magic_crypt;
|
||||
#[macro_use] extern crate serde_derive;
|
||||
|
||||
mod routes;
|
||||
mod server_state;
|
||||
|
||||
use actix_web::middleware::{DefaultHeaders, Logger};
|
||||
use actix_web::{App, HttpServer, web};
|
||||
use cloud_storage::bucket_client::BucketClient;
|
||||
use config::common_env::CommonEnv;
|
||||
use config::shared_constants::{DEFAULT_MYSQL_CONNECTION_STRING, DEFAULT_RUST_LOG};
|
||||
use errors::AnyhowResult;
|
||||
use crate::routes::add_routes;
|
||||
use crate::server_state::{EnvConfig, InMemoryCaches, ServerState};
|
||||
use http_server_common::cors::build_production_cors_config;
|
||||
use limitation::Limiter;
|
||||
use log::info;
|
||||
use memory_caching::single_item_ttl_cache::SingleItemTtlCache;
|
||||
use r2d2_redis::{r2d2, RedisConnectionManager};
|
||||
use sqlx::mysql::MySqlPoolOptions;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use tokio::runtime::Runtime;
|
||||
|
||||
const DEFAULT_BIND_ADDRESS : &'static str = "0.0.0.0:12345";
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> AnyhowResult<()> {
|
||||
easyenv::init_all_with_default_logging(Some(DEFAULT_RUST_LOG));
|
||||
|
||||
// NB: Do not check this secrets-containing dotenv file into VCS.
|
||||
// This file should only contain *development* secrets, never production.
|
||||
let _ = dotenv::from_filename(".env-secrets").ok();
|
||||
|
||||
let common_env = CommonEnv::read_from_env()?; // TODO: Deprecate and remove
|
||||
|
||||
info!("Obtaining hostname...");
|
||||
|
||||
let server_hostname = hostname::get()
|
||||
.ok()
|
||||
.and_then(|h| h.into_string().ok())
|
||||
.unwrap_or("image-generation-service".to_string());
|
||||
|
||||
info!("Hostname: {}", &server_hostname);
|
||||
|
||||
info!("Connecting to database...");
|
||||
|
||||
let db_connection_string =
|
||||
easyenv::get_env_string_or_default(
|
||||
"MYSQL_URL",
|
||||
DEFAULT_MYSQL_CONNECTION_STRING);
|
||||
|
||||
let pool = MySqlPoolOptions::new()
|
||||
.max_connections(easyenv::get_env_num("MYSQL_MAX_CONNECTIONS", 5)?)
|
||||
.connect(&db_connection_string)
|
||||
.await?;
|
||||
|
||||
// let firehose_publisher = FirehosePublisher {
|
||||
// mysql_pool: pool.clone(), // NB: Pool is clone/sync/send-safe
|
||||
// };
|
||||
//
|
||||
// let badge_granter = BadgeGranter {
|
||||
// mysql_pool: pool.clone(), // NB: Pool is clone/sync/send-safe
|
||||
// firehose_publisher: firehose_publisher.clone(), // NB: Also safe
|
||||
// };
|
||||
|
||||
let redis_manager = RedisConnectionManager::new(
|
||||
common_env.redis_0_connection_string.clone())?;
|
||||
|
||||
let redis_pool = r2d2::Pool::builder()
|
||||
.build(redis_manager)?;
|
||||
|
||||
info!("Setting up Redis rate limiters...");
|
||||
|
||||
//let logged_out_redis_rate_limiter = {
|
||||
// let limiter_enabled = easyenv::get_env_bool_or_default("LIMITER_LOGGED_OUT_ENABLED", true);
|
||||
// let limiter_max_requests = easyenv::get_env_num("LIMITER_LOGGED_OUT_MAX_REQUESTS", 3)?;
|
||||
// let limiter_window_seconds = easyenv::get_env_num("LIMITER_LOGGED_OUT_WINDOW_SECONDS", 10)?;
|
||||
//
|
||||
// let limiter = Limiter::build(&common_env.redis_0_connection_string)
|
||||
// .limit(limiter_max_requests)
|
||||
// .period(Duration::from_secs(limiter_window_seconds))
|
||||
// .finish()?;
|
||||
//
|
||||
// RedisRateLimiter::new(limiter, "logged_out", limiter_enabled)
|
||||
//};
|
||||
|
||||
//let logged_in_redis_rate_limiter = {
|
||||
// let limiter_enabled = easyenv::get_env_bool_or_default("LIMITER_LOGGED_IN_ENABLED", true);
|
||||
// let limiter_max_requests = easyenv::get_env_num("LIMITER_LOGGED_IN_MAX_REQUESTS", 3)?;
|
||||
// let limiter_window_seconds = easyenv::get_env_num("LIMITER_LOGGED_IN_WINDOW_SECONDS", 10)?;
|
||||
//
|
||||
// let limiter = Limiter::build(&common_env.redis_0_connection_string)
|
||||
// .limit(limiter_max_requests)
|
||||
// .period(Duration::from_secs(limiter_window_seconds))
|
||||
// .finish()?;
|
||||
//
|
||||
// RedisRateLimiter::new(limiter, "logged_in", limiter_enabled)
|
||||
//};
|
||||
|
||||
//let api_high_priority_redis_rate_limiter = {
|
||||
// let limiter_enabled = easyenv::get_env_bool_or_default("LIMITER_API_HIGH_PRIORITY_ENABLED", true);
|
||||
// let limiter_max_requests = easyenv::get_env_num("LIMITER_API_HIGH_PRIORITY_MAX_REQUESTS", 30)?;
|
||||
// let limiter_window_seconds = easyenv::get_env_num("LIMITER_API_HIGH_PRIORITY_WINDOW_SECONDS", 30)?;
|
||||
//
|
||||
// let limiter = Limiter::build(&common_env.redis_0_connection_string)
|
||||
// .limit(limiter_max_requests)
|
||||
// .period(Duration::from_secs(limiter_window_seconds))
|
||||
// .finish()?;
|
||||
//
|
||||
// RedisRateLimiter::new(limiter, "api_high_priority", limiter_enabled)
|
||||
//};
|
||||
|
||||
//let model_upload_rate_limiter = {
|
||||
// let limiter_enabled = easyenv::get_env_bool_or_default("LIMITER_MODEL_UPLOAD_ENABLED", true);
|
||||
// let limiter_max_requests = easyenv::get_env_num("LIMITER_MODEL_UPLOAD_MAX_REQUESTS", 3)?;
|
||||
// let limiter_window_seconds = easyenv::get_env_num("LIMITER_MODEL_UPLOAD_WINDOW_SECONDS", 10)?;
|
||||
//
|
||||
// let limiter = Limiter::build(&common_env.redis_0_connection_string)
|
||||
// .limit(limiter_max_requests)
|
||||
// .period(Duration::from_secs(limiter_window_seconds))
|
||||
// .finish()?;
|
||||
//
|
||||
// RedisRateLimiter::new(limiter, "model_upload", limiter_enabled)
|
||||
//};
|
||||
|
||||
info!("Reading env vars and setting up utils...");
|
||||
|
||||
let bind_address = easyenv::get_env_string_or_default("BIND_ADDRESS", DEFAULT_BIND_ADDRESS);
|
||||
let num_workers = easyenv::get_env_num("NUM_WORKERS", 8)?;
|
||||
let hmac_secret = easyenv::get_env_string_or_default("COOKIE_SECRET", "notsecret");
|
||||
let cookie_domain = easyenv::get_env_string_or_default("COOKIE_DOMAIN", ".vo.codes");
|
||||
let cookie_secure = easyenv::get_env_bool_or_default("COOKIE_SECURE", true);
|
||||
let cookie_http_only = easyenv::get_env_bool_or_default("COOKIE_HTTP_ONLY", true);
|
||||
let website_homepage_redirect =
|
||||
easyenv::get_env_string_or_default("WEBSITE_HOMEPAGE_REDIRECT", "https://vo.codes/");
|
||||
|
||||
//let cookie_manager = CookieManager::new(&cookie_domain, &hmac_secret);
|
||||
//let session_checker = SessionChecker::new(&cookie_manager);
|
||||
|
||||
let access_key = easyenv::get_env_string_required("ACCESS_KEY")?;
|
||||
let secret_key = easyenv::get_env_string_required("SECRET_KEY")?;
|
||||
let region_name = easyenv::get_env_string_required("REGION_NAME")?;
|
||||
|
||||
// NB: This secret really isn't too important.
|
||||
// We can even rotate it without too much impact to users.
|
||||
//let sort_key_crypto_secret =
|
||||
// easyenv::get_env_string_or_default("SORT_KEY_SECRET", "webscale");
|
||||
//let sort_key_crypto = SortKeyCrypto::new(&sort_key_crypto_secret);
|
||||
|
||||
// Background jobs.
|
||||
|
||||
// let health_check_status = HealthCheckStatus::new();
|
||||
// let health_check_status2 = health_check_status.clone();
|
||||
// let ip_banlist = IpBanlistSet::new();
|
||||
// let ip_banlist2 = ip_banlist.clone();
|
||||
// let mysql_pool3 = pool.clone();
|
||||
// let mysql_pool4 = pool.clone();
|
||||
|
||||
let tokio_runtime = Runtime::new()?;
|
||||
|
||||
// info!("Spawning DB health checker thread.");
|
||||
//
|
||||
// tokio_runtime.spawn(async {
|
||||
// db_health_checker_thread(health_check_status2, mysql_pool3).await;
|
||||
// });
|
||||
//
|
||||
// info!("Spawning IP ban polling thread.");
|
||||
//
|
||||
// tokio_runtime.spawn(async {
|
||||
// poll_ip_bans(ip_banlist2, mysql_pool4).await;
|
||||
// });
|
||||
|
||||
let server_state = ServerState {
|
||||
env_config: EnvConfig {
|
||||
num_workers,
|
||||
bind_address,
|
||||
cookie_domain,
|
||||
cookie_secure,
|
||||
cookie_http_only,
|
||||
website_homepage_redirect,
|
||||
},
|
||||
hostname: server_hostname,
|
||||
mysql_pool: pool,
|
||||
redis_pool,
|
||||
caches: InMemoryCaches {
|
||||
},
|
||||
};
|
||||
|
||||
serve(server_state)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn serve(server_state: ServerState) -> AnyhowResult<()>
|
||||
{
|
||||
let bind_address = server_state.env_config.bind_address.clone();
|
||||
let num_workers = server_state.env_config.num_workers.clone();
|
||||
let hostname = server_state.hostname.clone();
|
||||
|
||||
let server_state_arc = web::Data::new(Arc::new(server_state));
|
||||
|
||||
info!("Starting HTTP service.");
|
||||
|
||||
let log_format = "[%{HOSTNAME}e] %a \"%r\" %s %b \"%{Referer}i\" \"%{User-Agent}i\" %T";
|
||||
|
||||
HttpServer::new(move || {
|
||||
// NB: Safe to clone due to internal arc
|
||||
//let ip_banlist = server_state_arc.ip_banlist.clone();
|
||||
let build_sha = std::fs::read_to_string("/GIT_SHA").unwrap_or(String::from("unknown"));
|
||||
|
||||
let app = App::new()
|
||||
.app_data(server_state_arc.clone())
|
||||
.wrap(build_production_cors_config())
|
||||
.wrap(DefaultHeaders::new()
|
||||
.header("X-Backend-Hostname", &hostname)
|
||||
.header("X-Build-Sha", build_sha.trim()))
|
||||
//.wrap(IpFilter::new(ip_banlist))
|
||||
.wrap(Logger::new(&log_format)
|
||||
.exclude("/liveness")
|
||||
.exclude("/readiness"));
|
||||
|
||||
add_routes(app)
|
||||
})
|
||||
.bind(bind_address)?
|
||||
.workers(num_workers)
|
||||
.run()
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
use actix_http::body::MessageBody;
|
||||
use actix_service::ServiceFactory;
|
||||
use actix_web::dev::{ServiceRequest, ServiceResponse};
|
||||
use actix_web::error::Error;
|
||||
use actix_web::{App, web, HttpResponse};
|
||||
use http_server_common::endpoints::default_route_404::default_route_404;
|
||||
use http_server_common::endpoints::root_index::get_root_index;
|
||||
|
||||
pub fn add_routes<T, B> (app: App<T, B>) -> App<T, B>
|
||||
where
|
||||
B: MessageBody,
|
||||
T: ServiceFactory<
|
||||
ServiceRequest,
|
||||
Config = (),
|
||||
Response = ServiceResponse<B>,
|
||||
Error = Error,
|
||||
InitError = (),
|
||||
>,
|
||||
{
|
||||
app
|
||||
//.service(web::resource("/_status")
|
||||
// .route(web::get().to(get_health_check_handler))
|
||||
// .route(web::head().to(|| HttpResponse::Ok())))
|
||||
.service(web::resource("/")
|
||||
.route(web::get().to(get_root_index))
|
||||
.route(web::head().to(|| HttpResponse::Ok()))
|
||||
)
|
||||
.default_service( web::route().to(default_route_404))
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
use r2d2_redis::{r2d2, RedisConnectionManager};
|
||||
use sqlx::MySqlPool;
|
||||
|
||||
/// State that is injected into every endpoint.
|
||||
pub struct ServerState {
|
||||
pub env_config: EnvConfig,
|
||||
|
||||
pub hostname: String,
|
||||
|
||||
//pub health_check_status: HealthCheckStatus,
|
||||
|
||||
pub mysql_pool: MySqlPool,
|
||||
|
||||
pub redis_pool: r2d2::Pool<RedisConnectionManager>,
|
||||
|
||||
//pub redis_rate_limiters: RedisRateLimiters,
|
||||
|
||||
//pub cookie_manager: CookieManager,
|
||||
|
||||
//pub session_checker: SessionChecker,
|
||||
|
||||
//pub sort_key_crypto: SortKeyCrypto,
|
||||
|
||||
//pub ip_banlist: IpBanlistSet,
|
||||
|
||||
pub caches: InMemoryCaches,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct EnvConfig {
|
||||
// Number of thread workers.
|
||||
pub num_workers: usize,
|
||||
pub bind_address: String,
|
||||
pub cookie_domain: String,
|
||||
pub cookie_secure: bool,
|
||||
pub cookie_http_only: bool,
|
||||
pub website_homepage_redirect: String,
|
||||
}
|
||||
|
||||
/// Different rate limiters for different users
|
||||
//#[derive(Clone)]
|
||||
//pub struct RedisRateLimiters {
|
||||
// /// Logged out users have stricter limits
|
||||
// pub logged_out: RedisRateLimiter,
|
||||
//
|
||||
// /// Logged in users have a little more leeway
|
||||
// pub logged_in: RedisRateLimiter,
|
||||
//
|
||||
// /// API consumers have even higher priority
|
||||
// /// (Temporary for VidVoice.ai; a long term solution builds an in-memory cache
|
||||
// /// of these or finds a better rate limit library that allows on-demand rate
|
||||
// /// constructions)
|
||||
// pub api_high_priority: RedisRateLimiter,
|
||||
//}
|
||||
|
||||
/// In-memory caches
|
||||
#[derive(Clone)]
|
||||
pub struct InMemoryCaches {
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
use actix_helpers::route_builder::RouteBuilder;
|
||||
use actix_http::body::MessageBody;
|
||||
use actix_service::ServiceFactory;
|
||||
use actix_web::dev::{ServiceRequest, ServiceResponse};
|
||||
use actix_web::error::Error;
|
||||
@@ -116,12 +117,13 @@ use users_component::default_routes::add_suggested_api_v1_account_creation_and_s
|
||||
use users_component::endpoints::edit_profile_handler::edit_profile_handler;
|
||||
use users_component::endpoints::get_profile_handler::get_profile_handler;
|
||||
|
||||
pub fn add_routes<T> (app: App<T>) -> App<T>
|
||||
pub fn add_routes<T, B> (app: App<T>) -> App<T>
|
||||
where
|
||||
B: MessageBody,
|
||||
T: ServiceFactory<
|
||||
ServiceRequest,
|
||||
Config = (),
|
||||
Response = ServiceResponse,
|
||||
Response = ServiceResponse<B>,
|
||||
Error = Error,
|
||||
InitError = (),
|
||||
>,
|
||||
@@ -209,12 +211,13 @@ pub fn add_routes<T> (app: App<T>) -> App<T>
|
||||
|
||||
// ==================== MODERATOR ROUTES ====================
|
||||
|
||||
fn add_moderator_routes<T> (app: App<T>) -> App<T>
|
||||
fn add_moderator_routes<T, B> (app: App<T>) -> App<T>
|
||||
where
|
||||
B: MessageBody,
|
||||
T: ServiceFactory<
|
||||
ServiceRequest,
|
||||
Config = (),
|
||||
Response = ServiceResponse,
|
||||
Response = ServiceResponse<B>,
|
||||
Error = Error,
|
||||
InitError = (),
|
||||
>,
|
||||
@@ -350,12 +353,13 @@ fn add_moderator_routes<T> (app: App<T>) -> App<T>
|
||||
|
||||
// ==================== TTS ROUTES ====================
|
||||
|
||||
fn add_tts_routes<T> (app: App<T>) -> App<T>
|
||||
fn add_tts_routes<T, B> (app: App<T>) -> App<T>
|
||||
where
|
||||
B: MessageBody,
|
||||
T: ServiceFactory<
|
||||
ServiceRequest,
|
||||
Config = (),
|
||||
Response = ServiceResponse,
|
||||
Response = ServiceResponse<B>,
|
||||
Error = Error,
|
||||
InitError = (),
|
||||
>,
|
||||
@@ -432,12 +436,13 @@ fn add_tts_routes<T> (app: App<T>) -> App<T>
|
||||
|
||||
// ==================== WAV2LIP ROUTES ====================
|
||||
|
||||
fn add_w2l_routes<T> (app: App<T>) -> App<T>
|
||||
fn add_w2l_routes<T, B> (app: App<T>) -> App<T>
|
||||
where
|
||||
B: MessageBody,
|
||||
T: ServiceFactory<
|
||||
ServiceRequest,
|
||||
Config = (),
|
||||
Response = ServiceResponse,
|
||||
Response = ServiceResponse<B>,
|
||||
Error = Error,
|
||||
InitError = (),
|
||||
>,
|
||||
@@ -514,12 +519,13 @@ fn add_w2l_routes<T> (app: App<T>) -> App<T>
|
||||
|
||||
// ==================== WEB VOICE CONVERSION ROUTES ====================
|
||||
|
||||
fn add_web_vc_routes<T> (app: App<T>) -> App<T>
|
||||
fn add_web_vc_routes<T, B> (app: App<T>) -> App<T>
|
||||
where
|
||||
B: MessageBody,
|
||||
T: ServiceFactory<
|
||||
ServiceRequest,
|
||||
Config = (),
|
||||
Response = ServiceResponse,
|
||||
Response = ServiceResponse<B>,
|
||||
Error = Error,
|
||||
InitError = (),
|
||||
>,
|
||||
@@ -597,12 +603,13 @@ fn add_web_vc_routes<T> (app: App<T>) -> App<T>
|
||||
|
||||
// ==================== VOCODER ROUTES ====================
|
||||
|
||||
fn add_vocoder_routes<T> (app: App<T>) -> App<T>
|
||||
fn add_vocoder_routes<T, B> (app: App<T>) -> App<T>
|
||||
where
|
||||
B: MessageBody,
|
||||
T: ServiceFactory<
|
||||
ServiceRequest,
|
||||
Config = (),
|
||||
Response = ServiceResponse,
|
||||
Response = ServiceResponse<B>,
|
||||
Error = Error,
|
||||
InitError = (),
|
||||
>,
|
||||
@@ -634,12 +641,13 @@ fn add_vocoder_routes<T> (app: App<T>) -> App<T>
|
||||
|
||||
// ==================== RETRIEVAL ROUTES ("GENERIC_DOWNLOAD_JOBS") ====================
|
||||
|
||||
fn add_remote_download_routes<T> (app: App<T>) -> App<T>
|
||||
fn add_remote_download_routes<T, B> (app: App<T>) -> App<T>
|
||||
where
|
||||
B: MessageBody,
|
||||
T: ServiceFactory<
|
||||
ServiceRequest,
|
||||
Config = (),
|
||||
Response = ServiceResponse,
|
||||
Response = ServiceResponse<B>,
|
||||
Error = Error,
|
||||
InitError = (),
|
||||
>,
|
||||
@@ -656,12 +664,13 @@ fn add_remote_download_routes<T> (app: App<T>) -> App<T>
|
||||
|
||||
// ==================== CATEGORY ROUTES ====================
|
||||
|
||||
fn add_category_routes<T> (app: App<T>) -> App<T>
|
||||
fn add_category_routes<T, B> (app: App<T>) -> App<T>
|
||||
where
|
||||
B: MessageBody,
|
||||
T: ServiceFactory<
|
||||
ServiceRequest,
|
||||
Config = (),
|
||||
Response = ServiceResponse,
|
||||
Response = ServiceResponse<B>,
|
||||
Error = Error,
|
||||
InitError = (),
|
||||
>,
|
||||
@@ -726,12 +735,13 @@ fn add_category_routes<T> (app: App<T>) -> App<T>
|
||||
|
||||
// ==================== USER PROFILE ROUTES ====================
|
||||
|
||||
fn add_user_profile_routes<T> (app: App<T>) -> App<T>
|
||||
fn add_user_profile_routes<T, B> (app: App<T>) -> App<T>
|
||||
where
|
||||
B: MessageBody,
|
||||
T: ServiceFactory<
|
||||
ServiceRequest,
|
||||
Config = (),
|
||||
Response = ServiceResponse,
|
||||
Response = ServiceResponse<B>,
|
||||
Error = Error,
|
||||
InitError = (),
|
||||
>,
|
||||
@@ -773,12 +783,13 @@ fn add_user_profile_routes<T> (app: App<T>) -> App<T>
|
||||
|
||||
// ==================== API TOKEN ROUTES ====================
|
||||
|
||||
fn add_api_token_routes<T> (app: App<T>) -> App<T>
|
||||
fn add_api_token_routes<T, B> (app: App<T>) -> App<T>
|
||||
where
|
||||
B: MessageBody,
|
||||
T: ServiceFactory<
|
||||
ServiceRequest,
|
||||
Config = (),
|
||||
Response = ServiceResponse,
|
||||
Response = ServiceResponse<B>,
|
||||
Error = Error,
|
||||
InitError = (),
|
||||
>,
|
||||
@@ -805,12 +816,13 @@ fn add_api_token_routes<T> (app: App<T>) -> App<T>
|
||||
|
||||
// ==================== API TOKEN ROUTES ====================
|
||||
|
||||
fn add_voice_clone_request_routes<T> (app: App<T>) -> App<T>
|
||||
fn add_voice_clone_request_routes<T, B> (app: App<T>) -> App<T>
|
||||
where
|
||||
B: MessageBody,
|
||||
T: ServiceFactory<
|
||||
ServiceRequest,
|
||||
Config = (),
|
||||
Response = ServiceResponse,
|
||||
Response = ServiceResponse<B>,
|
||||
Error = Error,
|
||||
InitError = (),
|
||||
>,
|
||||
@@ -829,12 +841,13 @@ fn add_voice_clone_request_routes<T> (app: App<T>) -> App<T>
|
||||
|
||||
// ==================== INVESTOR DEMO MODE ====================
|
||||
|
||||
fn add_investor_demo_routes<T> (app: App<T>) -> App<T>
|
||||
fn add_investor_demo_routes<T, B> (app: App<T>) -> App<T>
|
||||
where
|
||||
B: MessageBody,
|
||||
T: ServiceFactory<
|
||||
ServiceRequest,
|
||||
Config = (),
|
||||
Response = ServiceResponse,
|
||||
Response = ServiceResponse<B>,
|
||||
Error = Error,
|
||||
InitError = (),
|
||||
>,
|
||||
@@ -853,12 +866,13 @@ fn add_investor_demo_routes<T> (app: App<T>) -> App<T>
|
||||
|
||||
// ==================== FLAG ROUTES ====================
|
||||
|
||||
fn add_flag_routes<T> (app: App<T>) -> App<T>
|
||||
fn add_flag_routes<T, B> (app: App<T>) -> App<T>
|
||||
where
|
||||
B: MessageBody,
|
||||
T: ServiceFactory<
|
||||
ServiceRequest,
|
||||
Config = (),
|
||||
Response = ServiceResponse,
|
||||
Response = ServiceResponse<B>,
|
||||
Error = Error,
|
||||
InitError = (),
|
||||
>,
|
||||
@@ -879,12 +893,13 @@ fn add_flag_routes<T> (app: App<T>) -> App<T>
|
||||
|
||||
// ==================== DESKTOP APP ROUTES ====================
|
||||
|
||||
fn add_desktop_app_routes<T> (app: App<T>) -> App<T>
|
||||
fn add_desktop_app_routes<T, B> (app: App<T>) -> App<T>
|
||||
where
|
||||
B: MessageBody,
|
||||
T: ServiceFactory<
|
||||
ServiceRequest,
|
||||
Config = (),
|
||||
Response = ServiceResponse,
|
||||
Response = ServiceResponse<B>,
|
||||
Error = Error,
|
||||
InitError = (),
|
||||
>,
|
||||
@@ -911,12 +926,13 @@ fn add_desktop_app_routes<T> (app: App<T>) -> App<T>
|
||||
|
||||
// ==================== MEDIA UPLOAD ROUTES ====================
|
||||
|
||||
fn add_media_upload_routes<T> (app: App<T>) -> App<T>
|
||||
fn add_media_upload_routes<T, B> (app: App<T>) -> App<T>
|
||||
where
|
||||
B: MessageBody,
|
||||
T: ServiceFactory<
|
||||
ServiceRequest,
|
||||
Config = (),
|
||||
Response = ServiceResponse,
|
||||
Response = ServiceResponse<B>,
|
||||
Error = Error,
|
||||
InitError = (),
|
||||
>,
|
||||
@@ -939,12 +955,13 @@ fn add_media_upload_routes<T> (app: App<T>) -> App<T>
|
||||
|
||||
// ==================== TRENDING ROUTES ====================
|
||||
|
||||
fn add_trending_routes<T> (app: App<T>) -> App<T>
|
||||
fn add_trending_routes<T, B> (app: App<T>) -> App<T>
|
||||
where
|
||||
B: MessageBody,
|
||||
T: ServiceFactory<
|
||||
ServiceRequest,
|
||||
Config = (),
|
||||
Response = ServiceResponse,
|
||||
Response = ServiceResponse<B>,
|
||||
Error = Error,
|
||||
InitError = (),
|
||||
>,
|
||||
@@ -958,12 +975,13 @@ fn add_trending_routes<T> (app: App<T>) -> App<T>
|
||||
}
|
||||
// ==================== USER RATING ROUTES ====================
|
||||
|
||||
fn add_user_rating_routes<T> (app: App<T>) -> App<T>
|
||||
fn add_user_rating_routes<T, B> (app: App<T>) -> App<T>
|
||||
where
|
||||
B: MessageBody,
|
||||
T: ServiceFactory<
|
||||
ServiceRequest,
|
||||
Config = (),
|
||||
Response = ServiceResponse,
|
||||
Response = ServiceResponse<B>,
|
||||
Error = Error,
|
||||
InitError = (),
|
||||
>,
|
||||
@@ -985,12 +1003,13 @@ fn add_user_rating_routes<T> (app: App<T>) -> App<T>
|
||||
// TODO: Maybe move these into an "oauth-gateway" type http service.
|
||||
// We'll want the domain to have reputation and not confuse people.
|
||||
// It'll also be nice to accrue all oauth things here.
|
||||
fn add_twitch_routes<T> (app: App<T>) -> App<T>
|
||||
fn add_twitch_routes<T, B> (app: App<T>) -> App<T>
|
||||
where
|
||||
B: MessageBody,
|
||||
T: ServiceFactory<
|
||||
ServiceRequest,
|
||||
Config = (),
|
||||
Response = ServiceResponse,
|
||||
Response = ServiceResponse<B>,
|
||||
Error = Error,
|
||||
InitError = (),
|
||||
>,
|
||||
@@ -1045,12 +1064,13 @@ fn add_twitch_routes<T> (app: App<T>) -> App<T>
|
||||
}
|
||||
|
||||
// ============= SUBSCRIPTION ROUTES ===================
|
||||
fn add_subscription_routes<T> (app: App<T>) -> App<T>
|
||||
fn add_subscription_routes<T, B> (app: App<T>) -> App<T>
|
||||
where
|
||||
B: MessageBody,
|
||||
T: ServiceFactory<
|
||||
ServiceRequest,
|
||||
Config = (),
|
||||
Response = ServiceResponse,
|
||||
Response = ServiceResponse<B>,
|
||||
Error = Error,
|
||||
InitError = (),
|
||||
>,
|
||||
|
||||
@@ -17,7 +17,6 @@ pub mod endpoints_ws;
|
||||
pub mod server_state;
|
||||
|
||||
use actix_cors::Cors;
|
||||
use actix_http::http;
|
||||
use actix_web::middleware::{Logger, DefaultHeaders};
|
||||
use actix_web::{HttpServer, web, HttpResponse, App};
|
||||
use config::shared_constants::DEFAULT_MYSQL_CONNECTION_STRING;
|
||||
|
||||
Reference in new issue
Block a user