refactor!: setup file proxy for projects

This commit is contained in:
2026-01-20 19:10:01 -08:00
parent 5eccfe32da
commit a2afc3fa05
17 changed files with 279 additions and 103 deletions

View File

@@ -18,6 +18,16 @@ pub struct UserRepository {
pub struct RepositorySchema {
pub id: String,
pub full_name: String,
#[serde(skip)]
pub owner_id: String,
pub description: String,
}
#[derive(Serialize)]
pub struct GlobalRepositoriesResponse {
pub id: String,
pub full_name: String,
pub description: String,
}
impl UserRepository {
@@ -38,7 +48,7 @@ impl UserRepository {
.map_err(|_| crate::error::Error::AccessToken)
}
pub async fn get_repositories(&self, user_id: &str) -> Result<Vec<RepositorySchema>> {
pub async fn get_repositories_user(&self, user_id: &str) -> Result<Vec<RepositorySchema>> {
let response = self
.dynamodb_client
.query()
@@ -59,6 +69,8 @@ impl UserRepository {
.strip_prefix("REPO#")?
.to_string(),
full_name: item.get("full_name")?.as_s().ok()?.to_string(),
owner_id: item.get("owner_id")?.as_s().ok()?.to_string(),
description: item.get("description")?.as_s().ok()?.to_string(),
})
})
.collect::<Vec<RepositorySchema>>();
@@ -70,7 +82,9 @@ impl UserRepository {
let response = self
.dynamodb_client
.query()
.key_condition_expression("pk = :pk")
.table_name(&self.table_name)
.index_name("gsi1")
.key_condition_expression("gsi1pk = :pk")
.expression_attribute_values(":pk", AttributeValue::S("REPOS".into()))
.send()
.await?
@@ -80,13 +94,53 @@ impl UserRepository {
if (*item.get("approved")?.as_bool().ok()?) == false {
return None;
};
Some(item.get("full_name")?.as_s().ok()?.to_string())
Some(GlobalRepositoriesResponse {
id: item
.get("sk")?
.as_s()
.ok()?
.strip_prefix("REPO#")?
.to_string(),
full_name: item.get("full_name")?.as_s().ok()?.to_string(),
description: item.get("description")?.as_s().ok()?.to_string(),
})
})
.collect::<Vec<String>>();
.collect::<Vec<GlobalRepositoriesResponse>>();
Ok(HttpResponse::Ok().json(response))
}
pub async fn get_approved_repository(&self, repo_id: &str) -> Result<Option<RepositorySchema>> {
let response = self
.dynamodb_client
.query()
.table_name(&self.table_name)
.index_name("gsi1")
.key_condition_expression("gsi1pk = :pk")
.filter_expression("sk = :sk AND approved = :approved")
.expression_attribute_values(":pk", AttributeValue::S("REPOS".into()))
.expression_attribute_values(":sk", AttributeValue::S(format!("REPO#{repo_id}")))
.expression_attribute_values(":approved", AttributeValue::Bool(true))
.send()
.await?;
let repo = response.items().first().and_then(|item| {
Some(RepositorySchema {
id: item
.get("sk")?
.as_s()
.ok()?
.strip_prefix("REPO#")?
.to_string(),
full_name: item.get("full_name")?.as_s().ok()?.to_string(),
owner_id: item.get("owner_id")?.as_s().ok()?.to_string(),
description: item.get("description")?.as_s().ok()?.to_string(),
})
});
Ok(repo)
}
pub async fn add_repository(
&self,
user_id: &str,
@@ -105,6 +159,8 @@ impl UserRepository {
.item("gsi1sk", AttributeValue::S(now.clone()))
.item("imported_at", AttributeValue::S(now))
.item("approved", AttributeValue::Bool(false))
.item("owner_id", AttributeValue::S(user_id.into()))
.item("description", AttributeValue::S(repo.description.clone()))
.send()
.await;