Add /api/v1/accounts/{account_id}/aliases API endpoint

This commit is contained in:
silverpill 2023-02-26 22:10:42 +00:00
parent baec22272d
commit 82b6c4e7cf
3 changed files with 42 additions and 0 deletions

View file

@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Add empty `spoiler_text` property to Mastodon API Status object. - Add empty `spoiler_text` property to Mastodon API Status object.
- Added `error` and `error_description` fields to Mastodon API error responses. - Added `error` and `error_description` fields to Mastodon API error responses.
- Store information about failed activity deliveries in database. - Store information about failed activity deliveries in database.
- Added `/api/v1/accounts/{account_id}/aliases` API endpoint.
### Changed ### Changed

View file

@ -544,6 +544,23 @@ paths:
$ref: '#/components/schemas/Subscription' $ref: '#/components/schemas/Subscription'
404: 404:
description: Profile not found description: Profile not found
/api/v1/accounts/{account_id}/aliases:
get:
summary: Get actor's aliases.
parameters:
- $ref: '#/components/parameters/account_id'
responses:
200:
description: Successful operation
content:
application/json:
schema:
description: Profile list
type: array
items:
$ref: '#/components/schemas/Account'
404:
description: Profile not found
/api/v1/accounts/{account_id}/follow: /api/v1/accounts/{account_id}/follow:
post: post:
summary: Follow the given actor. summary: Follow the given actor.

View file

@ -67,6 +67,7 @@ use crate::mastodon_api::{
}; };
use crate::models::{ use crate::models::{
posts::queries::get_posts_by_author, posts::queries::get_posts_by_author,
profiles::helpers::find_aliases,
profiles::queries::{ profiles::queries::{
get_profile_by_acct, get_profile_by_acct,
get_profile_by_id, get_profile_by_id,
@ -797,6 +798,28 @@ async fn get_account_subscribers(
Ok(HttpResponse::Ok().json(subscriptions)) Ok(HttpResponse::Ok().json(subscriptions))
} }
#[get("/{account_id}/aliases")]
async fn get_account_aliases(
connection_info: ConnectionInfo,
config: web::Data<Config>,
db_pool: web::Data<DbPool>,
account_id: web::Path<Uuid>,
) -> Result<HttpResponse, MastodonError> {
let db_client = &**get_database_client(&db_pool).await?;
let profile = get_profile_by_id(db_client, &account_id).await?;
let aliases = find_aliases(db_client, &profile).await?;
let base_url = get_request_base_url(connection_info);
let instance_url = config.instance_url();
let accounts: Vec<Account> = aliases.into_iter()
.map(|profile| Account::from_profile(
&base_url,
&instance_url,
profile,
))
.collect();
Ok(HttpResponse::Ok().json(accounts))
}
pub fn account_api_scope() -> Scope { pub fn account_api_scope() -> Scope {
web::scope("/api/v1/accounts") web::scope("/api/v1/accounts")
// Routes without account ID // Routes without account ID
@ -819,4 +842,5 @@ pub fn account_api_scope() -> Scope {
.service(get_account_followers) .service(get_account_followers)
.service(get_account_following) .service(get_account_following)
.service(get_account_subscribers) .service(get_account_subscribers)
.service(get_account_aliases)
} }