diff --git a/src/app.ts b/src/app.ts index ef7c88b..853e1a0 100644 --- a/src/app.ts +++ b/src/app.ts @@ -57,6 +57,7 @@ import { bookmarkController, contextController, createStatusController, + deleteStatusController, favouriteController, favouritedByController, pinController, @@ -167,6 +168,7 @@ app.post('/api/v1/statuses/:id{[0-9a-f]{64}}/pin', requirePubkey, pinController) app.post('/api/v1/statuses/:id{[0-9a-f]{64}}/unpin', requirePubkey, unpinController); app.post('/api/v1/statuses/:id{[0-9a-f]{64}}/zap', requirePubkey, zapController); app.post('/api/v1/statuses', requirePubkey, createStatusController); +app.delete('/api/v1/statuses/:id{[0-9a-f]{64}}', requirePubkey, deleteStatusController); app.post('/api/v1/media', requireRole('user', { validatePayload: false }), mediaController); app.post('/api/v2/media', requireRole('user', { validatePayload: false }), mediaController); diff --git a/src/controllers/api/statuses.ts b/src/controllers/api/statuses.ts index 2d85985..0b4216e 100644 --- a/src/controllers/api/statuses.ts +++ b/src/controllers/api/statuses.ts @@ -96,6 +96,29 @@ const createStatusController: AppController = async (c) => { return c.json(await renderStatus({ ...event, author }, c.get('pubkey'))); }; +const deleteStatusController: AppController = async (c) => { + const id = c.req.param('id'); + const pubkey = c.get('pubkey'); + + const event = await getEvent(id, { signal: c.req.raw.signal }); + + if (event) { + if (event.pubkey === pubkey) { + await createEvent({ + kind: 5, + tags: [['e', id]], + }, c); + + const author = await getAuthor(event.pubkey); + return c.json(await renderStatus({ ...event, author }, pubkey)); + } else { + return c.json({ error: 'Unauthorized' }, 403); + } + } + + return c.json({ error: 'Event not found.' }, 404); +}; + const contextController: AppController = async (c) => { const id = c.req.param('id'); const event = await getEvent(id, { kind: 1, relations: ['author', 'event_stats', 'author_stats'] }); @@ -312,6 +335,7 @@ export { bookmarkController, contextController, createStatusController, + deleteStatusController, favouriteController, favouritedByController, pinController,