mirror of
https://github.com/aljazceru/ditto.git
synced 2026-01-25 00:04:22 +01:00
Let searchController look up accounts
This commit is contained in:
@@ -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,
|
||||
|
||||
23
src/controllers/api/search.ts
Normal file
23
src/controllers/api/search.ts
Normal 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 };
|
||||
Reference in New Issue
Block a user