diff options
-rw-r--r-- | Cargo.lock | 4 | ||||
-rw-r--r-- | base/Cargo.toml | 2 | ||||
-rw-r--r-- | base/src/database.rs (renamed from server/src/database.rs) | 24 | ||||
-rw-r--r-- | base/src/lib.rs | 1 | ||||
-rw-r--r-- | server/Cargo.toml | 3 | ||||
-rw-r--r-- | server/src/main.rs | 21 | ||||
-rw-r--r-- | server/src/routes/ui/error.rs | 1 |
7 files changed, 27 insertions, 29 deletions
@@ -1395,7 +1395,9 @@ dependencies = [ "serde", "serde_yaml", "sha2", + "sled", "tokio", + "typed-sled", ] [[package]] @@ -1484,10 +1486,8 @@ dependencies = [ "rocket", "serde", "serde_json", - "sled", "tokio", "tokio-util", - "typed-sled", "vte", ] diff --git a/base/Cargo.toml b/base/Cargo.toml index 45c3843..0dede64 100644 --- a/base/Cargo.toml +++ b/base/Cargo.toml @@ -13,3 +13,5 @@ base64 = "0.21.4" tokio = { workspace = true } anyhow = "1.0.75" bincode = "2.0.0-rc.3" +sled = "0.34.7" +typed-sled = "0.2.3" diff --git a/server/src/database.rs b/base/src/database.rs index 80bfe50..b8ba28e 100644 --- a/server/src/database.rs +++ b/base/src/database.rs @@ -3,17 +3,14 @@ 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 jellycommon::{user::User, Node}; use log::info; use std::path::Path; use typed_sled::Tree; +pub use sled; + pub struct Database { pub db: sled::Db, @@ -36,19 +33,4 @@ impl Database { 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/base/src/lib.rs b/base/src/lib.rs index 132fd45..5d96b1a 100644 --- a/base/src/lib.rs +++ b/base/src/lib.rs @@ -7,6 +7,7 @@ pub mod cache; pub mod permission; pub mod temp; +pub mod database; use jellycommon::{config::GlobalConfig, AssetLocation}; use std::{fs::File, path::PathBuf, sync::LazyLock}; diff --git a/server/Cargo.toml b/server/Cargo.toml index efecfe5..23c533b 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -33,9 +33,6 @@ tokio-util = { version = "0.7.9", features = ["io", "io-util"] } markup = "0.13.1" rocket = { workspace = true, features = ["secrets", "json"] } -sled = "0.34.7" -typed-sled = "0.2.3" - [build-dependencies] glob = "0.3.1" 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}, |