aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/Cargo.toml3
-rw-r--r--server/src/database.rs54
-rw-r--r--server/src/main.rs21
-rw-r--r--server/src/routes/stream.rs3
-rw-r--r--server/src/routes/ui/error.rs1
5 files changed, 22 insertions, 60 deletions
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/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},