2026-04-29 17:49:07 +03:00
|
|
|
mod admin;
|
|
|
|
|
mod i18n;
|
|
|
|
|
mod migrations;
|
|
|
|
|
pub mod models;
|
|
|
|
|
mod public;
|
|
|
|
|
mod telegram;
|
2026-05-18 22:12:54 +03:00
|
|
|
mod turnstile;
|
2026-05-11 13:43:16 +01:00
|
|
|
mod tz;
|
2026-04-29 17:49:07 +03:00
|
|
|
|
2026-05-18 17:07:43 +03:00
|
|
|
use tracing_subscriber;
|
|
|
|
|
|
2026-04-29 17:49:07 +03:00
|
|
|
use cot::cli::CliMetadata;
|
|
|
|
|
use cot::config::{
|
2026-05-19 00:32:36 +03:00
|
|
|
DatabaseConfig, MiddlewareConfig, ProjectConfig, SameSite, SessionMiddlewareConfig,
|
|
|
|
|
SessionStoreConfig, SessionStoreTypeConfig,
|
2026-04-29 17:49:07 +03:00
|
|
|
};
|
|
|
|
|
use cot::db::migrations::SyncDynMigration;
|
|
|
|
|
use cot::middleware::SessionMiddleware;
|
|
|
|
|
use cot::project::{MiddlewareContext, RegisterAppsContext, RootHandler};
|
|
|
|
|
use cot::router::Router;
|
|
|
|
|
use cot::session::db::SessionApp;
|
|
|
|
|
use cot::{App, AppBuilder, Project};
|
|
|
|
|
|
|
|
|
|
struct PettingApp;
|
|
|
|
|
|
|
|
|
|
impl App for PettingApp {
|
|
|
|
|
fn name(&self) -> &'static str {
|
|
|
|
|
"web-petting"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn migrations(&self) -> Vec<Box<SyncDynMigration>> {
|
|
|
|
|
cot::db::migrations::wrap_migrations(migrations::MIGRATIONS)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn router(&self) -> Router {
|
|
|
|
|
admin::admin_router()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct PublicApp;
|
|
|
|
|
|
|
|
|
|
impl App for PublicApp {
|
|
|
|
|
fn name(&self) -> &'static str {
|
|
|
|
|
"public"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn router(&self) -> Router {
|
|
|
|
|
public::public_router()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct PettingProject;
|
|
|
|
|
|
2026-06-04 13:41:18 +03:00
|
|
|
fn parse_bool_env(name: &str) -> Option<bool> {
|
|
|
|
|
let value = std::env::var(name).ok()?;
|
|
|
|
|
match value.trim().to_ascii_lowercase().as_str() {
|
|
|
|
|
"1" | "true" | "yes" | "on" => Some(true),
|
|
|
|
|
"0" | "false" | "no" | "off" => Some(false),
|
|
|
|
|
_ => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn debug_enabled(config_name: &str) -> bool {
|
|
|
|
|
parse_bool_env("WEB_PETTING_DEBUG").unwrap_or_else(|| {
|
|
|
|
|
matches!(
|
|
|
|
|
config_name,
|
|
|
|
|
"dev" | "development" | "debug" | "local" | "test"
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-29 17:49:07 +03:00
|
|
|
impl Project for PettingProject {
|
|
|
|
|
fn cli_metadata(&self) -> CliMetadata {
|
|
|
|
|
cot::cli::metadata!()
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-04 13:41:18 +03:00
|
|
|
fn config(&self, config_name: &str) -> cot::Result<ProjectConfig> {
|
2026-04-29 17:49:07 +03:00
|
|
|
Ok(ProjectConfig::builder()
|
2026-06-04 13:41:18 +03:00
|
|
|
.debug(debug_enabled(config_name))
|
2026-04-29 17:49:07 +03:00
|
|
|
.database(
|
|
|
|
|
DatabaseConfig::builder()
|
|
|
|
|
.url("sqlite://db.sqlite3?mode=rwc")
|
|
|
|
|
.build(),
|
|
|
|
|
)
|
|
|
|
|
.middlewares(
|
|
|
|
|
MiddlewareConfig::builder()
|
|
|
|
|
.session(
|
|
|
|
|
SessionMiddlewareConfig::builder()
|
|
|
|
|
.secure(false)
|
2026-05-19 00:32:36 +03:00
|
|
|
.same_site(SameSite::Lax)
|
2026-04-29 17:49:07 +03:00
|
|
|
.store(
|
|
|
|
|
SessionStoreConfig::builder()
|
|
|
|
|
.store_type(SessionStoreTypeConfig::Database)
|
|
|
|
|
.build(),
|
|
|
|
|
)
|
|
|
|
|
.build(),
|
|
|
|
|
)
|
|
|
|
|
.build(),
|
|
|
|
|
)
|
|
|
|
|
.build())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn register_apps(&self, apps: &mut AppBuilder, _context: &RegisterAppsContext) {
|
|
|
|
|
apps.register(SessionApp::new());
|
|
|
|
|
apps.register_with_views(PublicApp, "");
|
|
|
|
|
apps.register_with_views(PettingApp, "/admin");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn middlewares(
|
|
|
|
|
&self,
|
|
|
|
|
handler: cot::project::RootHandlerBuilder,
|
|
|
|
|
context: &MiddlewareContext,
|
|
|
|
|
) -> RootHandler {
|
|
|
|
|
handler
|
|
|
|
|
.middleware(SessionMiddleware::from_context(context))
|
|
|
|
|
.build()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cot::main]
|
|
|
|
|
fn main() -> impl Project {
|
2026-05-18 17:07:43 +03:00
|
|
|
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();
|
2026-04-29 17:49:07 +03:00
|
|
|
PettingProject
|
|
|
|
|
}
|