Skip to content

Commit

Permalink
Look up account info on users own server
Browse files Browse the repository at this point in the history
  • Loading branch information
dholms committed Apr 12, 2022
1 parent 7e2fc3a commit 48b9ca5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cli/src/commands/social/whois.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
20 changes: 13 additions & 7 deletions common/src/microblog/delegator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,26 @@ export class MicroblogDelegator {
await service.register(this.url, username, this.did, true, token)
}

async lookupDid(username: string): Promise<string | null> {
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<AccountInfo | null> {
const did = await this.resolveDid(nameOrDid)
async lookupDid(username: string): Promise<string | null> {
const { name, hostUrl } = this.normalizeUsername(username)
return service.lookupDid(hostUrl, name)
}

async getAccountInfo(username: string): Promise<AccountInfo | null> {
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)
Expand Down

0 comments on commit 48b9ca5

Please sign in to comment.