feat: implement view single report

This commit is contained in:
P. Reis 2024-05-07 10:19:08 -03:00
parent 120003c5c8
commit 17706d3b20
2 changed files with 26 additions and 3 deletions

View File

@ -44,7 +44,7 @@ import {
} from '@/controllers/api/pleroma.ts';
import { preferencesController } from '@/controllers/api/preferences.ts';
import { relayController } from '@/controllers/nostr/relay.ts';
import { adminReportsController, reportsController } from '@/controllers/api/reports.ts';
import { adminReportsController, reportsController, singleAdminReportsController } from '@/controllers/api/reports.ts';
import { searchController } from '@/controllers/api/search.ts';
import {
bookmarkController,
@ -209,6 +209,7 @@ app.put('/api/v1/admin/ditto/relays', requireRole('admin'), adminSetRelaysContro
app.post('/api/v1/reports', requirePubkey, reportsController);
app.get('/api/v1/admin/reports', requirePubkey, requireRole('admin'), adminReportsController);
app.get('/api/v1/admin/reports/:id', requirePubkey, requireRole('admin'), singleAdminReportsController);
// Not (yet) implemented.
app.get('/api/v1/custom_emojis', emptyArrayController);

View File

@ -16,7 +16,7 @@ const reportsSchema = z.object({
// TODO: rules_ids[] is not implemented
});
/** https://docs.joinmastodon.org/methods/reports/ */
/** https://docs.joinmastodon.org/methods/reports/#post */
const reportsController: AppController = async (c) => {
const store = c.get('store');
const body = await parseBody(c.req.raw);
@ -66,4 +66,26 @@ const adminReportsController: AppController = async (c) => {
return c.json(reports);
};
export { adminReportsController, reportsController };
/** https://docs.joinmastodon.org/methods/admin/reports/#get-one */
const singleAdminReportsController: AppController = async (c) => {
const eventId = c.req.param('id');
const { signal } = c.req.raw;
const store = c.get('store');
const pubkey = c.get('pubkey');
const [event] = await store.query([{
kinds: [1984],
ids: [eventId],
limit: 1,
}], { signal });
if (!event) {
return c.json({ error: 'This action is not allowed' }, 403);
}
await hydrateEvents({ events: [event], storage: store, signal });
return c.json(await renderAdminReport(event, { viewerPubkey: pubkey }));
};
export { adminReportsController, reportsController, singleAdminReportsController };