mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
refactor(updateInstanceController): move async function out of callback
This commit is contained in:
parent
33b36ba0ed
commit
d9cc8cc7c2
2 changed files with 5 additions and 4 deletions
|
|
@ -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> {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue