diff options
author | metamuffin <metamuffin@disroot.org> | 2023-12-21 23:57:42 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-12-21 23:57:42 +0100 |
commit | 3a29113e965a94bdef06655f1583cc6e86edd606 (patch) | |
tree | a0910fa9687a9935ba1ca85a9cb5def1a0bc9069 /server/src/federation.rs | |
parent | a8b2480e898e269e7e0d41dbd46d9a18c7d1e4ba (diff) | |
download | jellything-3a29113e965a94bdef06655f1583cc6e86edd606.tar jellything-3a29113e965a94bdef06655f1583cc6e86edd606.tar.bz2 jellything-3a29113e965a94bdef06655f1583cc6e86edd606.tar.zst |
rework import system pt. 1
Diffstat (limited to 'server/src/federation.rs')
-rw-r--r-- | server/src/federation.rs | 61 |
1 files changed, 0 insertions, 61 deletions
diff --git a/server/src/federation.rs b/server/src/federation.rs deleted file mode 100644 index eb2a1ac..0000000 --- a/server/src/federation.rs +++ /dev/null @@ -1,61 +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 anyhow::anyhow; -use jellybase::CONF; -use jellyclient::{Instance, LoginDetails, Session}; -use std::{collections::HashMap, sync::Arc}; -use tokio::sync::RwLock; - -pub struct Federation { - instances: HashMap<String, Instance>, - sessions: RwLock<HashMap<String, Arc<Session>>>, -} - -impl Federation { - pub fn initialize() -> Self { - let instances = CONF - .remote_credentials - .iter() - .map(|(k, (_, _, tls))| (k.to_owned(), Instance::new(k.to_owned(), *tls))) - .collect::<HashMap<_, _>>(); - - Self { - instances, - sessions: Default::default(), - } - } - - pub fn get_instance(&self, host: &String) -> anyhow::Result<&Instance> { - Ok(self - .instances - .get(host) - .ok_or(anyhow!("unknown instance"))?) - } - pub async fn get_session(&self, host: &String) -> anyhow::Result<Arc<Session>> { - let mut w = self.sessions.write().await; - if let Some(s) = w.get(host) { - Ok(s.to_owned()) - } else { - let (username, password, _) = CONF - .remote_credentials - .get(host) - .ok_or(anyhow!("no credentials of the remote server"))?; - let s = Arc::new( - self.get_instance(host)? - .to_owned() - .login(LoginDetails { - username: username.to_owned(), - password: password.to_owned(), - expire: None, - drop_permissions: None, - }) - .await?, - ); - w.insert(host.to_owned(), s.clone()); - Ok(s) - } - } -} |