2021-11-07 08:52:57 +00:00
|
|
|
use actix_web::{get, web, HttpResponse, Scope};
|
2021-04-09 00:22:17 +00:00
|
|
|
|
|
|
|
use crate::config::Config;
|
2022-12-03 21:23:52 +00:00
|
|
|
use crate::database::{get_database_client, DbPool};
|
2021-04-09 00:22:17 +00:00
|
|
|
use crate::errors::HttpError;
|
2022-06-28 23:02:31 +00:00
|
|
|
use crate::ethereum::contracts::ContractSet;
|
2022-10-04 20:50:00 +00:00
|
|
|
use crate::models::{
|
|
|
|
instances::queries::get_peer_count,
|
|
|
|
posts::queries::get_local_post_count,
|
|
|
|
users::queries::get_user_count,
|
|
|
|
};
|
2021-11-10 14:32:27 +00:00
|
|
|
use super::types::InstanceInfo;
|
2021-04-09 00:22:17 +00:00
|
|
|
|
2023-01-06 16:46:59 +00:00
|
|
|
/// https://docs.joinmastodon.org/methods/instance/#v1
|
2021-11-07 08:52:57 +00:00
|
|
|
#[get("")]
|
|
|
|
async fn instance_view(
|
|
|
|
config: web::Data<Config>,
|
2022-12-03 21:23:52 +00:00
|
|
|
db_pool: web::Data<DbPool>,
|
2022-06-28 23:02:31 +00:00
|
|
|
maybe_blockchain: web::Data<Option<ContractSet>>,
|
2021-04-09 00:22:17 +00:00
|
|
|
) -> Result<HttpResponse, HttpError> {
|
2022-10-04 20:50:00 +00:00
|
|
|
let db_client = &**get_database_client(&db_pool).await?;
|
|
|
|
let user_count = get_user_count(db_client).await?;
|
|
|
|
let post_count = get_local_post_count(db_client).await?;
|
|
|
|
let peer_count = get_peer_count(db_client).await?;
|
2022-06-28 23:02:31 +00:00
|
|
|
let instance = InstanceInfo::create(
|
|
|
|
config.as_ref(),
|
|
|
|
maybe_blockchain.as_ref().as_ref(),
|
2022-10-04 20:50:00 +00:00
|
|
|
user_count,
|
|
|
|
post_count,
|
|
|
|
peer_count,
|
2022-06-28 23:02:31 +00:00
|
|
|
);
|
2021-04-09 00:22:17 +00:00
|
|
|
Ok(HttpResponse::Ok().json(instance))
|
|
|
|
}
|
2021-11-07 08:52:57 +00:00
|
|
|
|
|
|
|
pub fn instance_api_scope() -> Scope {
|
|
|
|
web::scope("/api/v1/instance")
|
|
|
|
.service(instance_view)
|
|
|
|
}
|