fix,feat: mention behavior and page titles

This commit is contained in:
Robert Perce 2026-02-14 13:35:59 -06:00
parent 7e2f5d0a18
commit 79a054ab40
22 changed files with 314 additions and 140 deletions

View file

@ -3,7 +3,8 @@ use axum::response::{IntoResponse, Response};
use axum::routing::get;
use axum_login::AuthUser;
use axum_login::{AuthManagerLayerBuilder, login_required};
use clap::{Parser, Subcommand, arg, command};
use cache_bust::asset;
use clap::{Parser, Subcommand};
use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};
use std::collections::HashMap;
use std::str::FromStr;
@ -11,7 +12,7 @@ use std::sync::{Arc, RwLock};
use tokio::net::TcpListener;
use tokio::signal;
use tokio::task::AbortHandle;
use tower_http::services::ServeDir;
use tower_http::services::{ServeDir,ServeFile};
use tower_sessions::{ExpiredDeletion, Expiry, SessionManagerLayer, cookie::Key};
use tower_sessions_sqlx_store::SqliteStore;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
@ -108,10 +109,21 @@ enum Commands {
port: u32,
},
/// set password of user, creating if necessary
SetPassword {
/// username to create or set password
username: String,
},
/// set a user's ephemerality
SetEphemeral {
/// username to set ephemerality
username: String,
#[arg(action = clap::ArgAction::Set)]
ephemeral: bool,
},
}
async fn serve(port: &u32) -> Result<(), anyhow::Error> {
@ -169,6 +181,7 @@ async fn serve(port: &u32) -> Result<(), anyhow::Error> {
.merge(auth::router())
.merge(ics::router())
.nest_service("/static", ServeDir::new("./hashed_static"))
.nest_service("/favicon.ico", ServeFile::new(format!("./hashed_static/{}", asset!("favicon.ico"))))
.layer(auth_layer)
.layer(tower_http::trace::TraceLayer::new_for_http())
.with_state(state);
@ -218,6 +231,46 @@ async fn main() -> Result<(), anyhow::Error> {
println!("No update was made; probably something went wrong.");
}
}
Some(Commands::SetEphemeral { username, ephemeral }) => {
let users_db = {
let db_options = SqliteConnectOptions::from_str("users.db")?
.create_if_missing(true)
.to_owned();
let db = SqlitePoolOptions::new().connect_with(db_options).await?;
sqlx::migrate!("./migrations/users.db").run(&db).await?;
db
};
let eph: Option<bool> = sqlx::query_scalar(
"select ephemeral from users where username = ?"
)
.bind(&username)
.fetch_optional(&users_db)
.await?;
if let Some(eph) = eph {
if eph == *ephemeral {
println!("User {} is already {}.", username, if eph { "ephemeral" } else { "not ephemeral" });
} else {
let update = sqlx::query(
"update users set ephemeral=$1 where username = $2",
)
.bind(ephemeral)
.bind(&username)
.execute(&users_db)
.await?;
if update.rows_affected() > 0 {
println!("Updated ephemerality for {}.", username);
} else {
println!("No update was made; probably something went wrong.");
}
}
} else {
println!("User {} does not exist. Create them first with set-password.", username);
}
}
Some(Commands::Serve { port }) => {
serve(port).await?;
}