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

ambee/giterated

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

fixes

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨b91129f

Showing ⁨⁨7⁩ changed files⁩ with ⁨⁨117⁩ insertions⁩ and ⁨⁨118⁩ deletions⁩

.sqlx/query-5f9e3dd381486d725dbb7d6a8b9fd195b3fdf030f17c308c36122f2bd04340a2.json

View file
@@ -0,0 +1,63 @@
1 {
2 "db_name": "PostgreSQL",
3 "query": "SELECT instance_url, username, name, description, visibility as \"visibility: _\", default_branch FROM repositories WHERE name = $1",
4 "describe": {
5 "columns": [
6 {
7 "ordinal": 0,
8 "name": "instance_url",
9 "type_info": "Text"
10 },
11 {
12 "ordinal": 1,
13 "name": "username",
14 "type_info": "Text"
15 },
16 {
17 "ordinal": 2,
18 "name": "name",
19 "type_info": "Text"
20 },
21 {
22 "ordinal": 3,
23 "name": "description",
24 "type_info": "Text"
25 },
26 {
27 "ordinal": 4,
28 "name": "visibility: _",
29 "type_info": {
30 "Custom": {
31 "name": "visibility",
32 "kind": {
33 "Enum": [
34 "public",
35 "unlisted",
36 "private"
37 ]
38 }
39 }
40 }
41 },
42 {
43 "ordinal": 5,
44 "name": "default_branch",
45 "type_info": "Text"
46 }
47 ],
48 "parameters": {
49 "Left": [
50 "Text"
51 ]
52 },
53 "nullable": [
54 false,
55 false,
56 false,
57 true,
58 false,
59 false
60 ]
61 },
62 "hash": "5f9e3dd381486d725dbb7d6a8b9fd195b3fdf030f17c308c36122f2bd04340a2"
63 }

src/authentication.rs

View file
@@ -112,8 +112,6 @@ impl AuthenticationTokenGranter {
112 112 .await
113 113 .unwrap();
114 114
115 println!("Our Public Key:\n{}", server_public_key);
116
117 115 let verification_key = DecodingKey::from_rsa_pem(server_public_key.as_bytes()).unwrap();
118 116
119 117 let data: TokenData<UserTokenMetadata> = decode(

src/backend/git.rs

View file
@@ -73,10 +73,11 @@ pub enum GitBackendError {
73 73 FailedCreatingRepository(git2::Error),
74 74 #[error("Failed inserting into the database")]
75 75 FailedInsertingIntoDatabase(sqlx::Error),
76 #[error("Failed finding repository {instance_url:?}/{username:?}/{name:?}")]
76 #[error("")]
77 // #[error("Failed finding repository {instance_url:?}/{username:?}/{name:?}")]
77 78 RepositoryNotFound {
78 instance_url: String,
79 username: String,
79 // instance_url: String,
80 // username: String,
80 81 name: String,
81 82 },
82 83 #[error("Repository {instance_url:?}/{username:?}/{name:?} already exists")]
@@ -114,20 +115,20 @@ impl GitBackend {
114 115
115 116 pub async fn find_by_instance_username_name(
116 117 &self,
117 instance_url: &str,
118 username: &str,
118 // instance_url: &str,
119 // username: &str,
119 120 repository_name: &str,
120 121 ) -> Result<GitRepository, GitBackendError> {
121 122 if let Ok(repository) = sqlx::query_as!(GitRepository,
122 r#"SELECT username, instance_url, name, description, visibility as "visibility: _", default_branch FROM repositories WHERE instance_url = $1 AND username = $2 AND name = $3"#,
123 instance_url, username, repository_name)
123 r#"SELECT instance_url, username, name, description, visibility as "visibility: _", default_branch FROM repositories WHERE name = $1"#,
124 /*instance_url, username,*/ repository_name)
124 125 .fetch_one(&self.pg_pool.clone())
125 126 .await {
126 127 Ok(repository)
127 128 } else {
128 129 Err(GitBackendError::RepositoryNotFound {
129 instance_url: instance_url.to_string(),
130 username: username.to_string(),
130 // instance_url: instance_url.to_string(),
131 // username: username.to_string(),
131 132 name: repository_name.to_string(),
132 133 })
133 134 }
@@ -237,9 +238,9 @@ impl RepositoryBackend for GitBackend {
237 238 // Check if repository already exists in the database
238 239 if let Ok(_repository) = self
239 240 .find_by_instance_username_name(
240 request.owner.instance.url.as_str(),
241 request.owner.username.as_str(),
242 request.name.as_str(),
241 // request.owner.instance.url.as_str(),
242 // request.owner.username.as_str(),
243 &request.name,
243 244 )
244 245 .await
245 246 {
@@ -312,9 +313,9 @@ impl RepositoryBackend for GitBackend {
312 313 ) -> Result<RepositoryView, Box<dyn Error + Send>> {
313 314 let repository = match self
314 315 .find_by_instance_username_name(
315 &request.owner.instance.url,
316 &request.owner.username,
317 &request.name,
316 // &request.owner.instance.url,
317 // &request.owner.username,
318 &request.repository.name,
318 319 )
319 320 .await
320 321 {
@@ -322,16 +323,16 @@ impl RepositoryBackend for GitBackend {
322 323 Err(err) => return Err(Box::new(err)),
323 324 };
324 325
325 if !repository.can_user_view_repository(
326 request.owner.instance.url.as_str(),
327 Some(request.owner.username.as_str()),
328 ) {
329 return Err(Box::new(GitBackendError::RepositoryNotFound {
330 instance_url: request.owner.instance.url.clone(),
331 username: request.owner.username.clone(),
332 name: request.name.clone(),
333 }));
334 }
326 // if !repository.can_user_view_repository(
327 // request.owner.instance.url.as_str(),
328 // Some(request.owner.username.as_str()),
329 // ) {
330 // return Err(Box::new(GitBackendError::RepositoryNotFound {
331 // instance_url: request.owner.instance.url.clone(),
332 // username: request.owner.username.clone(),
333 // name: request.name.clone(),
334 // }));
335 // }
335 336
336 337 let git = match repository.open_git2_repository(&self.repository_folder) {
337 338 Ok(git) => git,
@@ -412,27 +413,27 @@ impl RepositoryBackend for GitBackend {
412 413 let mut tree_entry =
413 414 RepositoryTreeEntry::new(entry.name().unwrap(), object_type, entry.filemode());
414 415
415 if request.extra_metadata {
416 // Get the file size if It's a blob
417 let object = entry.to_object(&git).unwrap();
418 if let Some(blob) = object.as_blob() {
419 tree_entry.size = Some(blob.size());
420 }
421
422 // Could possibly be done better
423 let path = if let Some(path) = current_path.split_once('/') {
424 format!("{}/{}", path.1, entry.name().unwrap())
425 } else {
426 entry.name().unwrap().to_string()
427 };
428
429 // Get the last commit made to the entry
430 if let Ok(last_commit) =
431 GitBackend::get_last_commit_of_file(&path, &git, commit)
432 {
433 tree_entry.last_commit = Some(last_commit);
434 }
435 }
416 // if request.extra_metadata {
417 // // Get the file size if It's a blob
418 // let object = entry.to_object(&git).unwrap();
419 // if let Some(blob) = object.as_blob() {
420 // tree_entry.size = Some(blob.size());
421 // }
422
423 // // Could possibly be done better
424 // let path = if let Some(path) = current_path.split_once('/') {
425 // format!("{}/{}", path.1, entry.name().unwrap())
426 // } else {
427 // entry.name().unwrap().to_string()
428 // };
429
430 // // Get the last commit made to the entry
431 // if let Ok(last_commit) =
432 // GitBackend::get_last_commit_of_file(&path, &git, commit)
433 // {
434 // tree_entry.last_commit = Some(last_commit);
435 // }
436 // }
436 437
437 438 tree_entry
438 439 })

src/connection.rs

View file
@@ -94,7 +94,7 @@ pub async fn connection_worker(
94 94 }
95 95 };
96 96
97 info!("Read payload: {}", std::str::from_utf8(&payload).unwrap());
97 // info!("Read payload: {}", std::str::from_utf8(&payload).unwrap());
98 98
99 99 if let MessageKind::Handshake(handshake) = message {
100 100 match handshake {

src/main.rs

View file
@@ -48,7 +48,11 @@ async fn main() -> Result<(), Box<dyn Error>> {
48 48 let repository_backend: Arc<Mutex<dyn RepositoryBackend + Send>> = Arc::new(Mutex::new({
49 49 let foo: GitBackend = GitBackend {
50 50 pg_pool: db_pool,
51 repository_folder: String::from("/tmp/foo"),
51 repository_folder: String::from(
52 config["repository"]["backend"]["git"]["root"]
53 .as_str()
54 .unwrap(),
55 ),
52 56 };
53 57 foo
54 58 }));

src/messages/repository.rs

View file
@@ -115,9 +115,7 @@ pub struct RepositoryIssue {
115 115
116 116 #[derive(Clone, Serialize, Deserialize)]
117 117 pub struct RepositoryInfoRequest {
118 pub name: String,
119 pub owner: User,
118 pub repository: Repository,
120 119 pub rev: Option<String>,
121 120 pub path: Option<String>,
122 pub extra_metadata: bool,
123 121 }