2023-09-05 09:33:46 +00:00
|
|
|
use actix_web::web::{Data, Json};
|
2023-04-16 21:00:31 +00:00
|
|
|
use lemmy_api_common::{
|
|
|
|
context::LemmyContext,
|
2023-09-05 09:33:46 +00:00
|
|
|
site::GetFederatedInstancesResponse,
|
2023-04-16 21:00:31 +00:00
|
|
|
utils::build_federated_instances,
|
|
|
|
};
|
|
|
|
use lemmy_db_views::structs::SiteView;
|
2023-06-06 16:27:22 +00:00
|
|
|
use lemmy_utils::error::LemmyError;
|
2023-04-16 21:00:31 +00:00
|
|
|
|
2023-09-05 09:33:46 +00:00
|
|
|
#[tracing::instrument(skip(context))]
|
|
|
|
pub async fn get_federated_instances(
|
|
|
|
context: Data<LemmyContext>,
|
|
|
|
) -> Result<Json<GetFederatedInstancesResponse>, LemmyError> {
|
|
|
|
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
|
|
|
let federated_instances =
|
|
|
|
build_federated_instances(&site_view.local_site, &mut context.pool()).await?;
|
2023-04-16 21:00:31 +00:00
|
|
|
|
2023-09-05 09:33:46 +00:00
|
|
|
Ok(Json(GetFederatedInstancesResponse {
|
|
|
|
federated_instances,
|
|
|
|
}))
|
2023-04-16 21:00:31 +00:00
|
|
|
}
|