JavaScript is disabled, refresh for a better experience. ambee/giterated-api

ambee/giterated-api

Git repository hosting, collaboration, and discovery for the Fediverse.

Error handling fixes

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨5eaea71

⁨src/main.rs⁩ - ⁨1602⁩ bytes
Raw
1 use std::{str::FromStr, time::Instant};
2
3 use giterated_api::{daemon_backend::NetworkOperationState, DaemonConnectionPool};
4 use giterated_models::{
5 authenticated::{InstanceAuthenticator, UserAuthenticator},
6 instance::Instance,
7 object_backend::ObjectBackend,
8 repository::{AccessList, Description, Repository},
9 settings::AnySetting,
10 user::{Bio, DisplayName, User},
11 };
12
13 use color_eyre::eyre::Result;
14 use tokio::{fs::File, io::AsyncReadExt};
15 use tracing::info;
16
17 #[tokio::main]
18 async fn main() -> Result<()> {
19 tracing_subscriber::fmt::init();
20 color_eyre::install()?;
21
22 let start = Instant::now();
23 let pool = DaemonConnectionPool::connect_other(
24 Instance::from_str("giterated.dev")?,
25 ("127.0.0.1:1111").parse().unwrap(),
26 )
27 .unwrap();
28
29 let mut operation_state = NetworkOperationState::new();
30
31 let mut user = pool
32 .get_object::<User>("test:giterated.dev", &operation_state)
33 .await?;
34
35 let bio = user.get::<Bio>(&operation_state).await?;
36
37 info!("Bio: {}", bio);
38
39 let repositories = user
40 .repositories(&Instance::from_str("giterated.dev")?, &operation_state)
41 .await?;
42
43 let repository = repositories.first().unwrap();
44
45 let mut repository = pool
46 .get_object::<Repository>(&repository.repository.to_string(), &operation_state)
47 .await?;
48
49 info!(
50 "Repository description: {}",
51 repository.get::<Description>(&operation_state).await?
52 );
53
54 info!(
55 "User Bio Setting: {}",
56 user.get_setting::<Bio>(&operation_state).await?
57 );
58
59 Ok(())
60 }
61