From bf76f7b313910c13e0295e07dc3d09757d2e4075 Mon Sep 17 00:00:00 2001 From: AkiraFukushima Date: Thu, 2 May 2024 23:19:39 +0900 Subject: [PATCH] Implement accounts lookup method --- megalodon/src/firefish.ts | 7 +++++++ megalodon/src/friendica.ts | 7 +++++++ megalodon/src/gotosocial.ts | 14 ++++++++++++++ megalodon/src/mastodon.ts | 14 ++++++++++++++ megalodon/src/megalodon.ts | 8 ++++++++ megalodon/src/pleroma.ts | 14 ++++++++++++++ 6 files changed, 64 insertions(+) diff --git a/megalodon/src/firefish.ts b/megalodon/src/firefish.ts index 9d10cdff..d0184ded 100644 --- a/megalodon/src/firefish.ts +++ b/megalodon/src/firefish.ts @@ -617,6 +617,13 @@ export default class Firefish implements MegalodonInterface { }) } + public async lookupAccount(_acct: string): Promise> { + return new Promise((_, reject) => { + const err = new NotImplementedError('Firefish does not support this method') + reject(err) + }) + } + // ====================================== // accounts/bookmarks // ====================================== diff --git a/megalodon/src/friendica.ts b/megalodon/src/friendica.ts index fd29e943..8d153547 100644 --- a/megalodon/src/friendica.ts +++ b/megalodon/src/friendica.ts @@ -738,6 +738,13 @@ export default class Friendica implements MegalodonInterface { }) } + public async lookupAccount(_acct: string): Promise> { + return new Promise((_, reject) => { + const err = new NotImplementedError('Friendica does not support this method') + reject(err) + }) + } + // ====================================== // accounts/bookmarks // ====================================== diff --git a/megalodon/src/gotosocial.ts b/megalodon/src/gotosocial.ts index 4a452a89..fe5b808f 100644 --- a/megalodon/src/gotosocial.ts +++ b/megalodon/src/gotosocial.ts @@ -728,6 +728,20 @@ export default class Gotosocial implements MegalodonInterface { }) } + /** + * GET /api/v1/accounts/lookup + * + * @param acct The username or Webfinger address to lookup. + * @return Account. + */ + public async lookupAccount(acct: string): Promise> { + return this.client.get(`/api/v1/accounts/lookup?acct=${acct}`).then(res => { + return Object.assign(res, { + data: GotosocialAPI.Converter.account(res.data) + }) + }) + } + // ====================================== // accounts/bookmarks // ====================================== diff --git a/megalodon/src/mastodon.ts b/megalodon/src/mastodon.ts index 8ca97e7e..70e0f6ba 100644 --- a/megalodon/src/mastodon.ts +++ b/megalodon/src/mastodon.ts @@ -817,6 +817,20 @@ export default class Mastodon implements MegalodonInterface { }) } + /** + * GET /api/v1/accounts/lookup + * + * @param acct The username or Webfinger address to lookup. + * @return Account. + */ + public async lookupAccount(acct: string): Promise> { + return this.client.get(`/api/v1/accounts/lookup?acct=${acct}`).then(res => { + return Object.assign(res, { + data: MastodonAPI.Converter.account(res.data) + }) + }) + } + // ====================================== // accounts/bookmarks // ====================================== diff --git a/megalodon/src/megalodon.ts b/megalodon/src/megalodon.ts index 2ac3f408..678d41b5 100644 --- a/megalodon/src/megalodon.ts +++ b/megalodon/src/megalodon.ts @@ -367,6 +367,14 @@ export interface MegalodonInterface { since_id?: string } ): Promise>> + /** + * Lookup account ID from Webfinger address. + * + * @param acct Webfinger address. + * @return Account + */ + lookupAccount(acct: string): Promise> + // ====================================== // accounts/bookmarks // ====================================== diff --git a/megalodon/src/pleroma.ts b/megalodon/src/pleroma.ts index fe986f50..6259bbb2 100644 --- a/megalodon/src/pleroma.ts +++ b/megalodon/src/pleroma.ts @@ -815,6 +815,20 @@ export default class Pleroma implements MegalodonInterface { }) } + /** + * GET /api/v1/accounts/lookup + * + * @param acct The username or Webfinger address to lookup. + * @return Account. + */ + public async lookupAccount(acct: string): Promise> { + return this.client.get(`/api/v1/accounts/lookup?acct=${acct}`).then(res => { + return Object.assign(res, { + data: PleromaAPI.Converter.account(res.data) + }) + }) + } + // ====================================== // accounts/bookmarks // ======================================