feat: report version information
This commit is contained in:
parent
559c1f1760
commit
e74fe354d0
5 changed files with 223 additions and 30 deletions
55
src/main.rs
55
src/main.rs
|
|
@ -12,7 +12,7 @@ use std::sync::{Arc, RwLock};
|
|||
use tokio::net::TcpListener;
|
||||
use tokio::signal;
|
||||
use tokio::task::AbortHandle;
|
||||
use tower_http::services::{ServeDir,ServeFile};
|
||||
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};
|
||||
|
|
@ -124,6 +124,8 @@ enum Commands {
|
|||
ephemeral: bool,
|
||||
},
|
||||
|
||||
/// print version information
|
||||
Version,
|
||||
}
|
||||
|
||||
async fn serve(port: &u32) -> Result<(), anyhow::Error> {
|
||||
|
|
@ -181,7 +183,10 @@ 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"))))
|
||||
.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);
|
||||
|
|
@ -231,7 +236,10 @@ async fn main() -> Result<(), anyhow::Error> {
|
|||
println!("No update was made; probably something went wrong.");
|
||||
}
|
||||
}
|
||||
Some(Commands::SetEphemeral { username, ephemeral }) => {
|
||||
Some(Commands::SetEphemeral {
|
||||
username,
|
||||
ephemeral,
|
||||
}) => {
|
||||
let users_db = {
|
||||
let db_options = SqliteConnectOptions::from_str("users.db")?
|
||||
.create_if_missing(true)
|
||||
|
|
@ -242,23 +250,24 @@ async fn main() -> Result<(), anyhow::Error> {
|
|||
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)
|
||||
let eph: Option<bool> =
|
||||
sqlx::query_scalar("select ephemeral from users where username = ?")
|
||||
.bind(&username)
|
||||
.execute(&users_db)
|
||||
.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);
|
||||
|
|
@ -267,13 +276,19 @@ async fn main() -> Result<(), anyhow::Error> {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
println!("User {} does not exist. Create them first with set-password.", username);
|
||||
println!(
|
||||
"User {} does not exist. Create them first with set-password.",
|
||||
username
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Some(Commands::Serve { port }) => {
|
||||
serve(port).await?;
|
||||
}
|
||||
Some(Commands::Version) => {
|
||||
println!("mascarpone v{}", env!("CARGO_PKG_VERSION"));
|
||||
println!("from git commit {}", env!("VERGEN_GIT_SHA"));
|
||||
}
|
||||
None => {
|
||||
serve(&3000).await?;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue