2025-10-03 14:02:20 +01:00
|
|
|
use actix_web::dev::Service;
|
2025-03-25 01:10:43 -07:00
|
|
|
use actix_web::middleware::from_fn;
|
2023-10-06 09:57:33 -07:00
|
|
|
use actix_web::{App, HttpServer};
|
2023-10-06 17:58:02 -05:00
|
|
|
use actix_web_prom::PrometheusMetricsBuilder;
|
2025-03-15 09:28:20 -05:00
|
|
|
use clap::Parser;
|
2025-10-03 14:02:20 +01:00
|
|
|
|
[DO NOT MERGE] Email notification system (#4338)
* Migration
* Fixup db models
* Redis
* Stuff
* Switch PKs to BIGSERIALs, insert to notifications_deliveries when inserting notifications
* Queue, templates
* Query cache
* Fixes, fixtures
* Perf, cache template data & HTML bodies
* Notification type configuration, ResetPassword notification type
* Reset password
* Query cache
* Clippy + fmt
* Traces, fix typo, fix user email in ResetPassword
* send_email
* Models, db
* Remove dead code, adjust notification settings in migration
* Clippy fmt
* Delete dead code, fixes
* Fmt
* Update apps/labrinth/src/queue/email.rs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Remove old fixtures
* Unify email retry delay
* Fix type
* External notifications
* Remove `notifications_types_preference_restrictions`, as user notification preferences is out of scope for this PR
* Query cache, fmt, clippy
* Fix join in get_many_user_exposed_on_site
* Remove migration comment
* Query cache
* Update html body urls
* Remove comment
* Add paymentfailed.service variable to PaymentFailed notification variant
* Fix compile error
* Fix deleting notifications
* Update apps/labrinth/src/database/models/user_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update apps/labrinth/src/database/models/user_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update Cargo.toml
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update apps/labrinth/migrations/20250902133943_notification-extension.sql
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Address review comments
* Fix compliation
* Update apps/labrinth/src/database/models/users_notifications_preferences_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Use strfmt to format emails
* Configurable Reply-To
* Configurable Reply-To
* Refactor for email background task
* Send some emails inline
* Fix account creation email check
* Revert "Use strfmt to format emails"
This reverts commit e0d6614afe51fa6349918377e953ba294c34ae0b.
* Reintroduce fill_template
* Set password reset email inline
* Process more emails per index
* clippy fmt
* Query cache
---------
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
2025-09-15 15:02:29 -04:00
|
|
|
use labrinth::app_config;
|
2025-03-15 09:28:20 -05:00
|
|
|
use labrinth::background_task::BackgroundTask;
|
2023-10-06 09:57:33 -07:00
|
|
|
use labrinth::database::redis::RedisPool;
|
2025-06-19 14:46:12 -05:00
|
|
|
use labrinth::file_hosting::{S3BucketConfig, S3Host};
|
[DO NOT MERGE] Email notification system (#4338)
* Migration
* Fixup db models
* Redis
* Stuff
* Switch PKs to BIGSERIALs, insert to notifications_deliveries when inserting notifications
* Queue, templates
* Query cache
* Fixes, fixtures
* Perf, cache template data & HTML bodies
* Notification type configuration, ResetPassword notification type
* Reset password
* Query cache
* Clippy + fmt
* Traces, fix typo, fix user email in ResetPassword
* send_email
* Models, db
* Remove dead code, adjust notification settings in migration
* Clippy fmt
* Delete dead code, fixes
* Fmt
* Update apps/labrinth/src/queue/email.rs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Remove old fixtures
* Unify email retry delay
* Fix type
* External notifications
* Remove `notifications_types_preference_restrictions`, as user notification preferences is out of scope for this PR
* Query cache, fmt, clippy
* Fix join in get_many_user_exposed_on_site
* Remove migration comment
* Query cache
* Update html body urls
* Remove comment
* Add paymentfailed.service variable to PaymentFailed notification variant
* Fix compile error
* Fix deleting notifications
* Update apps/labrinth/src/database/models/user_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update apps/labrinth/src/database/models/user_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update Cargo.toml
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update apps/labrinth/migrations/20250902133943_notification-extension.sql
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Address review comments
* Fix compliation
* Update apps/labrinth/src/database/models/users_notifications_preferences_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Use strfmt to format emails
* Configurable Reply-To
* Configurable Reply-To
* Refactor for email background task
* Send some emails inline
* Fix account creation email check
* Revert "Use strfmt to format emails"
This reverts commit e0d6614afe51fa6349918377e953ba294c34ae0b.
* Reintroduce fill_template
* Set password reset email inline
* Process more emails per index
* clippy fmt
* Query cache
---------
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
2025-09-15 15:02:29 -04:00
|
|
|
use labrinth::queue::email::EmailQueue;
|
2024-01-05 08:20:56 -08:00
|
|
|
use labrinth::search;
|
Charge tax on products (#4361)
* Initial Anrok integration
* Query cache, fmt, clippy
* Fmt
* Use payment intent function in edit_subscription
* Attach Anrok client, use payments in index_billing
* Integrate Anrok with refunds
* Bug fixes
* More bugfixes
* Fix resubscriptions
* Medal promotion bugfixes
* Use stripe metadata constants everywhere
* Pre-fill values in products_tax_identifiers
* Cleanup billing route module
* Cleanup
* Email notification for tax charge
* Don't charge tax on users which haven't been notified of tax change
* Fix taxnotification.amount templates
* Update .env.docker-compose
* Update .env.local
* Clippy
* Fmt
* Query cache
* Periodically update tax amount on upcoming charges
* Fix queries
* Skip indexing tax amount on charges if no charges to process
* chore: query cache, clippy, fmt
* Fix a lot of things
* Remove test code
* chore: query cache, clippy, fmt
* Fix money formatting
* Fix conflicts
* Extra documentation, handle tax association properly
* Track loss in tax drift
* chore: query cache, clippy, fmt
* Add subscription.id variable
* chore: query cache, clippy, fmt
* chore: query cache, clippy, fmt
2025-09-25 12:29:29 +01:00
|
|
|
use labrinth::util::anrok;
|
2025-06-19 14:46:12 -05:00
|
|
|
use labrinth::util::env::parse_var;
|
2025-03-25 01:10:43 -07:00
|
|
|
use labrinth::util::ratelimit::rate_limit_middleware;
|
2023-10-06 09:57:33 -07:00
|
|
|
use labrinth::{check_env_vars, clickhouse, database, file_hosting, queue};
|
2025-06-14 02:10:12 +02:00
|
|
|
use std::ffi::CStr;
|
2025-10-03 14:02:20 +01:00
|
|
|
use std::str::FromStr;
|
2023-10-06 09:57:33 -07:00
|
|
|
use std::sync::Arc;
|
2025-10-03 14:02:20 +01:00
|
|
|
use tracing::level_filters::LevelFilter;
|
|
|
|
|
use tracing::{Instrument, error, info, info_span};
|
2025-03-09 13:01:24 -07:00
|
|
|
use tracing_actix_web::TracingLogger;
|
2025-10-03 14:02:20 +01:00
|
|
|
use tracing_ecs::ECSLayerBuilder;
|
|
|
|
|
use tracing_subscriber::EnvFilter;
|
|
|
|
|
use tracing_subscriber::layer::SubscriberExt;
|
|
|
|
|
use tracing_subscriber::util::SubscriberInitExt;
|
2020-05-09 22:11:48 -07:00
|
|
|
|
2025-05-05 21:38:10 +02:00
|
|
|
#[cfg(target_os = "linux")]
|
2024-01-27 18:13:52 -05:00
|
|
|
#[global_allocator]
|
2025-03-09 14:41:19 -07:00
|
|
|
static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
|
|
|
|
|
|
2025-05-09 07:27:55 -05:00
|
|
|
#[unsafe(export_name = "malloc_conf")]
|
2025-06-14 02:10:12 +02:00
|
|
|
pub static MALLOC_CONF: &CStr = c"prof:true,prof_active:true,lg_prof_sample:19";
|
2024-01-27 18:13:52 -05:00
|
|
|
|
2020-11-27 10:57:04 -07:00
|
|
|
#[derive(Clone)]
|
|
|
|
|
pub struct Pepper {
|
|
|
|
|
pub pepper: String,
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-15 09:28:20 -05:00
|
|
|
#[derive(Parser)]
|
|
|
|
|
#[command(version)]
|
|
|
|
|
struct Args {
|
|
|
|
|
/// Don't run regularly scheduled background tasks. This means the tasks should be run
|
|
|
|
|
/// manually with --run-background-task.
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
no_background_tasks: bool,
|
|
|
|
|
|
2025-03-25 01:10:43 -07:00
|
|
|
/// Don't automatically run migrations. This means the migrations should be run via --run-background-task.
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
no_migrations: bool,
|
|
|
|
|
|
2025-03-15 09:28:20 -05:00
|
|
|
/// Run a single background task and then exit. Perfect for cron jobs.
|
|
|
|
|
#[arg(long, value_enum, id = "task")]
|
|
|
|
|
run_background_task: Option<BackgroundTask>,
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-03 14:02:20 +01:00
|
|
|
#[derive(Debug, Clone, Default, PartialEq, Eq)]
|
|
|
|
|
enum OutputFormat {
|
|
|
|
|
#[default]
|
|
|
|
|
Human,
|
|
|
|
|
Json,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl FromStr for OutputFormat {
|
|
|
|
|
type Err = ();
|
|
|
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
|
match s {
|
|
|
|
|
"human" => Ok(Self::Human),
|
|
|
|
|
"json" => Ok(Self::Json),
|
|
|
|
|
_ => Err(()),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-09 22:11:48 -07:00
|
|
|
#[actix_rt::main]
|
2020-05-10 22:30:28 -07:00
|
|
|
async fn main() -> std::io::Result<()> {
|
2025-03-15 09:28:20 -05:00
|
|
|
let args = Args::parse();
|
|
|
|
|
|
2025-10-03 14:02:20 +01:00
|
|
|
color_eyre::install().expect("failed to install `color-eyre`");
|
2022-10-22 21:23:31 -07:00
|
|
|
dotenvy::dotenv().ok();
|
2025-10-03 14:02:20 +01:00
|
|
|
let console_layer = console_subscriber::spawn();
|
|
|
|
|
let env_filter = EnvFilter::builder()
|
|
|
|
|
.with_default_directive(LevelFilter::INFO.into())
|
|
|
|
|
.from_env_lossy();
|
|
|
|
|
|
|
|
|
|
let output_format =
|
|
|
|
|
dotenvy::var("LABRINTH_FORMAT").map_or(OutputFormat::Human, |format| {
|
|
|
|
|
format
|
|
|
|
|
.parse::<OutputFormat>()
|
|
|
|
|
.unwrap_or_else(|_| panic!("invalid output format '{format}'"))
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
match output_format {
|
|
|
|
|
OutputFormat::Human => {
|
|
|
|
|
tracing_subscriber::registry()
|
|
|
|
|
.with(console_layer)
|
|
|
|
|
.with(env_filter)
|
|
|
|
|
.with(tracing_subscriber::fmt::layer())
|
|
|
|
|
.init();
|
|
|
|
|
}
|
|
|
|
|
OutputFormat::Json => {
|
|
|
|
|
tracing_subscriber::registry()
|
|
|
|
|
.with(console_layer)
|
|
|
|
|
.with(env_filter)
|
|
|
|
|
.with(ECSLayerBuilder::default().stdout())
|
|
|
|
|
.init();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-28 13:28:58 -07:00
|
|
|
|
2020-11-05 09:38:03 -06:00
|
|
|
if check_env_vars() {
|
|
|
|
|
error!("Some environment variables are missing!");
|
2025-06-19 14:46:12 -05:00
|
|
|
std::process::exit(1);
|
2020-11-05 09:38:03 -06:00
|
|
|
}
|
2020-07-03 12:44:39 -05:00
|
|
|
|
2025-10-15 14:45:47 -06:00
|
|
|
rustls::crypto::aws_lc_rs::default_provider()
|
|
|
|
|
.install_default()
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
2022-11-20 19:50:14 -07:00
|
|
|
// DSN is from SENTRY_DSN env variable.
|
|
|
|
|
// Has no effect if not set.
|
2023-02-01 10:08:02 -07:00
|
|
|
let sentry = sentry::init(sentry::ClientOptions {
|
|
|
|
|
release: sentry::release_name!(),
|
|
|
|
|
traces_sample_rate: 0.1,
|
|
|
|
|
..Default::default()
|
|
|
|
|
});
|
2022-11-20 19:50:14 -07:00
|
|
|
if sentry.is_enabled() {
|
|
|
|
|
info!("Enabled Sentry integration");
|
2025-05-09 07:27:55 -05:00
|
|
|
unsafe {
|
|
|
|
|
std::env::set_var("RUST_BACKTRACE", "1");
|
|
|
|
|
}
|
2022-11-20 19:50:14 -07:00
|
|
|
}
|
|
|
|
|
|
2025-03-15 09:28:20 -05:00
|
|
|
if args.run_background_task.is_none() {
|
|
|
|
|
info!(
|
2025-08-09 16:51:04 +02:00
|
|
|
"Starting labrinth on {}",
|
2025-03-15 09:28:20 -05:00
|
|
|
dotenvy::var("BIND_ADDR").unwrap()
|
|
|
|
|
);
|
2022-02-21 18:57:40 -08:00
|
|
|
|
2025-03-25 01:10:43 -07:00
|
|
|
if !args.no_migrations {
|
|
|
|
|
database::check_for_migrations()
|
|
|
|
|
.await
|
|
|
|
|
.expect("An error occurred while running migrations.");
|
|
|
|
|
}
|
2025-03-15 08:32:45 -07:00
|
|
|
}
|
2020-08-28 17:48:01 +02:00
|
|
|
|
2020-07-23 22:46:33 +02:00
|
|
|
// Database Connector
|
2025-09-14 11:44:52 -04:00
|
|
|
let (pool, ro_pool) = database::connect_all()
|
2020-07-03 12:44:39 -05:00
|
|
|
.await
|
|
|
|
|
.expect("Database connection failed");
|
2020-07-16 10:16:35 -07:00
|
|
|
|
2023-07-07 12:20:16 -07:00
|
|
|
// Redis connector
|
2023-10-06 09:57:33 -07:00
|
|
|
let redis_pool = RedisPool::new(None);
|
2023-07-07 12:20:16 -07:00
|
|
|
|
2024-10-18 16:07:35 -07:00
|
|
|
let storage_backend =
|
|
|
|
|
dotenvy::var("STORAGE_BACKEND").unwrap_or_else(|_| "local".to_string());
|
|
|
|
|
|
|
|
|
|
let file_host: Arc<dyn file_hosting::FileHost + Send + Sync> =
|
|
|
|
|
match storage_backend.as_str() {
|
2025-06-19 14:46:12 -05:00
|
|
|
"s3" => {
|
|
|
|
|
let config_from_env = |bucket_type| S3BucketConfig {
|
|
|
|
|
name: parse_var(&format!("S3_{bucket_type}_BUCKET_NAME"))
|
|
|
|
|
.unwrap(),
|
|
|
|
|
uses_path_style: parse_var(&format!(
|
|
|
|
|
"S3_{bucket_type}_USES_PATH_STYLE_BUCKET"
|
|
|
|
|
))
|
|
|
|
|
.unwrap(),
|
|
|
|
|
region: parse_var(&format!("S3_{bucket_type}_REGION"))
|
|
|
|
|
.unwrap(),
|
|
|
|
|
url: parse_var(&format!("S3_{bucket_type}_URL")).unwrap(),
|
|
|
|
|
access_token: parse_var(&format!(
|
|
|
|
|
"S3_{bucket_type}_ACCESS_TOKEN"
|
|
|
|
|
))
|
|
|
|
|
.unwrap(),
|
|
|
|
|
secret: parse_var(&format!("S3_{bucket_type}_SECRET"))
|
|
|
|
|
.unwrap(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Arc::new(
|
|
|
|
|
S3Host::new(
|
|
|
|
|
config_from_env("PUBLIC"),
|
|
|
|
|
config_from_env("PRIVATE"),
|
|
|
|
|
)
|
|
|
|
|
.unwrap(),
|
2024-10-18 16:07:35 -07:00
|
|
|
)
|
2025-06-19 14:46:12 -05:00
|
|
|
}
|
2024-10-18 16:07:35 -07:00
|
|
|
"local" => Arc::new(file_hosting::MockHost::new()),
|
|
|
|
|
_ => panic!("Invalid storage backend specified. Aborting startup!"),
|
|
|
|
|
};
|
2020-07-16 10:16:35 -07:00
|
|
|
|
2023-08-02 14:43:04 -07:00
|
|
|
info!("Initializing clickhouse connection");
|
2023-10-06 09:57:33 -07:00
|
|
|
let mut clickhouse = clickhouse::init_client().await.unwrap();
|
2020-11-27 10:57:04 -07:00
|
|
|
|
2025-03-15 09:28:20 -05:00
|
|
|
let search_config = search::SearchConfig::new(None);
|
|
|
|
|
|
|
|
|
|
let stripe_client =
|
|
|
|
|
stripe::Client::new(dotenvy::var("STRIPE_API_KEY").unwrap());
|
|
|
|
|
|
Charge tax on products (#4361)
* Initial Anrok integration
* Query cache, fmt, clippy
* Fmt
* Use payment intent function in edit_subscription
* Attach Anrok client, use payments in index_billing
* Integrate Anrok with refunds
* Bug fixes
* More bugfixes
* Fix resubscriptions
* Medal promotion bugfixes
* Use stripe metadata constants everywhere
* Pre-fill values in products_tax_identifiers
* Cleanup billing route module
* Cleanup
* Email notification for tax charge
* Don't charge tax on users which haven't been notified of tax change
* Fix taxnotification.amount templates
* Update .env.docker-compose
* Update .env.local
* Clippy
* Fmt
* Query cache
* Periodically update tax amount on upcoming charges
* Fix queries
* Skip indexing tax amount on charges if no charges to process
* chore: query cache, clippy, fmt
* Fix a lot of things
* Remove test code
* chore: query cache, clippy, fmt
* Fix money formatting
* Fix conflicts
* Extra documentation, handle tax association properly
* Track loss in tax drift
* chore: query cache, clippy, fmt
* Add subscription.id variable
* chore: query cache, clippy, fmt
* chore: query cache, clippy, fmt
2025-09-25 12:29:29 +01:00
|
|
|
let anrok_client = anrok::Client::from_env().unwrap();
|
[DO NOT MERGE] Email notification system (#4338)
* Migration
* Fixup db models
* Redis
* Stuff
* Switch PKs to BIGSERIALs, insert to notifications_deliveries when inserting notifications
* Queue, templates
* Query cache
* Fixes, fixtures
* Perf, cache template data & HTML bodies
* Notification type configuration, ResetPassword notification type
* Reset password
* Query cache
* Clippy + fmt
* Traces, fix typo, fix user email in ResetPassword
* send_email
* Models, db
* Remove dead code, adjust notification settings in migration
* Clippy fmt
* Delete dead code, fixes
* Fmt
* Update apps/labrinth/src/queue/email.rs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Remove old fixtures
* Unify email retry delay
* Fix type
* External notifications
* Remove `notifications_types_preference_restrictions`, as user notification preferences is out of scope for this PR
* Query cache, fmt, clippy
* Fix join in get_many_user_exposed_on_site
* Remove migration comment
* Query cache
* Update html body urls
* Remove comment
* Add paymentfailed.service variable to PaymentFailed notification variant
* Fix compile error
* Fix deleting notifications
* Update apps/labrinth/src/database/models/user_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update apps/labrinth/src/database/models/user_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update Cargo.toml
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update apps/labrinth/migrations/20250902133943_notification-extension.sql
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Address review comments
* Fix compliation
* Update apps/labrinth/src/database/models/users_notifications_preferences_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Use strfmt to format emails
* Configurable Reply-To
* Configurable Reply-To
* Refactor for email background task
* Send some emails inline
* Fix account creation email check
* Revert "Use strfmt to format emails"
This reverts commit e0d6614afe51fa6349918377e953ba294c34ae0b.
* Reintroduce fill_template
* Set password reset email inline
* Process more emails per index
* clippy fmt
* Query cache
---------
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
2025-09-15 15:02:29 -04:00
|
|
|
let email_queue =
|
|
|
|
|
EmailQueue::init(pool.clone(), redis_pool.clone()).unwrap();
|
|
|
|
|
|
2025-03-15 09:28:20 -05:00
|
|
|
if let Some(task) = args.run_background_task {
|
|
|
|
|
info!("Running task {task:?} and exiting");
|
[DO NOT MERGE] Email notification system (#4338)
* Migration
* Fixup db models
* Redis
* Stuff
* Switch PKs to BIGSERIALs, insert to notifications_deliveries when inserting notifications
* Queue, templates
* Query cache
* Fixes, fixtures
* Perf, cache template data & HTML bodies
* Notification type configuration, ResetPassword notification type
* Reset password
* Query cache
* Clippy + fmt
* Traces, fix typo, fix user email in ResetPassword
* send_email
* Models, db
* Remove dead code, adjust notification settings in migration
* Clippy fmt
* Delete dead code, fixes
* Fmt
* Update apps/labrinth/src/queue/email.rs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Remove old fixtures
* Unify email retry delay
* Fix type
* External notifications
* Remove `notifications_types_preference_restrictions`, as user notification preferences is out of scope for this PR
* Query cache, fmt, clippy
* Fix join in get_many_user_exposed_on_site
* Remove migration comment
* Query cache
* Update html body urls
* Remove comment
* Add paymentfailed.service variable to PaymentFailed notification variant
* Fix compile error
* Fix deleting notifications
* Update apps/labrinth/src/database/models/user_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update apps/labrinth/src/database/models/user_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update Cargo.toml
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update apps/labrinth/migrations/20250902133943_notification-extension.sql
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Address review comments
* Fix compliation
* Update apps/labrinth/src/database/models/users_notifications_preferences_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Use strfmt to format emails
* Configurable Reply-To
* Configurable Reply-To
* Refactor for email background task
* Send some emails inline
* Fix account creation email check
* Revert "Use strfmt to format emails"
This reverts commit e0d6614afe51fa6349918377e953ba294c34ae0b.
* Reintroduce fill_template
* Set password reset email inline
* Process more emails per index
* clippy fmt
* Query cache
---------
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
2025-09-15 15:02:29 -04:00
|
|
|
task.run(
|
|
|
|
|
pool,
|
|
|
|
|
redis_pool,
|
|
|
|
|
search_config,
|
|
|
|
|
clickhouse,
|
|
|
|
|
stripe_client,
|
Charge tax on products (#4361)
* Initial Anrok integration
* Query cache, fmt, clippy
* Fmt
* Use payment intent function in edit_subscription
* Attach Anrok client, use payments in index_billing
* Integrate Anrok with refunds
* Bug fixes
* More bugfixes
* Fix resubscriptions
* Medal promotion bugfixes
* Use stripe metadata constants everywhere
* Pre-fill values in products_tax_identifiers
* Cleanup billing route module
* Cleanup
* Email notification for tax charge
* Don't charge tax on users which haven't been notified of tax change
* Fix taxnotification.amount templates
* Update .env.docker-compose
* Update .env.local
* Clippy
* Fmt
* Query cache
* Periodically update tax amount on upcoming charges
* Fix queries
* Skip indexing tax amount on charges if no charges to process
* chore: query cache, clippy, fmt
* Fix a lot of things
* Remove test code
* chore: query cache, clippy, fmt
* Fix money formatting
* Fix conflicts
* Extra documentation, handle tax association properly
* Track loss in tax drift
* chore: query cache, clippy, fmt
* Add subscription.id variable
* chore: query cache, clippy, fmt
* chore: query cache, clippy, fmt
2025-09-25 12:29:29 +01:00
|
|
|
anrok_client.clone(),
|
[DO NOT MERGE] Email notification system (#4338)
* Migration
* Fixup db models
* Redis
* Stuff
* Switch PKs to BIGSERIALs, insert to notifications_deliveries when inserting notifications
* Queue, templates
* Query cache
* Fixes, fixtures
* Perf, cache template data & HTML bodies
* Notification type configuration, ResetPassword notification type
* Reset password
* Query cache
* Clippy + fmt
* Traces, fix typo, fix user email in ResetPassword
* send_email
* Models, db
* Remove dead code, adjust notification settings in migration
* Clippy fmt
* Delete dead code, fixes
* Fmt
* Update apps/labrinth/src/queue/email.rs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Remove old fixtures
* Unify email retry delay
* Fix type
* External notifications
* Remove `notifications_types_preference_restrictions`, as user notification preferences is out of scope for this PR
* Query cache, fmt, clippy
* Fix join in get_many_user_exposed_on_site
* Remove migration comment
* Query cache
* Update html body urls
* Remove comment
* Add paymentfailed.service variable to PaymentFailed notification variant
* Fix compile error
* Fix deleting notifications
* Update apps/labrinth/src/database/models/user_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update apps/labrinth/src/database/models/user_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update Cargo.toml
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update apps/labrinth/migrations/20250902133943_notification-extension.sql
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Address review comments
* Fix compliation
* Update apps/labrinth/src/database/models/users_notifications_preferences_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Use strfmt to format emails
* Configurable Reply-To
* Configurable Reply-To
* Refactor for email background task
* Send some emails inline
* Fix account creation email check
* Revert "Use strfmt to format emails"
This reverts commit e0d6614afe51fa6349918377e953ba294c34ae0b.
* Reintroduce fill_template
* Set password reset email inline
* Process more emails per index
* clippy fmt
* Query cache
---------
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
2025-09-15 15:02:29 -04:00
|
|
|
email_queue,
|
|
|
|
|
)
|
|
|
|
|
.await;
|
2025-03-15 09:28:20 -05:00
|
|
|
return Ok(());
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-18 16:07:35 -07:00
|
|
|
let maxmind_reader =
|
|
|
|
|
Arc::new(queue::maxmind::MaxMindIndexer::new().await.unwrap());
|
2022-11-20 19:50:14 -07:00
|
|
|
|
2023-10-06 17:58:02 -05:00
|
|
|
let prometheus = PrometheusMetricsBuilder::new("labrinth")
|
|
|
|
|
.endpoint("/metrics")
|
2025-03-05 15:40:46 -08:00
|
|
|
.exclude_regex(r"^/api/v1/.*$")
|
|
|
|
|
.exclude_regex(r"^/maven/.*$")
|
2024-12-27 22:44:09 -07:00
|
|
|
.exclude("/_internal/launcher_socket")
|
2025-03-05 15:40:46 -08:00
|
|
|
.mask_unmatched_patterns("UNKNOWN")
|
2023-10-06 17:58:02 -05:00
|
|
|
.build()
|
|
|
|
|
.expect("Failed to create prometheus metrics middleware");
|
|
|
|
|
|
2025-03-07 17:16:45 -08:00
|
|
|
database::register_and_set_metrics(&pool, &prometheus.registry)
|
|
|
|
|
.await
|
|
|
|
|
.expect("Failed to register database metrics");
|
|
|
|
|
redis_pool
|
|
|
|
|
.register_and_set_metrics(&prometheus.registry)
|
|
|
|
|
.await
|
|
|
|
|
.expect("Failed to register redis metrics");
|
2025-03-10 16:45:36 -05:00
|
|
|
|
2025-05-05 21:38:10 +02:00
|
|
|
#[cfg(target_os = "linux")]
|
2025-05-15 22:47:29 +02:00
|
|
|
labrinth::routes::debug::jemalloc_memory_stats(&prometheus.registry)
|
2025-03-09 14:41:19 -07:00
|
|
|
.expect("Failed to register jemalloc metrics");
|
2025-03-07 17:16:45 -08:00
|
|
|
|
2024-04-22 13:09:35 -07:00
|
|
|
let labrinth_config = labrinth::app_setup(
|
2023-10-06 09:57:33 -07:00
|
|
|
pool.clone(),
|
2025-09-14 11:44:52 -04:00
|
|
|
ro_pool.clone(),
|
2023-10-06 09:57:33 -07:00
|
|
|
redis_pool.clone(),
|
2024-01-05 08:20:56 -08:00
|
|
|
search_config.clone(),
|
2023-10-06 09:57:33 -07:00
|
|
|
&mut clickhouse,
|
|
|
|
|
file_host.clone(),
|
|
|
|
|
maxmind_reader.clone(),
|
2025-03-15 09:28:20 -05:00
|
|
|
stripe_client,
|
Charge tax on products (#4361)
* Initial Anrok integration
* Query cache, fmt, clippy
* Fmt
* Use payment intent function in edit_subscription
* Attach Anrok client, use payments in index_billing
* Integrate Anrok with refunds
* Bug fixes
* More bugfixes
* Fix resubscriptions
* Medal promotion bugfixes
* Use stripe metadata constants everywhere
* Pre-fill values in products_tax_identifiers
* Cleanup billing route module
* Cleanup
* Email notification for tax charge
* Don't charge tax on users which haven't been notified of tax change
* Fix taxnotification.amount templates
* Update .env.docker-compose
* Update .env.local
* Clippy
* Fmt
* Query cache
* Periodically update tax amount on upcoming charges
* Fix queries
* Skip indexing tax amount on charges if no charges to process
* chore: query cache, clippy, fmt
* Fix a lot of things
* Remove test code
* chore: query cache, clippy, fmt
* Fix money formatting
* Fix conflicts
* Extra documentation, handle tax association properly
* Track loss in tax drift
* chore: query cache, clippy, fmt
* Add subscription.id variable
* chore: query cache, clippy, fmt
* chore: query cache, clippy, fmt
2025-09-25 12:29:29 +01:00
|
|
|
anrok_client.clone(),
|
[DO NOT MERGE] Email notification system (#4338)
* Migration
* Fixup db models
* Redis
* Stuff
* Switch PKs to BIGSERIALs, insert to notifications_deliveries when inserting notifications
* Queue, templates
* Query cache
* Fixes, fixtures
* Perf, cache template data & HTML bodies
* Notification type configuration, ResetPassword notification type
* Reset password
* Query cache
* Clippy + fmt
* Traces, fix typo, fix user email in ResetPassword
* send_email
* Models, db
* Remove dead code, adjust notification settings in migration
* Clippy fmt
* Delete dead code, fixes
* Fmt
* Update apps/labrinth/src/queue/email.rs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Remove old fixtures
* Unify email retry delay
* Fix type
* External notifications
* Remove `notifications_types_preference_restrictions`, as user notification preferences is out of scope for this PR
* Query cache, fmt, clippy
* Fix join in get_many_user_exposed_on_site
* Remove migration comment
* Query cache
* Update html body urls
* Remove comment
* Add paymentfailed.service variable to PaymentFailed notification variant
* Fix compile error
* Fix deleting notifications
* Update apps/labrinth/src/database/models/user_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update apps/labrinth/src/database/models/user_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update Cargo.toml
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update apps/labrinth/migrations/20250902133943_notification-extension.sql
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Address review comments
* Fix compliation
* Update apps/labrinth/src/database/models/users_notifications_preferences_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Use strfmt to format emails
* Configurable Reply-To
* Configurable Reply-To
* Refactor for email background task
* Send some emails inline
* Fix account creation email check
* Revert "Use strfmt to format emails"
This reverts commit e0d6614afe51fa6349918377e953ba294c34ae0b.
* Reintroduce fill_template
* Set password reset email inline
* Process more emails per index
* clippy fmt
* Query cache
---------
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
2025-09-15 15:02:29 -04:00
|
|
|
email_queue,
|
2025-03-15 09:28:20 -05:00
|
|
|
!args.no_background_tasks,
|
2023-10-06 09:57:33 -07:00
|
|
|
);
|
|
|
|
|
|
2024-03-27 15:56:29 -07:00
|
|
|
info!("Starting Actix HTTP server!");
|
|
|
|
|
|
2020-05-09 22:11:48 -07:00
|
|
|
HttpServer::new(move || {
|
|
|
|
|
App::new()
|
2025-03-09 13:01:24 -07:00
|
|
|
.wrap(TracingLogger::default())
|
2025-10-03 14:02:20 +01:00
|
|
|
.wrap_fn(|req, srv| {
|
|
|
|
|
// We capture the same fields as `tracing-actix-web`'s `RootSpanBuilder`.
|
|
|
|
|
// See `root_span!` macro.
|
|
|
|
|
let span = info_span!(
|
|
|
|
|
"HTTP request",
|
|
|
|
|
http.method = %req.method(),
|
|
|
|
|
http.client_ip = %req.connection_info().realip_remote_addr().unwrap_or(""),
|
|
|
|
|
http.user_agent = %req.headers().get("User-Agent").map_or("", |h| h.to_str().unwrap_or("")),
|
|
|
|
|
http.target = %req.uri().path_and_query().map_or("", |p| p.as_str()),
|
|
|
|
|
http.authenticated = %req.headers().get("Authorization").is_some()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let fut = srv.call(req);
|
|
|
|
|
async move {
|
|
|
|
|
fut.await.inspect(|resp| {
|
|
|
|
|
let _span = info_span!(
|
|
|
|
|
"HTTP response",
|
|
|
|
|
http.status = %resp.response().status().as_u16(),
|
|
|
|
|
).entered();
|
|
|
|
|
|
|
|
|
|
resp.response()
|
|
|
|
|
.error()
|
|
|
|
|
.inspect(|err| log_error(err));
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
.instrument(span)
|
|
|
|
|
})
|
2023-10-06 17:58:02 -05:00
|
|
|
.wrap(prometheus.clone())
|
2025-03-25 01:10:43 -07:00
|
|
|
.wrap(from_fn(rate_limit_middleware))
|
2023-02-15 15:05:28 -07:00
|
|
|
.wrap(actix_web::middleware::Compress::default())
|
2023-08-02 14:43:04 -07:00
|
|
|
.wrap(sentry_actix::Sentry::new())
|
[DO NOT MERGE] Email notification system (#4338)
* Migration
* Fixup db models
* Redis
* Stuff
* Switch PKs to BIGSERIALs, insert to notifications_deliveries when inserting notifications
* Queue, templates
* Query cache
* Fixes, fixtures
* Perf, cache template data & HTML bodies
* Notification type configuration, ResetPassword notification type
* Reset password
* Query cache
* Clippy + fmt
* Traces, fix typo, fix user email in ResetPassword
* send_email
* Models, db
* Remove dead code, adjust notification settings in migration
* Clippy fmt
* Delete dead code, fixes
* Fmt
* Update apps/labrinth/src/queue/email.rs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Remove old fixtures
* Unify email retry delay
* Fix type
* External notifications
* Remove `notifications_types_preference_restrictions`, as user notification preferences is out of scope for this PR
* Query cache, fmt, clippy
* Fix join in get_many_user_exposed_on_site
* Remove migration comment
* Query cache
* Update html body urls
* Remove comment
* Add paymentfailed.service variable to PaymentFailed notification variant
* Fix compile error
* Fix deleting notifications
* Update apps/labrinth/src/database/models/user_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update apps/labrinth/src/database/models/user_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update Cargo.toml
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update apps/labrinth/migrations/20250902133943_notification-extension.sql
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Address review comments
* Fix compliation
* Update apps/labrinth/src/database/models/users_notifications_preferences_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Use strfmt to format emails
* Configurable Reply-To
* Configurable Reply-To
* Refactor for email background task
* Send some emails inline
* Fix account creation email check
* Revert "Use strfmt to format emails"
This reverts commit e0d6614afe51fa6349918377e953ba294c34ae0b.
* Reintroduce fill_template
* Set password reset email inline
* Process more emails per index
* clippy fmt
* Query cache
---------
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
2025-09-15 15:02:29 -04:00
|
|
|
.configure(|cfg| app_config(cfg, labrinth_config.clone()))
|
2020-05-09 22:11:48 -07:00
|
|
|
})
|
2022-10-22 21:23:31 -07:00
|
|
|
.bind(dotenvy::var("BIND_ADDR").unwrap())?
|
2020-05-27 20:51:28 +02:00
|
|
|
.run()
|
|
|
|
|
.await
|
2020-05-09 22:11:48 -07:00
|
|
|
}
|
2025-10-03 14:02:20 +01:00
|
|
|
|
|
|
|
|
fn log_error(err: &actix_web::Error) {
|
|
|
|
|
if err.as_response_error().status_code().is_client_error() {
|
|
|
|
|
tracing::debug!(
|
|
|
|
|
"Error encountered while processing the incoming HTTP request: {err}"
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
tracing::error!(
|
|
|
|
|
"Error encountered while processing the incoming HTTP request: {err}"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|