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

ambee/giterated

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

Fixes for authentication!

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨969964d

⁨src/connection/repository.rs⁩ - ⁨4178⁩ bytes
Raw
1 use anyhow::Error;
2
3 use crate::backend::git::GitBackendError;
4 use crate::{
5 messages::repository::{
6 RepositoryCreateRequest, RepositoryFileInspectRequest, RepositoryInfoRequest,
7 RepositoryIssueLabelsRequest, RepositoryIssuesCountRequest, RepositoryIssuesRequest,
8 },
9 model::authenticated::{AuthenticatedUser, Message, MessageHandler, NetworkMessage, State},
10 };
11
12 use super::wrapper::ConnectionState;
13
14 pub async fn repository_handle(
15 message_type: &str,
16 message: &NetworkMessage,
17 state: &ConnectionState,
18 ) -> Result<bool, Error> {
19 match message_type {
20 "&giterated_daemon::messages::repository::RepositoryCreateRequest" => {
21 create_repository.handle_message(&message, state).await?;
22
23 Ok(true)
24 }
25 "&giterated_daemon::messages::repository::RepositoryFileInspectRequest" => {
26 repository_file_inspect
27 .handle_message(&message, state)
28 .await?;
29
30 Ok(true)
31 }
32 "&giterated_daemon::messages::repository::RepositoryInfoRequest" => {
33 repository_info.handle_message(&message, state).await?;
34
35 Ok(true)
36 }
37 "&giterated_daemon::messages::repository::RepositoryIssuesCountRequest" => {
38 issues_count.handle_message(&message, state).await?;
39
40 Ok(true)
41 }
42 "&giterated_daemon::messages::repository::RepositoryIssueLabelsRequest" => {
43 issue_labels.handle_message(&message, state).await?;
44
45 Ok(true)
46 }
47 "&giterated_daemon::messages::repository::RepositoryIssuesRequest" => {
48 issues.handle_message(&message, state).await?;
49
50 Ok(true)
51 }
52 _ => Ok(false),
53 }
54 }
55
56 async fn create_repository(
57 Message(request): Message<RepositoryCreateRequest>,
58 State(connection_state): State<ConnectionState>,
59 AuthenticatedUser(user): AuthenticatedUser,
60 ) -> Result<(), RepositoryError> {
61 let mut repository_backend = connection_state.repository_backend.lock().await;
62 let response = repository_backend
63 .create_repository(&user, &request)
64 .await?;
65
66 drop(repository_backend);
67
68 connection_state.send(response).await?;
69
70 Ok(())
71 }
72
73 async fn repository_file_inspect(
74 Message(request): Message<RepositoryFileInspectRequest>,
75 State(connection_state): State<ConnectionState>,
76 user: Option<AuthenticatedUser>,
77 ) -> Result<(), RepositoryError> {
78 let user = user.map(|u| u.0);
79
80 let mut repository_backend = connection_state.repository_backend.lock().await;
81 let response = repository_backend
82 .repository_file_inspect(user.as_ref(), &request)
83 .await?;
84
85 drop(repository_backend);
86
87 connection_state.send(response).await?;
88
89 Ok(())
90 }
91
92 async fn repository_info(
93 Message(request): Message<RepositoryInfoRequest>,
94 State(connection_state): State<ConnectionState>,
95 user: Option<AuthenticatedUser>,
96 ) -> Result<(), RepositoryError> {
97 let user = user.map(|u| u.0);
98
99 let mut repository_backend = connection_state.repository_backend.lock().await;
100 let response = repository_backend
101 .repository_info(user.as_ref(), &request)
102 .await?;
103
104 drop(repository_backend);
105
106 connection_state.send(response).await?;
107
108 Ok(())
109 }
110
111 async fn issues_count(
112 Message(_request): Message<RepositoryIssuesCountRequest>,
113 State(_connection_state): State<ConnectionState>,
114 _user: Option<AuthenticatedUser>,
115 ) -> Result<(), RepositoryError> {
116 unimplemented!();
117 }
118
119 async fn issue_labels(
120 Message(_request): Message<RepositoryIssueLabelsRequest>,
121 State(_connection_state): State<ConnectionState>,
122 _user: Option<AuthenticatedUser>,
123 ) -> Result<(), RepositoryError> {
124 unimplemented!();
125 }
126
127 async fn issues(
128 Message(_request): Message<RepositoryIssuesRequest>,
129 State(_connection_state): State<ConnectionState>,
130 _user: Option<AuthenticatedUser>,
131 ) -> Result<(), RepositoryError> {
132 unimplemented!();
133 }
134
135 #[derive(Debug, thiserror::Error)]
136 pub enum RepositoryError {
137 #[error("{0}")]
138 GitBackendError(#[from] GitBackendError),
139 #[error("{0}")]
140 Other(#[from] Error),
141 }
142