mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-22 04:11:17 +00:00
This commit is contained in:
parent
90c6dc2732
commit
33ba1fc623
9 changed files with 56 additions and 7 deletions
29
crates/api/src/site/federated_instances.rs
Normal file
29
crates/api/src/site/federated_instances.rs
Normal file
|
@ -0,0 +1,29 @@
|
|||
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;
|
||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for GetFederatedInstances {
|
||||
type Response = GetFederatedInstancesResponse;
|
||||
|
||||
#[tracing::instrument(skip(context, _websocket_id))]
|
||||
async fn perform(
|
||||
&self,
|
||||
context: &Data<LemmyContext>,
|
||||
_websocket_id: Option<ConnectionId>,
|
||||
) -> Result<Self::Response, LemmyError> {
|
||||
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,
|
||||
})
|
||||
}
|
||||
}
|
|
@ -73,7 +73,6 @@ impl Perform for LeaveAdmin {
|
|||
online: 0,
|
||||
version: version::VERSION.to_string(),
|
||||
my_user: None,
|
||||
federated_instances: None,
|
||||
all_languages,
|
||||
discussion_languages,
|
||||
taglines,
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
mod federated_instances;
|
||||
mod leave_admin;
|
||||
mod mod_log;
|
||||
mod purge;
|
||||
|
|
|
@ -222,13 +222,20 @@ pub struct GetSiteResponse {
|
|||
pub online: usize,
|
||||
pub version: String,
|
||||
pub my_user: Option<MyUserInfo>,
|
||||
pub federated_instances: Option<FederatedInstances>, // Federation may be disabled
|
||||
pub all_languages: Vec<Language>,
|
||||
pub discussion_languages: Vec<LanguageId>,
|
||||
pub taglines: Vec<Tagline>,
|
||||
pub custom_emojis: Vec<CustomEmojiView>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct GetFederatedInstances {}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct GetFederatedInstancesResponse {
|
||||
pub federated_instances: Option<FederatedInstances>, // Federation may be disabled
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct MyUserInfo {
|
||||
pub local_user_view: LocalUserView,
|
||||
|
|
|
@ -94,6 +94,7 @@ pub enum UserOperation {
|
|||
PurgeCommunity,
|
||||
PurgePost,
|
||||
PurgeComment,
|
||||
GetFederatedInstances,
|
||||
}
|
||||
|
||||
#[derive(EnumString, Display, Debug, Clone)]
|
||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
|||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
site::{GetSite, GetSiteResponse, MyUserInfo},
|
||||
utils::{build_federated_instances, get_local_user_settings_view_from_jwt_opt},
|
||||
utils::get_local_user_settings_view_from_jwt_opt,
|
||||
websocket::handlers::online_users::GetUsersOnline,
|
||||
};
|
||||
use lemmy_db_schema::source::{
|
||||
|
@ -84,9 +84,6 @@ impl PerformCrud for GetSite {
|
|||
None
|
||||
};
|
||||
|
||||
let federated_instances =
|
||||
build_federated_instances(&site_view.local_site, context.pool()).await?;
|
||||
|
||||
let all_languages = Language::read_all(context.pool()).await?;
|
||||
let discussion_languages = SiteLanguage::read_local_raw(context.pool()).await?;
|
||||
let taglines = Tagline::get_all(context.pool(), site_view.local_site.id).await?;
|
||||
|
@ -98,7 +95,6 @@ impl PerformCrud for GetSite {
|
|||
online,
|
||||
version: version::VERSION.to_string(),
|
||||
my_user,
|
||||
federated_instances,
|
||||
all_languages,
|
||||
discussion_languages,
|
||||
taglines,
|
||||
|
|
|
@ -93,6 +93,8 @@ use lemmy_api_common::{
|
|||
ApproveRegistrationApplication,
|
||||
CreateSite,
|
||||
EditSite,
|
||||
GetFederatedInstances,
|
||||
GetFederatedInstancesResponse,
|
||||
GetModlog,
|
||||
GetModlogResponse,
|
||||
GetSite,
|
||||
|
@ -373,3 +375,7 @@ impl SendActivity for EditCustomEmoji {
|
|||
impl SendActivity for DeleteCustomEmoji {
|
||||
type Response = DeleteCustomEmojiResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for GetFederatedInstances {
|
||||
type Response = GetFederatedInstancesResponse;
|
||||
}
|
||||
|
|
|
@ -86,6 +86,7 @@ use lemmy_api_common::{
|
|||
ApproveRegistrationApplication,
|
||||
CreateSite,
|
||||
EditSite,
|
||||
GetFederatedInstances,
|
||||
GetModlog,
|
||||
GetSite,
|
||||
GetUnreadRegistrationApplicationCount,
|
||||
|
@ -165,6 +166,11 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
|
|||
.route("/join", web::post().to(route_post::<CommunityJoin>))
|
||||
.route("/mod/join", web::post().to(route_post::<ModJoin>)),
|
||||
)
|
||||
.service(
|
||||
web::scope("/federated_instances")
|
||||
.wrap(rate_limit.message())
|
||||
.route("", web::get().to(route_get::<GetFederatedInstances>)),
|
||||
)
|
||||
// Post
|
||||
.service(
|
||||
// Handle POST to /post separately to add the post() rate limitter
|
||||
|
|
|
@ -98,6 +98,7 @@ use lemmy_api_common::{
|
|||
ApproveRegistrationApplication,
|
||||
CreateSite,
|
||||
EditSite,
|
||||
GetFederatedInstances,
|
||||
GetModlog,
|
||||
GetSite,
|
||||
GetUnreadRegistrationApplicationCount,
|
||||
|
@ -640,6 +641,9 @@ pub async fn match_websocket_operation(
|
|||
do_websocket_operation::<TransferCommunity>(context, id, op, data).await
|
||||
}
|
||||
UserOperation::LeaveAdmin => do_websocket_operation::<LeaveAdmin>(context, id, op, data).await,
|
||||
UserOperation::GetFederatedInstances => {
|
||||
do_websocket_operation::<GetFederatedInstances>(context, id, op, data).await
|
||||
}
|
||||
|
||||
// Community ops
|
||||
UserOperation::FollowCommunity => {
|
||||
|
|
Loading…
Reference in a new issue