Let searchController look up accounts

This commit is contained in:
Alex Gleason
2023-05-13 14:45:13 -05:00
parent 017a34d5d4
commit a766449ba6
4 changed files with 41 additions and 16 deletions

View File

@@ -1,11 +1,8 @@
import { type AppController } from '@/app.ts';
import { z } from '@/deps.ts';
import { getAuthor, getFilter, getFollows } from '@/client.ts';
import { lookupNip05Cached } from '@/nip05.ts';
import { toAccount, toStatus } from '@/transmute.ts';
import { bech32ToPubkey, eventDateComparator } from '@/utils.ts';
import type { Event } from '@/event.ts';
import { eventDateComparator, lookupAccount } from '@/utils.ts';
const credentialsController: AppController = async (c) => {
const pubkey = c.get('pubkey')!;
@@ -107,17 +104,6 @@ const accountStatusesController: AppController = async (c) => {
return c.json(statuses);
};
/** Resolve a bech32 or NIP-05 identifier to an account. */
async function lookupAccount(value: string): Promise<Event<0> | undefined> {
console.log(`Looking up ${value}`);
const pubkey = bech32ToPubkey(value) || await lookupNip05Cached(value);
if (pubkey) {
return getAuthor(pubkey);
}
}
export {
accountController,
accountLookupController,

View File

@@ -0,0 +1,23 @@
import { AppController } from '@/app.ts';
import { lookupAccount } from '../../utils.ts';
import { toAccount } from '../../transmute.ts';
const searchController: AppController = async (c) => {
const q = c.req.query('q');
if (!q) {
return c.json({ error: 'Missing `q` query parameter.' }, 422);
}
// For now, only support looking up accounts.
// TODO: Support searching statuses and hashtags.
const event = await lookupAccount(decodeURIComponent(q));
return c.json({
accounts: event ? [await toAccount(event)] : [],
statuses: [],
hashtags: [],
});
};
export { searchController };