DELETE /api/v1/statuses/:id

This commit is contained in:
Alex Gleason 2024-03-30 13:34:18 -05:00
parent 02af0cf06d
commit 2a032b7b7b
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 26 additions and 0 deletions

View File

@ -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);

View File

@ -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,