mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
refactor(updateCredentialsController): stop overwriting kind 0 unnecessarily
This commit is contained in:
parent
b45fcdde69
commit
30d7f1a053
1 changed files with 52 additions and 44 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { NostrFilter, NSchema as n } from '@nostrify/nostrify';
|
import { NostrEvent, NostrFilter, NSchema as n } from '@nostrify/nostrify';
|
||||||
import { nip19 } from 'nostr-tools';
|
import { nip19 } from 'nostr-tools';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
|
@ -288,12 +288,19 @@ const updateCredentialsController: AppController = async (c) => {
|
||||||
const pubkey = await signer.getPublicKey();
|
const pubkey = await signer.getPublicKey();
|
||||||
const body = await parseBody(c.req.raw);
|
const body = await parseBody(c.req.raw);
|
||||||
const result = updateCredentialsSchema.safeParse(body);
|
const result = updateCredentialsSchema.safeParse(body);
|
||||||
|
const store = await Storages.db();
|
||||||
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
return c.json(result.error, 422);
|
return c.json(result.error, 422);
|
||||||
}
|
}
|
||||||
|
|
||||||
const event = await updateEvent(
|
const keys = Object.keys(result.data);
|
||||||
|
let event: NostrEvent;
|
||||||
|
|
||||||
|
if (keys.length === 1 && keys[0] === 'pleroma_settings_store') {
|
||||||
|
event = (await store.query([{ kinds: [0], authors: [pubkey] }]))[0];
|
||||||
|
} else {
|
||||||
|
event = await updateEvent(
|
||||||
{ kinds: [0], authors: [pubkey], limit: 1 },
|
{ kinds: [0], authors: [pubkey], limit: 1 },
|
||||||
async (prev) => {
|
async (prev) => {
|
||||||
const meta = n.json().pipe(metadataSchema).catch({}).parse(prev.content);
|
const meta = n.json().pipe(metadataSchema).catch({}).parse(prev.content);
|
||||||
|
|
@ -341,6 +348,7 @@ const updateCredentialsController: AppController = async (c) => {
|
||||||
},
|
},
|
||||||
c,
|
c,
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const settingsStore = result.data.pleroma_settings_store;
|
const settingsStore = result.data.pleroma_settings_store;
|
||||||
const account = await renderAccount(event, { withSource: true, settingsStore });
|
const account = await renderAccount(event, { withSource: true, settingsStore });
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue