aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Cargo.lock174
-rw-r--r--Cargo.toml3
-rw-r--r--src/database.rs13
-rw-r--r--src/frontend/pages/home.rs9
-rw-r--r--src/frontend/pages/layout.rs4
-rw-r--r--src/library.rs23
-rw-r--r--src/main.rs24
8 files changed, 239 insertions, 12 deletions
diff --git a/.gitignore b/.gitignore
index ea8c4bf..a727c0a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
/target
+/data
diff --git a/Cargo.lock b/Cargo.lock
index 0c7a2e3..817fb9a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -241,6 +241,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
[[package]]
+name = "bincode"
+version = "1.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"
+dependencies = [
+ "serde",
+]
+
+[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -277,6 +286,12 @@ dependencies = [
]
[[package]]
+name = "byteorder"
+version = "1.4.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
+
+[[package]]
name = "bytes"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -342,6 +357,28 @@ dependencies = [
]
[[package]]
+name = "crossbeam-epoch"
+version = "0.9.13"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "01a9af1f4c2ef74bb8aa1f7e19706bc72d03598c8a570bb5de72243c7a9d9d5a"
+dependencies = [
+ "autocfg",
+ "cfg-if",
+ "crossbeam-utils",
+ "memoffset",
+ "scopeguard",
+]
+
+[[package]]
+name = "crossbeam-utils"
+version = "0.8.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f"
+dependencies = [
+ "cfg-if",
+]
+
+[[package]]
name = "crypto-common"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -443,6 +480,16 @@ dependencies = [
]
[[package]]
+name = "fs2"
+version = "0.4.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213"
+dependencies = [
+ "libc",
+ "winapi",
+]
+
+[[package]]
name = "futures-core"
version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -473,6 +520,15 @@ dependencies = [
]
[[package]]
+name = "fxhash"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c"
+dependencies = [
+ "byteorder",
+]
+
+[[package]]
name = "generic-array"
version = "0.14.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -577,6 +633,15 @@ dependencies = [
]
[[package]]
+name = "instant"
+version = "0.1.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
+dependencies = [
+ "cfg-if",
+]
+
+[[package]]
name = "io-lifetimes"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -615,7 +680,9 @@ dependencies = [
"markup",
"serde",
"serde_json",
+ "sled",
"tokio",
+ "typed-sled",
]
[[package]]
@@ -710,6 +777,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
+name = "memoffset"
+version = "0.7.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4"
+dependencies = [
+ "autocfg",
+]
+
+[[package]]
name = "mime"
version = "0.3.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -754,12 +830,37 @@ checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66"
[[package]]
name = "parking_lot"
+version = "0.11.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99"
+dependencies = [
+ "instant",
+ "lock_api",
+ "parking_lot_core 0.8.6",
+]
+
+[[package]]
+name = "parking_lot"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
dependencies = [
"lock_api",
- "parking_lot_core",
+ "parking_lot_core 0.9.5",
+]
+
+[[package]]
+name = "parking_lot_core"
+version = "0.8.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc"
+dependencies = [
+ "cfg-if",
+ "instant",
+ "libc",
+ "redox_syscall",
+ "smallvec",
+ "winapi",
]
[[package]]
@@ -788,6 +889,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e"
[[package]]
+name = "pin-project"
+version = "1.0.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc"
+dependencies = [
+ "pin-project-internal",
+]
+
+[[package]]
+name = "pin-project-internal"
+version = "1.0.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
name = "pin-project-lite"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -993,6 +1114,22 @@ dependencies = [
]
[[package]]
+name = "sled"
+version = "0.34.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7f96b4737c2ce5987354855aed3797279def4ebf734436c6aa4552cf8e169935"
+dependencies = [
+ "crc32fast",
+ "crossbeam-epoch",
+ "crossbeam-utils",
+ "fs2",
+ "fxhash",
+ "libc",
+ "log",
+ "parking_lot 0.11.2",
+]
+
+[[package]]
name = "smallvec"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1029,6 +1166,26 @@ dependencies = [
]
[[package]]
+name = "thiserror"
+version = "1.0.38"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0"
+dependencies = [
+ "thiserror-impl",
+]
+
+[[package]]
+name = "thiserror-impl"
+version = "1.0.38"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
name = "time"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1081,7 +1238,7 @@ dependencies = [
"libc",
"memchr",
"mio",
- "parking_lot",
+ "parking_lot 0.12.1",
"pin-project-lite",
"signal-hook-registry",
"socket2",
@@ -1124,6 +1281,19 @@ dependencies = [
]
[[package]]
+name = "typed-sled"
+version = "0.2.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1060f05a4450ec5b758da60951b04f225a93a62079316630e76cf25c4034500d"
+dependencies = [
+ "bincode",
+ "pin-project",
+ "serde",
+ "sled",
+ "thiserror",
+]
+
+[[package]]
name = "typenum"
version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 49a7ada..fd16832 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -14,3 +14,6 @@ anyhow = "1.0.68"
actix-web = "4.2.1"
tokio = "1.24.1"
markup = "0.13.1"
+
+sled = "0.34.7"
+typed-sled = "0.2.3"
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
}