2026-04-29 17:49:07 +03:00
|
|
|
mod admin;
|
|
|
|
|
mod i18n;
|
|
|
|
|
mod migrations;
|
|
|
|
|
pub mod models;
|
|
|
|
|
mod public;
|
|
|
|
|
mod telegram;
|
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::{
|
|
|
|
|
DatabaseConfig, MiddlewareConfig, ProjectConfig, SessionMiddlewareConfig, SessionStoreConfig,
|
|
|
|
|
SessionStoreTypeConfig,
|
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
impl Project for PettingProject {
|
|
|
|
|
fn cli_metadata(&self) -> CliMetadata {
|
|
|
|
|
cot::cli::metadata!()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn config(&self, _config_name: &str) -> cot::Result<ProjectConfig> {
|
|
|
|
|
Ok(ProjectConfig::builder()
|
|
|
|
|
.debug(true)
|
|
|
|
|
.database(
|
|
|
|
|
DatabaseConfig::builder()
|
|
|
|
|
.url("sqlite://db.sqlite3?mode=rwc")
|
|
|
|
|
.build(),
|
|
|
|
|
)
|
|
|
|
|
.middlewares(
|
|
|
|
|
MiddlewareConfig::builder()
|
|
|
|
|
.session(
|
|
|
|
|
SessionMiddlewareConfig::builder()
|
|
|
|
|
.secure(false)
|
|
|
|
|
.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
|
|
|
|
|
}
|