diff options
author | metamuffin <metamuffin@disroot.org> | 2023-10-24 19:22:01 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-10-24 19:22:01 +0200 |
commit | 2fc5931a6ce9bbb75757c4a20022b19778bd91c5 (patch) | |
tree | 22dec1279ac77bb14a07a7ce4cbd4583756a6fdb /server/src | |
parent | f4f3a16bca576c202887799066bd896863612e2b (diff) | |
download | jellything-2fc5931a6ce9bbb75757c4a20022b19778bd91c5.tar jellything-2fc5931a6ce9bbb75757c4a20022b19778bd91c5.tar.bz2 jellything-2fc5931a6ce9bbb75757c4a20022b19778bd91c5.tar.zst |
move db to jellybase
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/database.rs | 54 | ||||
-rw-r--r-- | server/src/main.rs | 21 | ||||
-rw-r--r-- | server/src/routes/ui/error.rs | 1 |
3 files changed, 19 insertions, 57 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(); - } -} diff --git a/server/src/main.rs b/server/src/main.rs index 2b2d2c0..7c868a9 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -6,15 +6,16 @@ #![feature(lazy_cell)] #![feature(int_roundings)] -use crate::routes::ui::admin::log::enable_logging; +use crate::routes::ui::{account::hash_password, admin::log::enable_logging}; use database::Database; use federation::Federation; use jellybase::CONF; +use jellycommon::user::{PermissionSet, Theme, User}; use log::{error, warn}; use routes::build_rocket; use tokio::fs::create_dir_all; -pub mod database; +pub use jellybase::database; pub mod federation; pub mod import; pub mod routes; @@ -28,7 +29,21 @@ async fn main() { create_dir_all(&CONF.cache_path).await.unwrap(); let database = Database::open(&CONF.database_path).unwrap(); let federation = Federation::initialize(); - database.create_admin(); + + database + .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(); // if let Err(err) = import::import(&database, &federation).await { // log::error!("import not sucessful: {err:?}") // } diff --git a/server/src/routes/ui/error.rs b/server/src/routes/ui/error.rs index b538a06..a4ef50c 100644 --- a/server/src/routes/ui/error.rs +++ b/server/src/routes/ui/error.rs @@ -5,6 +5,7 @@ */ use super::layout::{DynLayoutPage, LayoutPage}; use crate::{routes::ui::account::rocket_uri_macro_r_account_login, uri}; +use jellybase::database::sled; use rocket::{ catch, http::{MediaType, Status}, |