Init package

This commit is contained in:
Matthieu Bessat 2024-10-10 18:20:06 +02:00
commit 66b3a99814
17 changed files with 2526 additions and 0 deletions

28
src/cli.rs Normal file
View file

@ -0,0 +1,28 @@
use argh::FromArgs;
#[derive(Debug, FromArgs)]
/// Autotasker daemon
struct CliFlags {
/// path to YAML config file to use to configure autotasker
#[argh(option)]
config: Option<String>,
/// path to the Sqlite3 DB file to use
#[argh(option)]
database: Option<String>,
/// path to the static assets dir
#[argh(option)]
static_assets: Option<String>,
/// HTTP listen host
#[argh(option, default="String::from(\"localhost\")")]
listen_host: String,
/// HTTP listen port
#[argh(option, default="8085")]
listen_port: u32
}

View file

@ -0,0 +1 @@
pub mod verify_authorization;

2
src/controllers/mod.rs Normal file
View file

@ -0,0 +1,2 @@
pub mod api;
pub mod ui;

View file

View file

View file

@ -0,0 +1,3 @@
pub mod authorize;
pub mod login;
pub mod register;

View file

20
src/main.rs Normal file
View file

@ -0,0 +1,20 @@
pub mod models;
pub mod controllers;
use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};
use sqlx::{ConnectOptions, Pool, Sqlite};
use models::config::Config;
use minijinja::{context, Environment};
#[derive(Debug, Clone)]
pub struct AppState {
config: Config,
db: Pool<Sqlite>,
templating_env: Environment<'static>
}
fn main() {
println!("Hello, world!");
}

0
src/models/app.rs Normal file
View file

24
src/models/config.rs Normal file
View file

@ -0,0 +1,24 @@
use std::collections::HashMap;
use chrono::{DateTime, Utc};
use fully_pub::fully_pub;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[fully_pub]
/// Instance branding/customization config
struct InstanceConfig {
name: String,
logo_uri: String
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[fully_pub]
/// Configuration of this minauthator instance
struct Config {
/// configure current autotasker instance
instance: Option<InstanceConfig>,
}

3
src/models/mod.rs Normal file
View file

@ -0,0 +1,3 @@
pub mod app;
pub mod config;
pub mod user;

0
src/models/user.rs Normal file
View file

34
src/server.rs Normal file
View file

@ -0,0 +1,34 @@
fn get_config(path: String) -> Result<Config> {
let inp_def_yaml = fs::read_to_string(path)
.expect("Should have been able to read the the config file");
serde_yaml::from_str(&inp_def_yaml)
.map_err(|e| anyhow!("Failed to parse config, {:?}", e))
}
fn build_templating_env() -> Environment<'static> {
let mut templating_env = Environment::new();
let _ = templating_env
.add_template("layouts/base.html", include_str!("./templates/layouts/base.html"));
let _ = templating_env
.add_template("pages/home.html", include_str!("./templates/pages/home.html"));
let _ = templating_env
.add_template("pages/list_tasks.html", include_str!("./templates/pages/list_tasks.html"));
let _ = templating_env
.add_template("pages/list_task_runs.html", include_str!("./templates/pages/list_task_runs.html"));
let _ = templating_env
.add_template("pages/task_run_details.html", include_str!("./templates/pages/task_run_details.html"));
let _ = templating_env
.add_template("pages/run_task.html", include_str!("./templates/pages/run_task.html"));
// TODO: better loading with embed https://docs.rs/minijinja-embed/latest/minijinja_embed/
templating_env.add_global("gl", context! {
instance => context! {
version => "1.243".to_string()
}
});
templating_env
}