Add /api/v1/accounts/lookup Mastodon API endpoint

This commit is contained in:
silverpill 2022-12-28 00:13:49 +00:00
parent de9bc7f35e
commit 7ccd29abf2
5 changed files with 43 additions and 1 deletions

View file

@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [Unreleased]
### Added
- Added `/api/v1/accounts/lookup` Mastodon API endpoint.
### Changed
- Updated installation instructions, default mitra config and recommended nginx config.

View file

@ -345,6 +345,25 @@ paths:
type: array
items:
$ref: '#/components/schemas/Relationship'
/api/v1/accounts/lookup:
get:
summary: Lookup webfinger address.
parameters:
- name: acct
in: query
description: The username or Webfinger address to lookup.
required: true
schema:
type: string
responses:
200:
description: Successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/Account'
404:
description: Profile not found
/api/v1/accounts/search:
get:
summary: Search for matching profiles by username.

View file

@ -379,6 +379,11 @@ impl Default for RelationshipMap {
}
}
#[derive(Deserialize)]
pub struct LookupAcctQueryParams {
pub acct: String,
}
fn default_search_page_size() -> PageSize { PageSize::new(40) }
#[derive(Deserialize)]

View file

@ -105,6 +105,7 @@ use super::types::{
IdentityClaim,
IdentityClaimQueryParams,
IdentityProofData,
LookupAcctQueryParams,
MoveFollowersRequest,
RelationshipQueryParams,
SearchAcctQueryParams,
@ -552,6 +553,18 @@ async fn get_relationships_view(
Ok(HttpResponse::Ok().json(vec![relationship]))
}
#[get("/lookup")]
async fn lookup_acct(
config: web::Data<Config>,
db_pool: web::Data<DbPool>,
query_params: web::Query<LookupAcctQueryParams>,
) -> Result<HttpResponse, HttpError> {
let db_client = &**get_database_client(&db_pool).await?;
let profile = get_profile_by_acct(db_client, &query_params.acct).await?;
let account = Account::from_profile(profile, &config.instance_url());
Ok(HttpResponse::Ok().json(account))
}
#[get("/search")]
async fn search_by_acct(
config: web::Data<Config>,
@ -839,6 +852,7 @@ pub fn account_api_scope() -> Scope {
.service(get_identity_claim)
.service(create_identity_proof)
.service(get_relationships_view)
.service(lookup_acct)
.service(search_by_acct)
.service(search_by_did)
// Routes with account ID

View file

@ -13,5 +13,5 @@ pub mod subscriptions;
pub mod timelines;
mod uploads;
const MASTODON_API_VERSION: &str = "3.0.0";
const MASTODON_API_VERSION: &str = "4.0.0";
pub use uploads::UPLOAD_MAX_SIZE;