2021-12-16 23:00:52 +00:00
|
|
|
/// https://docs.joinmastodon.org/methods/instance/directory/
|
2021-11-07 08:52:57 +00:00
|
|
|
use actix_web::{get, web, HttpResponse, Scope};
|
2021-10-05 18:10:14 +00:00
|
|
|
use actix_web_httpauth::extractors::bearer::BearerAuth;
|
2021-04-09 00:22:17 +00:00
|
|
|
|
2023-02-18 23:52:48 +00:00
|
|
|
use mitra_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;
|
2023-02-12 23:07:19 +00:00
|
|
|
use crate::mastodon_api::{
|
|
|
|
accounts::types::Account,
|
|
|
|
oauth::auth::get_current_user,
|
|
|
|
};
|
2021-04-09 00:22:17 +00:00
|
|
|
use crate::models::profiles::queries::get_profiles;
|
2021-12-16 23:00:52 +00:00
|
|
|
use super::types::DirectoryQueryParams;
|
2021-04-09 00:22:17 +00:00
|
|
|
|
2021-11-07 08:52:57 +00:00
|
|
|
#[get("")]
|
|
|
|
async fn profile_directory(
|
2021-10-05 18:10:14 +00:00
|
|
|
auth: BearerAuth,
|
2021-04-09 00:22:17 +00:00
|
|
|
config: web::Data<Config>,
|
2022-12-03 21:23:52 +00:00
|
|
|
db_pool: web::Data<DbPool>,
|
2021-12-16 23:00:52 +00:00
|
|
|
query_params: web::Query<DirectoryQueryParams>,
|
2021-04-09 00:22:17 +00:00
|
|
|
) -> Result<HttpResponse, HttpError> {
|
|
|
|
let db_client = &**get_database_client(&db_pool).await?;
|
2021-10-05 18:10:14 +00:00
|
|
|
get_current_user(db_client, auth.token()).await?;
|
2021-12-16 23:00:52 +00:00
|
|
|
let profiles = get_profiles(
|
|
|
|
db_client,
|
2022-10-02 20:43:51 +00:00
|
|
|
query_params.local,
|
2021-12-16 23:00:52 +00:00
|
|
|
query_params.offset,
|
2022-09-29 21:15:54 +00:00
|
|
|
query_params.limit.inner(),
|
2021-12-16 23:00:52 +00:00
|
|
|
).await?;
|
|
|
|
let accounts: Vec<Account> = profiles
|
2021-04-09 00:22:17 +00:00
|
|
|
.into_iter()
|
|
|
|
.map(|profile| Account::from_profile(profile, &config.instance_url()))
|
|
|
|
.collect();
|
|
|
|
Ok(HttpResponse::Ok().json(accounts))
|
|
|
|
}
|
2021-11-07 08:52:57 +00:00
|
|
|
|
|
|
|
pub fn directory_api_scope() -> Scope {
|
|
|
|
web::scope("/api/v1/directory")
|
|
|
|
.service(profile_directory)
|
|
|
|
}
|