2023-04-16 21:00:31 +00:00
|
|
|
use crate::Perform;
|
|
|
|
use actix_web::web::Data;
|
|
|
|
use lemmy_api_common::{
|
|
|
|
context::LemmyContext,
|
|
|
|
site::{GetFederatedInstances, GetFederatedInstancesResponse},
|
|
|
|
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
|
|
|
|
|
|
|
#[async_trait::async_trait(?Send)]
|
|
|
|
impl Perform for GetFederatedInstances {
|
|
|
|
type Response = GetFederatedInstancesResponse;
|
|
|
|
|
2023-06-06 16:27:22 +00:00
|
|
|
#[tracing::instrument(skip(context))]
|
|
|
|
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
|
2023-04-16 21:00:31 +00:00
|
|
|
let site_view = SiteView::read_local(context.pool()).await?;
|
|
|
|
let federated_instances =
|
|
|
|
build_federated_instances(&site_view.local_site, context.pool()).await?;
|
|
|
|
|
|
|
|
Ok(Self::Response {
|
|
|
|
federated_instances,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|