diff --git a/src/utils/api.ts b/src/utils/api.ts index 72f4c3e..cba7c66 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -76,6 +76,29 @@ async function createAdminEvent(t: EventStub, c: AppContext): Promise string[][], + c: AppContext, +): Promise { + return updateAdminEvent(filter, (prev) => ({ + kind: filter.kinds[0], + content: prev?.content ?? '', + tags: fn(prev?.tags ?? []), + }), c); +} + +/** Fetch existing event, update it, then publish the new admin event. */ +async function updateAdminEvent( + filter: UpdateEventFilter, + fn: (prev: NostrEvent | undefined) => E, + c: AppContext, +): Promise { + const [prev] = await Storages.db.query([filter], { limit: 1, signal: c.req.raw.signal }); + return createAdminEvent(fn(prev), c); +} + /** Push the event through the pipeline, rethrowing any RelayError. */ async function publishEvent(event: NostrEvent, c: AppContext): Promise { debug('EVENT', event); @@ -185,5 +208,6 @@ export { paginationSchema, parseBody, updateEvent, + updateListAdminEvent, updateListEvent, };