diff options
author | metamuffin <metamuffin@disroot.org> | 2023-10-25 12:21:27 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-10-25 12:21:27 +0200 |
commit | a491792196c034efbd2f8998944af3f7958c0e52 (patch) | |
tree | a295342aef8cd38e32b05af273ff305b7f2a5cc5 /server/src | |
parent | 5aa2a6fa5a6f8daf3ed4d86082658027a44f83c8 (diff) | |
parent | 8fc2d47f1f6cde93554ba096b959b3bef3652ac1 (diff) | |
download | jellything-a491792196c034efbd2f8998944af3f7958c0e52.tar jellything-a491792196c034efbd2f8998944af3f7958c0e52.tar.bz2 jellything-a491792196c034efbd2f8998944af3f7958c0e52.tar.zst |
Merge branch 'master' of codeberg.org:metamuffin/jellything
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/stream.rs | 3 | ||||
-rw-r--r-- | server/src/routes/ui/error.rs | 1 |
4 files changed, 22 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/stream.rs b/server/src/routes/stream.rs index 0569903..5944ace 100644 --- a/server/src/routes/stream.rs +++ b/server/src/routes/stream.rs @@ -68,6 +68,7 @@ pub async fn r_stream( .get(host) .ok_or(anyhow!("no credentials on the server-side"))?; + info!("creating session on {host}"); let instance = federation.get_instance(&host)?.to_owned(); let session = instance .login( @@ -78,6 +79,7 @@ pub async fn r_stream( .await?; let uri = session.stream(&remote_id, &spec); + info!("federation redirect"); return Ok(Either::Right(Redirect::found(uri))); } @@ -125,6 +127,7 @@ impl<'r> Responder<'r, 'static> for StreamResponse { fn respond_to(self, _: &'r Request<'_>) -> response::Result<'static> { let mut b = Response::build(); b.status(Status::Ok); + b.header(Header::new("access-control-allow-origin", "*")); if let Some(range) = self.range { b.status(Status::PartialContent); b.header(Header::new("content-range", range.to_cr_hv())); 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}, |