feat: create /api/v1/admin/reports endpoint & controller
This commit is contained in:
parent
b57188943f
commit
af7b83cf8a
|
@ -43,7 +43,7 @@ import {
|
||||||
} from '@/controllers/api/pleroma.ts';
|
} from '@/controllers/api/pleroma.ts';
|
||||||
import { preferencesController } from '@/controllers/api/preferences.ts';
|
import { preferencesController } from '@/controllers/api/preferences.ts';
|
||||||
import { relayController } from '@/controllers/nostr/relay.ts';
|
import { relayController } from '@/controllers/nostr/relay.ts';
|
||||||
import { reportsController } from '@/controllers/api/reports.ts';
|
import { reportsController, viewAllReportsController } from '@/controllers/api/reports.ts';
|
||||||
import { searchController } from '@/controllers/api/search.ts';
|
import { searchController } from '@/controllers/api/search.ts';
|
||||||
import {
|
import {
|
||||||
bookmarkController,
|
bookmarkController,
|
||||||
|
@ -200,6 +200,7 @@ app.get('/api/v1/admin/ditto/relays', requireRole('admin'), adminRelaysControlle
|
||||||
app.put('/api/v1/admin/ditto/relays', requireRole('admin'), adminSetRelaysController);
|
app.put('/api/v1/admin/ditto/relays', requireRole('admin'), adminSetRelaysController);
|
||||||
|
|
||||||
app.post('/api/v1/reports', requirePubkey, reportsController);
|
app.post('/api/v1/reports', requirePubkey, reportsController);
|
||||||
|
app.get('/api/v1/admin/reports', requirePubkey, requireRole('admin'), viewAllReportsController);
|
||||||
|
|
||||||
// Not (yet) implemented.
|
// Not (yet) implemented.
|
||||||
app.get('/api/v1/custom_emojis', emptyArrayController);
|
app.get('/api/v1/custom_emojis', emptyArrayController);
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { hydrateEvents } from '@/storages/hydrate.ts';
|
||||||
import { NSchema as n } from '@nostrify/nostrify';
|
import { NSchema as n } from '@nostrify/nostrify';
|
||||||
import { renderReport } from '@/views/mastodon/reports.ts';
|
import { renderReport } from '@/views/mastodon/reports.ts';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
import { renderAdminReport } from '@/views/mastodon/reports.ts';
|
||||||
|
|
||||||
const reportsSchema = z.object({
|
const reportsSchema = z.object({
|
||||||
account_id: n.id(),
|
account_id: n.id(),
|
||||||
|
@ -50,4 +51,20 @@ const reportsController: AppController = async (c) => {
|
||||||
return c.json(await renderReport(event, profile));
|
return c.json(await renderReport(event, profile));
|
||||||
};
|
};
|
||||||
|
|
||||||
export { reportsController };
|
/** https://docs.joinmastodon.org/methods/admin/reports/#get */
|
||||||
|
const viewAllReportsController: AppController = async (c) => {
|
||||||
|
const store = c.get('store');
|
||||||
|
const allMastodonReports = [];
|
||||||
|
|
||||||
|
const allReports = await store.query([{ kinds: [1984], '#P': [Conf.pubkey] }]);
|
||||||
|
|
||||||
|
await hydrateEvents({ storage: store, events: allReports, signal: AbortSignal.timeout(2000) });
|
||||||
|
|
||||||
|
for (const report of allReports) {
|
||||||
|
allMastodonReports.push(await renderAdminReport(report, { viewerPubkey: c.get('pubkey') }));
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.json(allMastodonReports);
|
||||||
|
};
|
||||||
|
|
||||||
|
export { reportsController, viewAllReportsController };
|
||||||
|
|
Loading…
Reference in New Issue