diff options
author | metamuffin <metamuffin@disroot.org> | 2023-01-09 22:53:14 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-01-09 22:53:14 +0100 |
commit | c64d3cd8cda389909b4b3dbdf00c0710e2c9a490 (patch) | |
tree | c0c5f8a077d4ca0c627f3f50b5f6690b86909681 /src | |
parent | 1599b61d22810e250f471b3b561660205297e07c (diff) | |
download | jellything-c64d3cd8cda389909b4b3dbdf00c0710e2c9a490.tar jellything-c64d3cd8cda389909b4b3dbdf00c0710e2c9a490.tar.bz2 jellything-c64d3cd8cda389909b4b3dbdf00c0710e2c9a490.tar.zst |
a
Diffstat (limited to 'src')
-rw-r--r-- | src/database.rs | 13 | ||||
-rw-r--r-- | src/frontend/pages/home.rs | 9 | ||||
-rw-r--r-- | src/frontend/pages/layout.rs | 4 | ||||
-rw-r--r-- | src/library.rs | 23 | ||||
-rw-r--r-- | src/main.rs | 24 |
5 files changed, 63 insertions, 10 deletions
diff --git a/src/database.rs b/src/database.rs new file mode 100644 index 0000000..51f7cb2 --- /dev/null +++ b/src/database.rs @@ -0,0 +1,13 @@ +use anyhow::Context; + +#[derive(Debug)] +pub struct Database { + db: sled::Db, +} + +impl Database { + pub fn open(path: &str) -> Result<Self, anyhow::Error> { + let db = sled::open(path).context("opening database")?; + Ok(Self { db }) + } +} diff --git a/src/frontend/pages/home.rs b/src/frontend/pages/home.rs index b7f1a12..a694c3c 100644 --- a/src/frontend/pages/home.rs +++ b/src/frontend/pages/home.rs @@ -1,8 +1,11 @@ -use crate::frontend::pages::{layout::Layout, HtmlTemplate}; -use actix_web::{get, Responder}; +use crate::{ + frontend::pages::{layout::Layout, HtmlTemplate}, + AppState, +}; +use actix_web::{get, web::Data, Responder}; #[get("/")] -async fn page_home() -> impl Responder { +async fn page_home(state: Data<AppState>) -> impl Responder { HtmlTemplate(Layout { title: "Home - Jellything", main: markup::new! { diff --git a/src/frontend/pages/layout.rs b/src/frontend/pages/layout.rs index 283721b..e02336d 100644 --- a/src/frontend/pages/layout.rs +++ b/src/frontend/pages/layout.rs @@ -10,9 +10,7 @@ markup::define! { } body { header { "Grain" } - #main { - @main - } + #main { @main } footer { span { "jellything" } } } } diff --git a/src/library.rs b/src/library.rs new file mode 100644 index 0000000..576ed77 --- /dev/null +++ b/src/library.rs @@ -0,0 +1,23 @@ +use anyhow::Ok; + +pub struct Library { + path: String, + tree: LibNode, +} + +pub enum LibNode { + Directory(LibDirectory), + Item(LibItem), +} + +pub struct LibDirectory {} +pub struct LibItem {} + +impl Library { + pub fn open(path: &str) -> anyhow::Result<Self> { + Ok(Self { + path: path.to_string(), + tree: , + }) + } +} diff --git a/src/main.rs b/src/main.rs index 5f49165..f400920 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,11 @@ use crate::frontend::style::CSS_BUNDLE; use actix_web::{get, web, App, HttpServer, Responder}; +use database::Database; use frontend::pages::home::page_home; +pub mod database; pub mod frontend; +pub mod library; #[get("/assets/style.css")] async fn assets_style() -> impl Responder { @@ -14,11 +17,24 @@ async fn hello(name: web::Path<String>) -> impl Responder { format!("Hello {}!", &name) } +pub struct AppState { + pub database: Database, +} + #[actix_web::main] async fn main() -> std::io::Result<()> { env_logger::init_from_env("LOG"); - HttpServer::new(|| App::new().service(page_home).service(hello)) - .bind(("127.0.0.1", 8080))? - .run() - .await + let db_path = std::env::var("DB_PATH").unwrap_or("data/db".to_string()); + let state = web::Data::new(AppState { + database: Database::open(&db_path).unwrap().into(), + }); + HttpServer::new(move || { + App::new() + .app_data(state.clone()) + .service(page_home) + .service(hello) + }) + .bind(("127.0.0.1", 8080))? + .run() + .await } |