fix: user profile URLs, typed returns for following/followers
- avatar_url/banner_url now use full base_url + /images/ prefix - get_user_following/followers return Result<Json<_>, ApiError> - add ap_to_domain helper for anyhow→DomainError conversion
This commit is contained in:
@@ -708,6 +708,12 @@ fn ap_err(e: anyhow::Error) -> impl IntoResponse {
|
|||||||
StatusCode::INTERNAL_SERVER_ERROR
|
StatusCode::INTERNAL_SERVER_ERROR
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "federation")]
|
||||||
|
fn ap_to_domain(e: anyhow::Error) -> domain::errors::DomainError {
|
||||||
|
tracing::error!("ActivityPub error: {:?}", e);
|
||||||
|
domain::errors::DomainError::InfrastructureError(e.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "federation")]
|
#[cfg(feature = "federation")]
|
||||||
#[utoipa::path(
|
#[utoipa::path(
|
||||||
get, path = "/api/v1/social/following",
|
get, path = "/api/v1/social/following",
|
||||||
@@ -775,21 +781,22 @@ pub async fn get_user_following(
|
|||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
_user: AuthenticatedUser,
|
_user: AuthenticatedUser,
|
||||||
Path(user_id): Path<Uuid>,
|
Path(user_id): Path<Uuid>,
|
||||||
) -> impl IntoResponse {
|
) -> Result<Json<ActorListResponse>, ApiError> {
|
||||||
match state.ap_service.get_following(user_id).await {
|
let actors = state
|
||||||
Ok(actors) => Json(ActorListResponse {
|
.ap_service
|
||||||
actors: actors
|
.get_following(user_id)
|
||||||
.into_iter()
|
.await
|
||||||
.map(|a| RemoteActorDto {
|
.map_err(ap_to_domain)?;
|
||||||
handle: a.handle,
|
Ok(Json(ActorListResponse {
|
||||||
display_name: a.display_name,
|
actors: actors
|
||||||
url: a.url,
|
.into_iter()
|
||||||
})
|
.map(|a| RemoteActorDto {
|
||||||
.collect(),
|
handle: a.handle,
|
||||||
})
|
display_name: a.display_name,
|
||||||
.into_response(),
|
url: a.url,
|
||||||
Err(e) => ap_err(e).into_response(),
|
})
|
||||||
}
|
.collect(),
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "federation")]
|
#[cfg(feature = "federation")]
|
||||||
@@ -797,21 +804,22 @@ pub async fn get_user_followers(
|
|||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
_user: AuthenticatedUser,
|
_user: AuthenticatedUser,
|
||||||
Path(user_id): Path<Uuid>,
|
Path(user_id): Path<Uuid>,
|
||||||
) -> impl IntoResponse {
|
) -> Result<Json<ActorListResponse>, ApiError> {
|
||||||
match state.ap_service.get_accepted_followers(user_id).await {
|
let actors = state
|
||||||
Ok(actors) => Json(ActorListResponse {
|
.ap_service
|
||||||
actors: actors
|
.get_accepted_followers(user_id)
|
||||||
.into_iter()
|
.await
|
||||||
.map(|a| RemoteActorDto {
|
.map_err(ap_to_domain)?;
|
||||||
handle: a.handle,
|
Ok(Json(ActorListResponse {
|
||||||
display_name: a.display_name,
|
actors: actors
|
||||||
url: a.url,
|
.into_iter()
|
||||||
})
|
.map(|a| RemoteActorDto {
|
||||||
.collect(),
|
handle: a.handle,
|
||||||
})
|
display_name: a.display_name,
|
||||||
.into_response(),
|
url: a.url,
|
||||||
Err(e) => ap_err(e).into_response(),
|
})
|
||||||
}
|
.collect(),
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "federation")]
|
#[cfg(feature = "federation")]
|
||||||
@@ -1120,8 +1128,12 @@ pub async fn get_user_profile(
|
|||||||
Json(UserProfileResponse {
|
Json(UserProfileResponse {
|
||||||
user_id,
|
user_id,
|
||||||
username: user.username().value().to_string(),
|
username: user.username().value().to_string(),
|
||||||
avatar_url: user.avatar_path().map(|s| s.to_string()),
|
avatar_url: user
|
||||||
banner_url: user.banner_path().map(|s| s.to_string()),
|
.avatar_path()
|
||||||
|
.map(|p| format!("{}/images/{}", state.app_ctx.config.base_url, p)),
|
||||||
|
banner_url: user
|
||||||
|
.banner_path()
|
||||||
|
.map(|p| format!("{}/images/{}", state.app_ctx.config.base_url, p)),
|
||||||
stats: UserStatsDto {
|
stats: UserStatsDto {
|
||||||
total_movies: profile.stats.total_movies,
|
total_movies: profile.stats.total_movies,
|
||||||
avg_rating: profile.stats.avg_rating,
|
avg_rating: profile.stats.avg_rating,
|
||||||
|
|||||||
Reference in New Issue
Block a user