mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Merge remote-tracking branch 'origin/main' into router
This commit is contained in:
commit
403b16a67b
5 changed files with 25 additions and 8 deletions
|
|
@ -80,7 +80,13 @@ export const nameRequestController: AppController = async (c) => {
|
|||
const { conf, relay, user } = c.var;
|
||||
|
||||
const pubkey = await user!.signer.getPublicKey();
|
||||
const { name, reason } = nameRequestSchema.parse(await c.req.json());
|
||||
const result = nameRequestSchema.safeParse(await c.req.json());
|
||||
|
||||
if (!result.success) {
|
||||
return c.json({ error: 'Invalid username', schema: result.error }, 400);
|
||||
}
|
||||
|
||||
const { name, reason } = result.data;
|
||||
|
||||
const [existing] = await relay.query([{ kinds: [3036], authors: [pubkey], '#r': [name], limit: 1 }]);
|
||||
if (existing) {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@ import { logi } from '@soapbox/logi';
|
|||
import { errorJson } from '@/utils/log.ts';
|
||||
|
||||
export const errorHandler: ErrorHandler = (err, c) => {
|
||||
const { method } = c.req;
|
||||
const { pathname } = new URL(c.req.url);
|
||||
|
||||
c.header('Cache-Control', 'no-store');
|
||||
|
||||
if (err instanceof HTTPException) {
|
||||
|
|
@ -19,7 +22,7 @@ export const errorHandler: ErrorHandler = (err, c) => {
|
|||
return c.json({ error: 'The server was unable to respond in a timely manner' }, 500);
|
||||
}
|
||||
|
||||
logi({ level: 'error', ns: 'ditto.http', msg: 'Unhandled error', error: errorJson(err) });
|
||||
logi({ level: 'error', ns: 'ditto.http', msg: 'Unhandled error', method, pathname, error: errorJson(err) });
|
||||
|
||||
return c.json({ error: 'Something went wrong' }, 500);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ export const logiMiddleware: MiddlewareHandler = async (c, next) => {
|
|||
await next();
|
||||
|
||||
const end = new Date();
|
||||
const delta = (end.getTime() - start.getTime()) / 1000;
|
||||
const duration = (end.getTime() - start.getTime()) / 1000;
|
||||
const level = c.res.status >= 500 ? 'error' : 'info';
|
||||
|
||||
logi({ level, ns: 'ditto.http.response', method, pathname, status: c.res.status, delta });
|
||||
logi({ level, ns: 'ditto.http.response', method, pathname, status: c.res.status, duration });
|
||||
};
|
||||
|
|
|
|||
|
|
@ -190,7 +190,7 @@ async function updateAuthorData(event: NostrEvent, signal: AbortSignal): Promise
|
|||
if (nip05) {
|
||||
const tld = tldts.parse(nip05);
|
||||
if (tld.isIcann && !tld.isIp && !tld.isPrivate) {
|
||||
const pointer = await nip05Cache.fetch(nip05.toLowerCase(), { signal });
|
||||
const pointer = await nip05Cache.fetch(nip05, { signal });
|
||||
if (pointer.pubkey === event.pubkey) {
|
||||
updates.nip05 = nip05;
|
||||
updates.nip05_domain = tld.domain;
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import { RelayError } from '@/RelayError.ts';
|
|||
import { Storages } from '@/storages.ts';
|
||||
import { nostrNow } from '@/utils.ts';
|
||||
import { parseFormData } from '@/utils/formdata.ts';
|
||||
import { errorJson } from '@/utils/log.ts';
|
||||
import { purifyEvent } from '@/utils/purify.ts';
|
||||
|
||||
/** EventTemplate with defaults. */
|
||||
|
|
@ -157,9 +158,16 @@ async function updateNames(k: number, d: string, n: Record<string, boolean>, c:
|
|||
async function publishEvent(event: NostrEvent, c: AppContext): Promise<NostrEvent> {
|
||||
logi({ level: 'info', ns: 'ditto.event', source: 'api', id: event.id, kind: event.kind });
|
||||
try {
|
||||
await pipeline.handleEvent(event, { source: 'api', signal: c.req.raw.signal });
|
||||
const promise = pipeline.handleEvent(event, { source: 'api', signal: c.req.raw.signal });
|
||||
|
||||
promise.then(async () => {
|
||||
const client = await Storages.client();
|
||||
await client.event(purifyEvent(event));
|
||||
}).catch((e: unknown) => {
|
||||
logi({ level: 'error', ns: 'ditto.pool', id: event.id, kind: event.kind, error: errorJson(e) });
|
||||
});
|
||||
|
||||
await promise;
|
||||
} catch (e) {
|
||||
if (e instanceof RelayError) {
|
||||
throw new HTTPException(422, {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue