From a2c5b5e61d048a22e55ae8237f78edb53a4ffc1d Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 3 May 2024 16:20:07 -0500 Subject: [PATCH] Markers: only allow 'home' and 'notifications' markers --- src/controllers/api/markers.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/controllers/api/markers.ts b/src/controllers/api/markers.ts index cd90e33..ce1c4ec 100644 --- a/src/controllers/api/markers.ts +++ b/src/controllers/api/markers.ts @@ -5,6 +5,8 @@ import { parseBody } from '@/utils/api.ts'; const kv = await Deno.openKv(); +type Timeline = 'home' | 'notifications'; + interface Marker { last_read_id: string; version: number; @@ -36,8 +38,8 @@ const markerDataSchema = z.object({ export const updateMarkersController: AppController = async (c) => { const pubkey = c.get('pubkey')!; - const record = z.record(z.string(), markerDataSchema).parse(await parseBody(c.req.raw)); - const timelines = Object.keys(record); + const record = z.record(z.enum(['home', 'notifications']), markerDataSchema).parse(await parseBody(c.req.raw)); + const timelines = Object.keys(record) as Timeline[]; const markers: Record = {}; @@ -49,7 +51,7 @@ export const updateMarkersController: AppController = async (c) => { const last = entries.find(({ key }) => key[key.length - 1] === timeline); const marker: Marker = { - last_read_id: record[timeline].last_read_id, + last_read_id: record[timeline]!.last_read_id, version: last?.value ? last.value.version + 1 : 1, updated_at: new Date().toISOString(), };