From 1620668d5aebc50fe8b33c86864b7e31fcc8228b Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 1 Jan 2024 17:02:09 -0600 Subject: [PATCH 1/4] debug: log events signed through the API --- src/utils/web.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/utils/web.ts b/src/utils/web.ts index a7822998..9a3eaf06 100644 --- a/src/utils/web.ts +++ b/src/utils/web.ts @@ -2,6 +2,7 @@ import { type AppContext } from '@/app.ts'; import { Conf } from '@/config.ts'; import { type Context, + Debug, type Event, EventTemplate, Filter, @@ -15,6 +16,8 @@ import { signAdminEvent, signEvent } from '@/sign.ts'; import { nostrNow } from '@/utils.ts'; import { eventsDB } from '@/db/events.ts'; +const debug = Debug('ditto:api'); + /** EventTemplate with defaults. */ type EventStub = TypeFest.SetOptional, 'content' | 'created_at' | 'tags'>; @@ -79,6 +82,7 @@ async function createAdminEvent(t: EventStub, c: AppContext /** Push the event through the pipeline, rethrowing any RelayError. */ async function publishEvent(event: Event, c: AppContext): Promise> { + debug('EVENT', event); try { await pipeline.handleEvent(event); } catch (e) { From 43359f787b535b8a5db0ba041be13f77e57019d6 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 1 Jan 2024 17:03:32 -0600 Subject: [PATCH 2/4] web.ts -> api.ts --- src/controllers/activitypub/actor.ts | 2 +- src/controllers/api/accounts.ts | 3 +-- src/controllers/api/media.ts | 2 +- src/controllers/api/notifications.ts | 2 +- src/controllers/api/oauth.ts | 2 +- src/controllers/api/pleroma.ts | 2 +- src/controllers/api/statuses.ts | 2 +- src/controllers/api/timelines.ts | 2 +- src/middleware/auth98.ts | 2 +- src/sign.ts | 2 +- src/utils/{web.ts => api.ts} | 0 src/views.ts | 2 +- 12 files changed, 11 insertions(+), 12 deletions(-) rename src/utils/{web.ts => api.ts} (100%) diff --git a/src/controllers/activitypub/actor.ts b/src/controllers/activitypub/actor.ts index 49fda36f..6b2c56e3 100644 --- a/src/controllers/activitypub/actor.ts +++ b/src/controllers/activitypub/actor.ts @@ -1,6 +1,6 @@ import { findUser } from '@/db/users.ts'; import { getAuthor } from '@/queries.ts'; -import { activityJson } from '@/utils/web.ts'; +import { activityJson } from '@/utils/api.ts'; import { renderActor } from '@/views/activitypub/actor.ts'; import type { AppContext, AppController } from '@/app.ts'; diff --git a/src/controllers/api/accounts.ts b/src/controllers/api/accounts.ts index 6ad39449..8316ede4 100644 --- a/src/controllers/api/accounts.ts +++ b/src/controllers/api/accounts.ts @@ -10,8 +10,7 @@ import { jsonMetaContentSchema } from '@/schemas/nostr.ts'; import { addTag, deleteTag, getTagSet } from '@/tags.ts'; import { uploadFile } from '@/upload.ts'; import { lookupAccount, nostrNow } from '@/utils.ts'; -import { paginated, paginationSchema, parseBody, updateListEvent } from '@/utils/web.ts'; -import { createEvent } from '@/utils/web.ts'; +import { createEvent, paginated, paginationSchema, parseBody, updateListEvent } from '@/utils/api.ts'; import { renderAccounts, renderEventAccounts, renderStatuses } from '@/views.ts'; import { accountFromPubkey, renderAccount } from '@/views/mastodon/accounts.ts'; import { renderRelationship } from '@/views/mastodon/relationships.ts'; diff --git a/src/controllers/api/media.ts b/src/controllers/api/media.ts index b35da9f1..f8868c17 100644 --- a/src/controllers/api/media.ts +++ b/src/controllers/api/media.ts @@ -1,7 +1,7 @@ import { AppController } from '@/app.ts'; import { z } from '@/deps.ts'; import { fileSchema } from '@/schema.ts'; -import { parseBody } from '@/utils/web.ts'; +import { parseBody } from '@/utils/api.ts'; import { renderAttachment } from '@/views/mastodon/attachments.ts'; import { uploadFile } from '@/upload.ts'; diff --git a/src/controllers/api/notifications.ts b/src/controllers/api/notifications.ts index 881f9aca..f50f8910 100644 --- a/src/controllers/api/notifications.ts +++ b/src/controllers/api/notifications.ts @@ -1,6 +1,6 @@ import { type AppController } from '@/app.ts'; import { eventsDB } from '@/db/events.ts'; -import { paginated, paginationSchema } from '@/utils/web.ts'; +import { paginated, paginationSchema } from '@/utils/api.ts'; import { renderNotification } from '@/views/mastodon/notifications.ts'; const notificationsController: AppController = async (c) => { diff --git a/src/controllers/api/oauth.ts b/src/controllers/api/oauth.ts index 19daff6b..267abb70 100644 --- a/src/controllers/api/oauth.ts +++ b/src/controllers/api/oauth.ts @@ -1,7 +1,7 @@ import { lodash, nip19, z } from '@/deps.ts'; import { AppController } from '@/app.ts'; import { nostrNow } from '@/utils.ts'; -import { parseBody } from '@/utils/web.ts'; +import { parseBody } from '@/utils/api.ts'; const passwordGrantSchema = z.object({ grant_type: z.literal('password'), diff --git a/src/controllers/api/pleroma.ts b/src/controllers/api/pleroma.ts index 450be07f..3b842273 100644 --- a/src/controllers/api/pleroma.ts +++ b/src/controllers/api/pleroma.ts @@ -2,7 +2,7 @@ import { type AppController } from '@/app.ts'; import { eventsDB } from '@/db/events.ts'; import { z } from '@/deps.ts'; import { configSchema, elixirTupleSchema } from '@/schemas/pleroma-api.ts'; -import { createAdminEvent } from '@/utils/web.ts'; +import { createAdminEvent } from '@/utils/api.ts'; import { Conf } from '@/config.ts'; const frontendConfigController: AppController = async (c) => { diff --git a/src/controllers/api/statuses.ts b/src/controllers/api/statuses.ts index 9cb789bf..82be6ad6 100644 --- a/src/controllers/api/statuses.ts +++ b/src/controllers/api/statuses.ts @@ -3,7 +3,7 @@ import { getUnattachedMediaByIds } from '@/db/unattached-media.ts'; import { type Event, ISO6391, z } from '@/deps.ts'; import { getAncestors, getAuthor, getDescendants, getEvent } from '@/queries.ts'; import { addTag, deleteTag } from '@/tags.ts'; -import { createEvent, paginationSchema, parseBody, updateListEvent } from '@/utils/web.ts'; +import { createEvent, paginationSchema, parseBody, updateListEvent } from '@/utils/api.ts'; import { renderEventAccounts } from '@/views.ts'; import { renderStatus } from '@/views/mastodon/statuses.ts'; diff --git a/src/controllers/api/timelines.ts b/src/controllers/api/timelines.ts index 2a20fddc..6d932801 100644 --- a/src/controllers/api/timelines.ts +++ b/src/controllers/api/timelines.ts @@ -3,7 +3,7 @@ import { z } from '@/deps.ts'; import { type DittoFilter } from '@/filter.ts'; import { getFeedPubkeys } from '@/queries.ts'; import { booleanParamSchema } from '@/schema.ts'; -import { paginated, paginationSchema } from '@/utils/web.ts'; +import { paginated, paginationSchema } from '@/utils/api.ts'; import { renderStatus } from '@/views/mastodon/statuses.ts'; import type { AppContext, AppController } from '@/app.ts'; diff --git a/src/middleware/auth98.ts b/src/middleware/auth98.ts index 0520010e..67beac67 100644 --- a/src/middleware/auth98.ts +++ b/src/middleware/auth98.ts @@ -6,7 +6,7 @@ import { type ParseAuthRequestOpts, validateAuthEvent, } from '@/utils/nip98.ts'; -import { localRequest } from '@/utils/web.ts'; +import { localRequest } from '@/utils/api.ts'; import { signEvent } from '@/sign.ts'; import { findUser, User } from '@/db/users.ts'; diff --git a/src/sign.ts b/src/sign.ts index de7149fe..0ab9608b 100644 --- a/src/sign.ts +++ b/src/sign.ts @@ -6,7 +6,7 @@ import { connectResponseSchema } from '@/schemas/nostr.ts'; import { jsonSchema } from '@/schema.ts'; import { Sub } from '@/subs.ts'; import { eventMatchesTemplate, Time } from '@/utils.ts'; -import { createAdminEvent } from '@/utils/web.ts'; +import { createAdminEvent } from '@/utils/api.ts'; const debug = Debug('ditto:sign'); diff --git a/src/utils/web.ts b/src/utils/api.ts similarity index 100% rename from src/utils/web.ts rename to src/utils/api.ts diff --git a/src/views.ts b/src/views.ts index b87baad7..c90f26d9 100644 --- a/src/views.ts +++ b/src/views.ts @@ -3,7 +3,7 @@ import { eventsDB } from '@/db/events.ts'; import { type Filter } from '@/deps.ts'; import { renderAccount } from '@/views/mastodon/accounts.ts'; import { renderStatus } from '@/views/mastodon/statuses.ts'; -import { paginated, paginationSchema } from '@/utils/web.ts'; +import { paginated, paginationSchema } from '@/utils/api.ts'; /** Render account objects for the author of each event. */ async function renderEventAccounts(c: AppContext, filters: Filter[], signal = AbortSignal.timeout(1000)) { From d13b7435a720f5a47dd6ecbfb1748382cde9f3a7 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 1 Jan 2024 17:30:01 -0600 Subject: [PATCH 3/4] debug: minimize socket close output --- src/subs.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/subs.ts b/src/subs.ts index c716e018..08ffbd24 100644 --- a/src/subs.ts +++ b/src/subs.ts @@ -48,7 +48,7 @@ class SubscriptionStore { /** Remove an entire socket. */ close(socket: unknown): void { - debug('close', socket); + debug('close', (socket as any)?.constructor?.name); const subs = this.#store.get(socket); if (subs) { From 777ac39ec7031b5a47ad3bc0a75970f6031ed190 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 1 Jan 2024 17:47:15 -0600 Subject: [PATCH 4/4] debug: improve output for nip05 --- src/utils/nip05.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/utils/nip05.ts b/src/utils/nip05.ts index 4fa38084..f885641e 100644 --- a/src/utils/nip05.ts +++ b/src/utils/nip05.ts @@ -29,7 +29,8 @@ async function lookup(value: string, opts: LookupOpts = {}): Promise { const result = lookup(value); nip05Cache.set(value, result); + result.then((result) => { + if (result) { + debug(`Found: ${value} is ${result}`); + } else { + debug(`Not found: ${value} is ${result}`); + } + }); + return result; }