diff --git a/cli/src/commands/social/whois.ts b/cli/src/commands/social/whois.ts index dd6fcbf17e0..1ba2b293de3 100644 --- a/cli/src/commands/social/whois.ts +++ b/cli/src/commands/social/whois.ts @@ -7,7 +7,7 @@ export default cmd({ name: 'whois', category: 'social', help: 'Display the profile of the given user.', - args: [{ name: 'user' }], + args: [{ name: 'username' }], opts: [], async command(args) { const nameOrDid = args._[0] diff --git a/common/src/microblog/delegator.ts b/common/src/microblog/delegator.ts index 0fe77b41ab1..0ffb814507e 100644 --- a/common/src/microblog/delegator.ts +++ b/common/src/microblog/delegator.ts @@ -95,20 +95,26 @@ export class MicroblogDelegator { await service.register(this.url, username, this.did, true, token) } - async lookupDid(username: string): Promise { + normalizeUsername(username: string): { name: string; hostUrl: string } { const [name, host] = username.split('@') - if (!host) { - return service.lookupDid(this.url, name) + if (host) { + return { name, hostUrl: 'http://' + host } } else { - return service.lookupDid(`http://${host}`, name) + return { name, hostUrl: this.url } } } - async getAccountInfo(nameOrDid: string): Promise { - const did = await this.resolveDid(nameOrDid) + async lookupDid(username: string): Promise { + const { name, hostUrl } = this.normalizeUsername(username) + return service.lookupDid(hostUrl, name) + } + + async getAccountInfo(username: string): Promise { + const { hostUrl } = this.normalizeUsername(username) + const did = await this.resolveDid(username) const params = { did } try { - const res = await axios.get(`${this.url}/indexer/account-info`, { + const res = await axios.get(`${hostUrl}/indexer/account-info`, { params, }) return check.assure(schema.accountInfo, res.data)