updateCredentialsController: delete empty fields from metadata

This commit is contained in:
Alex Gleason 2024-05-25 09:17:56 -05:00
parent 5dee6450ec
commit 4f32972d85
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 9 additions and 3 deletions

View File

@ -1,4 +1,4 @@
import { NostrFilter, NSchema as n } from '@nostrify/nostrify';
import { NostrFilter, NostrMetadata, NSchema as n } from '@nostrify/nostrify';
import { nip19 } from 'nostr-tools';
import { z } from 'zod';
@ -220,8 +220,8 @@ const accountStatusesController: AppController = async (c) => {
const updateCredentialsSchema = z.object({
display_name: z.string().optional(),
note: z.string().optional(),
avatar: fileSchema.optional(),
header: fileSchema.optional(),
avatar: fileSchema.or(z.literal('')).optional(),
header: fileSchema.or(z.literal('')).optional(),
locked: z.boolean().optional(),
bot: z.boolean().optional(),
discoverable: z.boolean().optional(),
@ -269,6 +269,12 @@ const updateCredentialsController: AppController = async (c) => {
meta.website = website ?? meta.website;
meta.bot = bot ?? meta.bot;
if (avatarFile === '') delete meta.picture;
if (headerFile === '') delete meta.banner;
if (nip05 === '') delete meta.nip05;
if (lud16 === '') delete meta.lud16;
if (website === '') delete meta.website;
const event = await createEvent({
kind: 0,
content: JSON.stringify(meta),