Added notifications, image preview generator

This commit is contained in:
Ultradesu
2026-08-08 11:02:56 +01:00
parent f7a89b431d
commit c4823b7e64
16 changed files with 1926 additions and 100 deletions
+40 -5
View File
@@ -7,6 +7,7 @@ mod telegram;
mod turnstile;
mod tz;
mod uploads;
mod web_push;
use tracing_subscriber;
@@ -17,7 +18,7 @@ use cot::config::{
};
use cot::db::migrations::SyncDynMigration;
use cot::middleware::SessionMiddleware;
use cot::project::{MiddlewareContext, RegisterAppsContext, RootHandler};
use cot::project::{MiddlewareContext, ProjectContext, RegisterAppsContext, RootHandler};
use cot::router::Router;
use cot::session::db::SessionApp;
use cot::{App, AppBuilder, Project};
@@ -40,11 +41,17 @@ impl App for PettingApp {
struct PublicApp;
#[async_trait::async_trait]
impl App for PublicApp {
fn name(&self) -> &'static str {
"public"
}
async fn init(&self, context: &mut ProjectContext) -> cot::Result<()> {
web_push::initialize(context.database()).await;
Ok(())
}
fn router(&self) -> Router {
public::public_router()
}
@@ -73,7 +80,13 @@ fn debug_enabled(config_name: &str) -> bool {
fn database_url() -> String {
std::env::var("WEB_PETTING_DATABASE_URL")
.or_else(|_| std::env::var("DATABASE_URL"))
.unwrap_or_else(|_| "postgresql://postgres:postgres@localhost:5432/web_petting".to_string())
.unwrap_or_else(|_| {
eprintln!(
"WEB_PETTING_DATABASE_URL and DATABASE_URL are not set; using the local default \
postgresql://postgres:postgres@localhost:5432/web_petting"
);
"postgresql://postgres:postgres@localhost:5432/web_petting".to_string()
})
}
impl Project for PettingProject {
@@ -120,10 +133,32 @@ impl Project for PettingProject {
}
}
#[cot::main]
fn main() -> impl Project {
fn main() {
let filter = tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info"));
let _ = tracing_subscriber::fmt().with_env_filter(filter).try_init();
PettingProject
let runtime = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.expect("failed to build Tokio runtime");
if let Err(error) = runtime.block_on(cot::run_cli(PettingProject)) {
let message = error.to_string();
let details = format!("{error:?}");
eprintln!("Failed to start web-petting: {message}\nDetails: {details}");
if details.contains("28P01") || details.contains("password authentication failed") {
eprintln!(
"\nPostgreSQL rejected the configured username or password.\n\
Set the connection string before starting the application, for example:\n\n \
WEB_PETTING_DATABASE_URL='postgresql://postgres:YOUR_PASSWORD@localhost:5432/web_petting' cargo run\n\n\
WEB_PETTING_DATABASE_URL takes priority over DATABASE_URL.\n\
Check the current value with: printenv WEB_PETTING_DATABASE_URL"
);
} else if message.to_ascii_lowercase().contains("database") {
eprintln!(
"\nConfigure PostgreSQL with WEB_PETTING_DATABASE_URL or DATABASE_URL.\n\
Example:\n\n WEB_PETTING_DATABASE_URL='postgresql://postgres:YOUR_PASSWORD@localhost:5432/web_petting' cargo run"
);
}
std::process::exit(1);
}
}