From 5dee6450ec1287b8b80621e29f6675004f56af2e Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Sat, 25 May 2024 10:41:39 -0300 Subject: [PATCH 1/4] fix(update credentials): allow only valid data or empty string --- src/controllers/api/accounts.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/controllers/api/accounts.ts b/src/controllers/api/accounts.ts index 55964a0..8844a69 100644 --- a/src/controllers/api/accounts.ts +++ b/src/controllers/api/accounts.ts @@ -225,10 +225,10 @@ const updateCredentialsSchema = z.object({ locked: z.boolean().optional(), bot: z.boolean().optional(), discoverable: z.boolean().optional(), - nip05: z.string().email().optional(), + nip05: z.union([z.string().email().optional(), z.literal('')]), pleroma_settings_store: z.unknown().optional(), - lud16: z.string().email().optional(), - website: z.string().url().optional(), + lud16: z.union([z.string().email().optional(), z.literal('')]), + website: z.union([z.string().url().optional(), z.literal('')]), }); const updateCredentialsController: AppController = async (c) => { From 4f32972d850275840173822f282240771ac77bd0 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 25 May 2024 09:17:56 -0500 Subject: [PATCH 2/4] updateCredentialsController: delete empty fields from metadata --- src/controllers/api/accounts.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/controllers/api/accounts.ts b/src/controllers/api/accounts.ts index 8844a69..3c2a985 100644 --- a/src/controllers/api/accounts.ts +++ b/src/controllers/api/accounts.ts @@ -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), From b64ea84b825dae1e58bc88f8e4aaa72a800775b9 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 25 May 2024 09:20:16 -0500 Subject: [PATCH 3/4] Use z.or --- src/controllers/api/accounts.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/controllers/api/accounts.ts b/src/controllers/api/accounts.ts index 3c2a985..857def2 100644 --- a/src/controllers/api/accounts.ts +++ b/src/controllers/api/accounts.ts @@ -225,10 +225,10 @@ const updateCredentialsSchema = z.object({ locked: z.boolean().optional(), bot: z.boolean().optional(), discoverable: z.boolean().optional(), - nip05: z.union([z.string().email().optional(), z.literal('')]), + nip05: z.string().email().or(z.literal('')).optional(), pleroma_settings_store: z.unknown().optional(), - lud16: z.union([z.string().email().optional(), z.literal('')]), - website: z.union([z.string().url().optional(), z.literal('')]), + lud16: z.string().email().or(z.literal('')).optional(), + website: z.string().url().or(z.literal('')).optional(), }); const updateCredentialsController: AppController = async (c) => { From c89867f486399f5b6e524a7b98536ce5fa10af20 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 25 May 2024 09:25:09 -0500 Subject: [PATCH 4/4] Remove unused NostrMetadata import --- src/controllers/api/accounts.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/api/accounts.ts b/src/controllers/api/accounts.ts index 857def2..ef9d634 100644 --- a/src/controllers/api/accounts.ts +++ b/src/controllers/api/accounts.ts @@ -1,4 +1,4 @@ -import { NostrFilter, NostrMetadata, NSchema as n } from '@nostrify/nostrify'; +import { NostrFilter, NSchema as n } from '@nostrify/nostrify'; import { nip19 } from 'nostr-tools'; import { z } from 'zod';