mirror of
https://github.com/aljazceru/ditto.git
synced 2026-01-22 14:54:22 +01:00
Refactor db.ts to use kysely statements
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { getAuthor } from '@/client.ts';
|
||||
import { db } from '@/db.ts';
|
||||
import { findUser } from '@/db/users.ts';
|
||||
import { toActor } from '@/transformers/nostr-to-activitypub.ts';
|
||||
import { activityJson } from '@/utils.ts';
|
||||
|
||||
@@ -8,7 +8,7 @@ import type { AppContext, AppController } from '@/app.ts';
|
||||
const actorController: AppController = async (c) => {
|
||||
const username = c.req.param('username');
|
||||
|
||||
const user = db.getUserByUsername(username);
|
||||
const user = await findUser({ username });
|
||||
if (!user) return notFound(c);
|
||||
|
||||
const event = await getAuthor(user.pubkey);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Conf } from '@/config.ts';
|
||||
import { db } from '@/db.ts';
|
||||
import { findUser } from '@/db/users.ts';
|
||||
import { z } from '@/deps.ts';
|
||||
|
||||
import type { AppController } from '@/app.ts';
|
||||
@@ -10,9 +10,9 @@ const nameSchema = z.string().min(1).regex(/^\w+$/);
|
||||
* Serves NIP-05's nostr.json.
|
||||
* https://github.com/nostr-protocol/nips/blob/master/05.md
|
||||
*/
|
||||
const nostrController: AppController = (c) => {
|
||||
const nostrController: AppController = async (c) => {
|
||||
const name = nameSchema.safeParse(c.req.query('name'));
|
||||
const user = name.success ? db.getUserByUsername(name.data) : null;
|
||||
const user = name.success ? await findUser({ username: name.data }) : null;
|
||||
|
||||
if (!user) return c.json({ names: {}, relays: {} });
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import { nip19, z } from '@/deps.ts';
|
||||
|
||||
import type { AppContext, AppController } from '@/app.ts';
|
||||
import type { Webfinger } from '@/schemas/webfinger.ts';
|
||||
import { findUser } from '@/db/users.ts';
|
||||
|
||||
const webfingerQuerySchema = z.object({
|
||||
resource: z.string().url(),
|
||||
@@ -36,14 +37,14 @@ const acctSchema = z.custom<URL>((value) => value instanceof URL)
|
||||
path: ['resource', 'acct'],
|
||||
});
|
||||
|
||||
function handleAcct(c: AppContext, resource: URL): Response {
|
||||
async function handleAcct(c: AppContext, resource: URL): Promise<Response> {
|
||||
const result = acctSchema.safeParse(resource);
|
||||
if (!result.success) {
|
||||
return c.json({ error: 'Invalid acct URI', schema: result.error }, 400);
|
||||
}
|
||||
|
||||
const [username, host] = result.data;
|
||||
const user = db.getUserByUsername(username);
|
||||
const user = await findUser({ username });
|
||||
|
||||
if (!user) {
|
||||
return c.json({ error: 'Not found' }, 404);
|
||||
|
||||
Reference in New Issue
Block a user