mirror of
https://github.com/aljazceru/ditto.git
synced 2025-12-17 05:24:22 +01:00
refactor(updateInstanceController): move async function out of callback
This commit is contained in:
@@ -311,10 +311,11 @@ export const updateInstanceController: AppController = async (c) => {
|
|||||||
return c.json(result.error, 422);
|
return c.json(result.error, 422);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const meta = await getInstanceMetadata(await Storages.db(), c.req.raw.signal);
|
||||||
|
|
||||||
await updateAdminEvent(
|
await updateAdminEvent(
|
||||||
{ kinds: [0], authors: [pubkey], limit: 1 },
|
{ kinds: [0], authors: [pubkey], limit: 1 },
|
||||||
async (_) => {
|
(_) => {
|
||||||
const meta = await getInstanceMetadata(await Storages.db(), c.req.raw.signal);
|
|
||||||
const {
|
const {
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
|
|||||||
@@ -111,12 +111,12 @@ function updateListAdminEvent(
|
|||||||
/** Fetch existing event, update it, then publish the new admin event. */
|
/** Fetch existing event, update it, then publish the new admin event. */
|
||||||
async function updateAdminEvent<E extends EventStub>(
|
async function updateAdminEvent<E extends EventStub>(
|
||||||
filter: UpdateEventFilter,
|
filter: UpdateEventFilter,
|
||||||
fn: (prev: NostrEvent | undefined) => E | Promise<E>,
|
fn: (prev: NostrEvent | undefined) => E,
|
||||||
c: AppContext,
|
c: AppContext,
|
||||||
): Promise<NostrEvent> {
|
): Promise<NostrEvent> {
|
||||||
const store = await Storages.db();
|
const store = await Storages.db();
|
||||||
const [prev] = await store.query([filter], { limit: 1, signal: c.req.raw.signal });
|
const [prev] = await store.query([filter], { limit: 1, signal: c.req.raw.signal });
|
||||||
return createAdminEvent(await fn(prev), c);
|
return createAdminEvent(fn(prev), c);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateUser(pubkey: string, n: Record<string, boolean>, c: AppContext): Promise<NostrEvent> {
|
function updateUser(pubkey: string, n: Record<string, boolean>, c: AppContext): Promise<NostrEvent> {
|
||||||
|
|||||||
Reference in New Issue
Block a user