license and some functions

This commit is contained in:
Mateusz Gruszczyński
2026-07-29 14:03:46 +02:00
parent 0655cfe48c
commit ef8dfc67c1
56 changed files with 2586 additions and 547 deletions
+46 -11
View File
@@ -1,4 +1,12 @@
mod row_decode;
/*
* Copyright (C) 2026 Mateusz Gruszczyński @linuxiarz.pl
* Source-Available Code / Dual-Licensed.
*
* Free for non-commercial and evaluation use under terms of BSL/GPLv3.
* Commercial or production use requires a valid paid license.
* See LICENSE file in repository root for details.
*/
mod api;
mod app;
mod assets;
@@ -7,6 +15,7 @@ mod config;
mod database;
mod db;
mod queries;
mod row_decode;
mod state;
mod storage;
mod websocket;
@@ -20,7 +29,6 @@ use tokio::net::TcpListener;
use tracing::{info, warn};
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
rustls::crypto::ring::default_provider()
@@ -33,10 +41,18 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = Config::load(cli.config.as_deref())?;
if matches!(cli.command, Command::CheckConfig) {
println!("configuration is valid{}", cli.config.as_ref().map(|path| format!(" ({})", path.display())).unwrap_or_default());
println!(
"configuration is valid{}",
cli.config
.as_ref()
.map(|path| format!(" ({})", path.display()))
.unwrap_or_default()
);
return Ok(());
}
info!(
"RustPad version" = %config.asset_version,
Copyright="@linuxiarz.pl Mateusz Gruszczyński",
host = %config.host,
port = config.port,
database_kind = %database_kind_label(&config.database_url),
@@ -103,12 +119,25 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut interval = tokio::time::interval(std::time::Duration::from_secs(24 * 60 * 60));
loop {
interval.tick().await;
let cutoff = (chrono::Utc::now() - chrono::Duration::days(cleanup_state.unconfirmed_account_ttl_days)).to_rfc3339();
match sqlx::query(crate::queries::get(cleanup_state.db.kind(), crate::queries::AUTH_DELETE_EXPIRED_UNCONFIRMED_USERS))
.bind(cutoff).execute(cleanup_state.db.pool()).await {
Ok(result) if result.rows_affected() > 0 => info!(deleted = result.rows_affected(), "removed expired unconfirmed accounts"),
Ok(_) => {},
Err(error) => tracing::error!(%error, "failed to remove expired unconfirmed accounts"),
let cutoff = (chrono::Utc::now()
- chrono::Duration::days(cleanup_state.unconfirmed_account_ttl_days))
.to_rfc3339();
match sqlx::query(crate::queries::get(
cleanup_state.db.kind(),
crate::queries::AUTH_DELETE_EXPIRED_UNCONFIRMED_USERS,
))
.bind(cutoff)
.execute(cleanup_state.db.pool())
.await
{
Ok(result) if result.rows_affected() > 0 => info!(
deleted = result.rows_affected(),
"removed expired unconfirmed accounts"
),
Ok(_) => {}
Err(error) => {
tracing::error!(%error, "failed to remove expired unconfirmed accounts")
}
}
}
});
@@ -130,7 +159,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}
#[derive(Clone, Copy)]
enum Command { Run, CheckConfig, Migrate }
enum Command {
Run,
CheckConfig,
Migrate,
}
struct Cli {
command: Command,
@@ -170,7 +203,9 @@ fn parse_command() -> Result<Cli, Box<dyn std::error::Error>> {
}
command = Command::Migrate;
}
_ if arg.starts_with('-') => return Err(format!("unknown option: {arg}; use --help").into()),
_ if arg.starts_with('-') => {
return Err(format!("unknown option: {arg}; use --help").into());
}
_ => return Err(format!("unknown command: {arg}; use --help").into()),
}
}