aboutsummaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
Diffstat (limited to 'server/src')
-rw-r--r--server/src/config.rs14
-rw-r--r--server/src/database.rs20
-rw-r--r--server/src/library.rs4
-rw-r--r--server/src/main.rs9
-rw-r--r--server/src/routes/mod.rs4
-rw-r--r--server/src/routes/ui/account/mod.rs57
-rw-r--r--server/src/routes/ui/mod.rs1
7 files changed, 100 insertions, 9 deletions
diff --git a/server/src/config.rs b/server/src/config.rs
new file mode 100644
index 0000000..1edf5e5
--- /dev/null
+++ b/server/src/config.rs
@@ -0,0 +1,14 @@
+use std::{fs::File, path::PathBuf};
+
+use serde::{Deserialize, Serialize};
+
+#[derive(Debug, Deserialize, Serialize)]
+pub struct GlobalConfig {
+ pub brand: String,
+ pub database_path: PathBuf,
+ pub library_path: PathBuf,
+}
+
+pub fn load_global_config() -> GlobalConfig {
+ serde_json::from_reader(File::open("data/config.json").unwrap()).unwrap()
+}
diff --git a/server/src/database.rs b/server/src/database.rs
index 3ba8c52..8574189 100644
--- a/server/src/database.rs
+++ b/server/src/database.rs
@@ -1,13 +1,27 @@
+use std::path::PathBuf;
+
use anyhow::Context;
+use log::info;
+use typed_sled::Tree;
-#[derive(Debug)]
pub struct Database {
pub db: sled::Db,
+ pub users: Tree<String, User>,
+}
+
+pub struct User {
+ pub name: String,
+ pub display_name: String,
+ pub password: Vec<u8>,
}
impl Database {
- pub fn open(path: &str) -> Result<Self, anyhow::Error> {
+ pub fn open(path: &PathBuf) -> Result<Self, anyhow::Error> {
+ info!("opening database… (takes O(n) time sadly)");
let db = sled::open(path).context("opening database")?;
- Ok(Self { db })
+ Ok(Self {
+ users: typed_sled::Tree::open(&db, "users"),
+ db,
+ })
}
}
diff --git a/server/src/library.rs b/server/src/library.rs
index 17adf3c..8c2e809 100644
--- a/server/src/library.rs
+++ b/server/src/library.rs
@@ -35,9 +35,9 @@ pub struct Item {
}
impl Library {
- pub fn open(path: &str) -> anyhow::Result<Self> {
+ pub fn open(path: &PathBuf) -> anyhow::Result<Self> {
Ok(Self {
- root: Node::from_path(path.into(), PathBuf::new(), true).context("indexing root")?,
+ root: Node::from_path(path.clone(), PathBuf::new(), true).context("indexing root")?,
})
}
pub fn nested_path(&self, path: &Path) -> anyhow::Result<Arc<Node>> {
diff --git a/server/src/main.rs b/server/src/main.rs
index 438051f..39d5513 100644
--- a/server/src/main.rs
+++ b/server/src/main.rs
@@ -1,5 +1,6 @@
#![feature(box_syntax)]
+use config::{load_global_config, GlobalConfig};
use database::Database;
use jellyremuxer::RemuxerContext;
use library::Library;
@@ -7,6 +8,7 @@ use rocket::launch;
use routes::build_rocket;
use std::sync::Arc;
+pub mod config;
pub mod database;
pub mod library;
pub mod routes;
@@ -20,12 +22,11 @@ pub struct AppState {
#[launch]
fn rocket() -> _ {
env_logger::init_from_env("LOG");
- let db_path = std::env::var("DB_PATH").unwrap_or("data/db".to_string());
- let lib_path = std::env::var("LIB_PATH").unwrap_or("data/library".to_string());
+ let conf = load_global_config();
let state = AppState {
remuxer: RemuxerContext::new(),
- library: Library::open(&lib_path).unwrap(),
- database: Database::open(&db_path).unwrap(),
+ library: Library::open(&conf.library_path).unwrap(),
+ database: Database::open(&conf.database_path).unwrap(),
};
build_rocket(state)
}
diff --git a/server/src/routes/mod.rs b/server/src/routes/mod.rs
index 87d3051..f74ed65 100644
--- a/server/src/routes/mod.rs
+++ b/server/src/routes/mod.rs
@@ -1,6 +1,7 @@
use crate::AppState;
use rocket::{catchers, routes, Build, Rocket};
use stream::r_stream;
+use ui::account::{r_account_login, r_account_register, r_account_register_post};
use ui::error::r_not_found;
use ui::home::r_home;
use ui::node::r_library_node;
@@ -23,6 +24,9 @@ pub fn build_rocket(state: AppState) -> Rocket<Build> {
r_assets_font,
r_stream,
r_player,
+ r_account_login,
+ r_account_register,
+ r_account_register_post
],
)
}
diff --git a/server/src/routes/ui/account/mod.rs b/server/src/routes/ui/account/mod.rs
new file mode 100644
index 0000000..86e0f18
--- /dev/null
+++ b/server/src/routes/ui/account/mod.rs
@@ -0,0 +1,57 @@
+use super::HtmlTemplate;
+use rocket::form::Form;
+use rocket::{get, post, FromForm};
+
+#[derive(FromForm)]
+pub struct RegisterForm {
+ #[field(validate = len(8..32))]
+ pub invitation: String,
+ #[field(validate = len(4..32))]
+ pub username: String,
+ #[field(validate = len(4..64))]
+ pub password: String,
+}
+
+#[get("/account/register")]
+pub fn r_account_register() -> HtmlTemplate<markup::DynRender<'static>> {
+ HtmlTemplate(
+ "Register".to_string(),
+ markup::new! {
+ h1 { "Register for Jellything" }
+ form[method="POST", action=""] {
+ label[for="inp-invitation"] { "Invite Code: " }
+ input[type="text", id="inp-invitation", name="invitation"]; br;
+
+ label[for="inp-username"] { "Username: " }
+ input[type="text", id="inp-username", name="username"]; br;
+ label[for="inp-password"] { "Password: " }
+ input[type="password", id="inp-password", name="password"]; br;
+
+ input[type="submit", value="Register now!"];
+ }
+ },
+ )
+}
+
+#[get("/account/login")]
+pub fn r_account_login() -> HtmlTemplate<markup::DynRender<'static>> {
+ HtmlTemplate(
+ "Log in".to_string(),
+ markup::new! {
+ h1 { "Log in to your Account" }
+
+ },
+ )
+}
+
+#[post("/account/register", data = "<form>")]
+pub fn r_account_register_post(
+ form: Form<RegisterForm>,
+) -> HtmlTemplate<markup::DynRender<'static>> {
+ HtmlTemplate(
+ "Registration successful".to_string(),
+ markup::new! {
+ h1 { "Registration successful." }
+ },
+ )
+}
diff --git a/server/src/routes/ui/mod.rs b/server/src/routes/ui/mod.rs
index 1cad72c..8a3bc4e 100644
--- a/server/src/routes/ui/mod.rs
+++ b/server/src/routes/ui/mod.rs
@@ -13,6 +13,7 @@ pub mod layout;
pub mod node;
pub mod style;
pub mod player;
+pub mod account;
pub struct HtmlTemplate<T>(pub String, pub T);