httpd: Announce refs in project POST/PATCH routes
This commit is contained in:
parent
1cbca28b7c
commit
638c2a3e4c
|
|
@ -19,13 +19,15 @@ use radicle::cob::{issue, Uri};
|
||||||
use radicle::cob::{patch, Embed};
|
use radicle::cob::{patch, Embed};
|
||||||
use radicle::identity::{DocAt, Id};
|
use radicle::identity::{DocAt, Id};
|
||||||
use radicle::node::routing::Store;
|
use radicle::node::routing::Store;
|
||||||
|
use radicle::node::Handle;
|
||||||
use radicle::storage::{Oid, ReadRepository, ReadStorage};
|
use radicle::storage::{Oid, ReadRepository, ReadStorage};
|
||||||
use radicle::Profile;
|
use radicle::{Node, Profile};
|
||||||
|
|
||||||
mod error;
|
mod error;
|
||||||
mod json;
|
mod json;
|
||||||
mod v1;
|
mod v1;
|
||||||
|
|
||||||
|
use crate::api::error::Error;
|
||||||
use crate::cache::Cache;
|
use crate::cache::Cache;
|
||||||
use crate::Options;
|
use crate::Options;
|
||||||
|
|
||||||
|
|
@ -232,6 +234,15 @@ impl TryFrom<&Uri> for DataUri {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Announce refs to the network for the given RID.
|
||||||
|
pub fn announce_refs(mut node: Node, rid: Id) -> Result<(), Error> {
|
||||||
|
match node.announce_refs(rid) {
|
||||||
|
Ok(_) => Ok(()),
|
||||||
|
Err(e) if e.is_connection_err() => Ok(()),
|
||||||
|
Err(e) => return Err(e.into()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Resolve an embed with a URI to one with actual data.
|
/// Resolve an embed with a URI to one with actual data.
|
||||||
pub fn resolve_embed(repo: &impl ReadRepository, embed: Embed<Uri>) -> Option<Embed<Vec<u8>>> {
|
pub fn resolve_embed(repo: &impl ReadRepository, embed: Embed<Uri>) -> Option<Embed<Vec<u8>>> {
|
||||||
DataUri::try_from(&embed.content)
|
DataUri::try_from(&embed.content)
|
||||||
|
|
|
||||||
|
|
@ -17,15 +17,14 @@ use tower_http::set_header::SetResponseHeaderLayer;
|
||||||
use radicle::cob::{issue, patch, Embed, Label, Uri};
|
use radicle::cob::{issue, patch, Embed, Label, Uri};
|
||||||
use radicle::identity::{Did, Id, Visibility};
|
use radicle::identity::{Did, Id, Visibility};
|
||||||
use radicle::node::routing::Store;
|
use radicle::node::routing::Store;
|
||||||
use radicle::node::AliasStore;
|
use radicle::node::{AliasStore, Node, NodeId};
|
||||||
use radicle::node::NodeId;
|
|
||||||
use radicle::storage::git::paths;
|
use radicle::storage::git::paths;
|
||||||
use radicle::storage::{ReadRepository, ReadStorage, RemoteRepository, WriteRepository};
|
use radicle::storage::{ReadRepository, ReadStorage, RemoteRepository, WriteRepository};
|
||||||
use radicle_surf::{diff, Glob, Oid, Repository};
|
use radicle_surf::{diff, Glob, Oid, Repository};
|
||||||
|
|
||||||
use crate::api::error::Error;
|
use crate::api::error::Error;
|
||||||
use crate::api::project::Info;
|
use crate::api::project::Info;
|
||||||
use crate::api::{self, resolve_embed, CobsQuery, Context, PaginationQuery};
|
use crate::api::{self, announce_refs, resolve_embed, CobsQuery, Context, PaginationQuery};
|
||||||
use crate::axum_extra::{Path, Query};
|
use crate::axum_extra::{Path, Query};
|
||||||
|
|
||||||
const CACHE_1_HOUR: &str = "public, max-age=3600, must-revalidate";
|
const CACHE_1_HOUR: &str = "public, max-age=3600, must-revalidate";
|
||||||
|
|
@ -604,6 +603,7 @@ async fn issue_create_handler(
|
||||||
Json(issue): Json<IssueCreate>,
|
Json(issue): Json<IssueCreate>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
api::auth::validate(&ctx, &token).await?;
|
api::auth::validate(&ctx, &token).await?;
|
||||||
|
let node = Node::new(ctx.profile.socket());
|
||||||
let storage = &ctx.profile.storage;
|
let storage = &ctx.profile.storage;
|
||||||
let signer = ctx
|
let signer = ctx
|
||||||
.profile
|
.profile
|
||||||
|
|
@ -628,6 +628,8 @@ async fn issue_create_handler(
|
||||||
)
|
)
|
||||||
.map_err(Error::from)?;
|
.map_err(Error::from)?;
|
||||||
|
|
||||||
|
announce_refs(node, repo.id())?;
|
||||||
|
|
||||||
Ok::<_, Error>((
|
Ok::<_, Error>((
|
||||||
StatusCode::CREATED,
|
StatusCode::CREATED,
|
||||||
Json(json!({ "success": true, "id": issue.id().to_string() })),
|
Json(json!({ "success": true, "id": issue.id().to_string() })),
|
||||||
|
|
@ -643,7 +645,7 @@ async fn issue_update_handler(
|
||||||
Json(action): Json<issue::Action>,
|
Json(action): Json<issue::Action>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
api::auth::validate(&ctx, &token).await?;
|
api::auth::validate(&ctx, &token).await?;
|
||||||
|
let node = Node::new(ctx.profile.socket());
|
||||||
let storage = &ctx.profile.storage;
|
let storage = &ctx.profile.storage;
|
||||||
let signer = ctx.profile.signer()?;
|
let signer = ctx.profile.signer()?;
|
||||||
let repo = storage.repository(project)?;
|
let repo = storage.repository(project)?;
|
||||||
|
|
@ -685,6 +687,8 @@ async fn issue_update_handler(
|
||||||
issue::Action::CommentRedact { id } => issue.redact_comment(id, &signer)?,
|
issue::Action::CommentRedact { id } => issue.redact_comment(id, &signer)?,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
announce_refs(node, repo.id())?;
|
||||||
|
|
||||||
Ok::<_, Error>(Json(json!({ "success": true, "id": id })))
|
Ok::<_, Error>(Json(json!({ "success": true, "id": id })))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -722,6 +726,7 @@ async fn patch_create_handler(
|
||||||
Json(patch): Json<PatchCreate>,
|
Json(patch): Json<PatchCreate>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
api::auth::validate(&ctx, &token).await?;
|
api::auth::validate(&ctx, &token).await?;
|
||||||
|
let node = Node::new(ctx.profile.socket());
|
||||||
let storage = &ctx.profile.storage;
|
let storage = &ctx.profile.storage;
|
||||||
let signer = ctx
|
let signer = ctx
|
||||||
.profile
|
.profile
|
||||||
|
|
@ -743,11 +748,14 @@ async fn patch_create_handler(
|
||||||
)
|
)
|
||||||
.map_err(Error::from)?;
|
.map_err(Error::from)?;
|
||||||
|
|
||||||
|
announce_refs(node, repo.id())?;
|
||||||
|
|
||||||
Ok::<_, Error>((
|
Ok::<_, Error>((
|
||||||
StatusCode::CREATED,
|
StatusCode::CREATED,
|
||||||
Json(json!({ "success": true, "id": patch.id.to_string() })),
|
Json(json!({ "success": true, "id": patch.id.to_string() })),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update an patch.
|
/// Update an patch.
|
||||||
/// `PATCH /projects/:project/patches/:id`
|
/// `PATCH /projects/:project/patches/:id`
|
||||||
async fn patch_update_handler(
|
async fn patch_update_handler(
|
||||||
|
|
@ -757,6 +765,7 @@ async fn patch_update_handler(
|
||||||
Json(action): Json<patch::Action>,
|
Json(action): Json<patch::Action>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
api::auth::validate(&ctx, &token).await?;
|
api::auth::validate(&ctx, &token).await?;
|
||||||
|
let node = Node::new(ctx.profile.socket());
|
||||||
let storage = &ctx.profile.storage;
|
let storage = &ctx.profile.storage;
|
||||||
let signer = ctx
|
let signer = ctx
|
||||||
.profile
|
.profile
|
||||||
|
|
@ -876,6 +885,8 @@ async fn patch_update_handler(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
announce_refs(node, repo.id())?;
|
||||||
|
|
||||||
Ok::<_, Error>(Json(json!({ "success": true, "id": id })))
|
Ok::<_, Error>(Json(json!({ "success": true, "id": id })))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue