diff options
Diffstat (limited to 'server/src/database.rs')
-rw-r--r-- | server/src/database.rs | 54 |
1 files changed, 0 insertions, 54 deletions
diff --git a/server/src/database.rs b/server/src/database.rs deleted file mode 100644 index 80bfe50..0000000 --- a/server/src/database.rs +++ /dev/null @@ -1,54 +0,0 @@ -/* - This file is part of jellything (https://codeberg.org/metamuffin/jellything) - which is licensed under the GNU Affero General Public License (version 3); see /COPYING. - Copyright (C) 2023 metamuffin <metamuffin.org> -*/ -use crate::routes::ui::account::hash_password; -use anyhow::Context; -use jellybase::CONF; -use jellycommon::{ - user::{PermissionSet, Theme, User}, - Node, -}; -use log::info; -use std::path::Path; -use typed_sled::Tree; - -pub struct Database { - pub db: sled::Db, - - pub user: Tree<String, User>, - pub invite: Tree<String, ()>, - pub node: Tree<String, Node>, -} - -impl Database { - pub fn open(path: &Path) -> Result<Self, anyhow::Error> { - info!("opening database… (might take up to O(n) time)"); - let db = sled::open(path).context("opening database")?; - info!("creating trees"); - let r = Ok(Self { - user: Tree::open(&db, "user"), - invite: Tree::open(&db, "invite"), - node: Tree::open(&db, "node"), - db, - }); - info!("ready"); - r - } - pub fn create_admin(&self) { - self.user - .insert( - &CONF.admin_username, - &User { - admin: true, - theme: Theme::Dark, - display_name: "Admin".to_string(), - name: CONF.admin_username.clone(), - password: hash_password(&CONF.admin_username, &CONF.admin_password), - permissions: PermissionSet::default(), - }, - ) - .unwrap(); - } -} |