reportsController -> reportController

This commit is contained in:
Alex Gleason 2024-05-08 14:59:30 -05:00
parent ccf126516d
commit f99958c40e
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
3 changed files with 9 additions and 9 deletions

View File

@ -48,7 +48,7 @@ import {
adminReportController,
adminReportResolveController,
adminReportsController,
reportsController,
reportController,
} from '@/controllers/api/reports.ts';
import { searchController } from '@/controllers/api/search.ts';
import {
@ -212,7 +212,7 @@ app.delete('/api/v1/pleroma/admin/statuses/:id', requireRole('admin'), pleromaAd
app.get('/api/v1/admin/ditto/relays', requireRole('admin'), adminRelaysController);
app.put('/api/v1/admin/ditto/relays', requireRole('admin'), adminSetRelaysController);
app.post('/api/v1/reports', requirePubkey, reportsController);
app.post('/api/v1/reports', requirePubkey, reportController);
app.get('/api/v1/admin/reports', requirePubkey, requireRole('admin'), adminReportsController);
app.get('/api/v1/admin/reports/:id{[0-9a-f]{64}}', requirePubkey, requireRole('admin'), adminReportController);
app.post(

View File

@ -8,7 +8,7 @@ import { hydrateEvents } from '@/storages/hydrate.ts';
import { renderAdminReport } from '@/views/mastodon/reports.ts';
import { renderReport } from '@/views/mastodon/reports.ts';
const reportsSchema = z.object({
const reportSchema = z.object({
account_id: n.id(),
status_ids: n.id().array().default([]),
comment: z.string().max(1000).default(''),
@ -17,10 +17,10 @@ const reportsSchema = z.object({
});
/** https://docs.joinmastodon.org/methods/reports/#post */
const reportsController: AppController = async (c) => {
const reportController: AppController = async (c) => {
const store = c.get('store');
const body = await parseBody(c.req.raw);
const result = reportsSchema.safeParse(body);
const result = reportSchema.safeParse(body);
if (!result.success) {
return c.json(result.error, 422);
@ -116,4 +116,4 @@ const adminReportResolveController: AppController = async (c) => {
return c.json(await renderAdminReport(event, { viewerPubkey: pubkey, action_taken: true }));
};
export { adminReportController, adminReportResolveController, adminReportsController, reportsController };
export { adminReportController, adminReportResolveController, adminReportsController, reportController };

View File

@ -30,14 +30,14 @@ async function renderReport(reportEvent: DittoEvent, profile: DittoEvent) {
interface RenderAdminReportOpts {
viewerPubkey?: string;
action_taken?: boolean;
actionTaken?: boolean;
}
/** Admin-level information about a filed report.
* Expects an event of kind 1984 fully hydrated.
* https://docs.joinmastodon.org/entities/Admin_Report */
async function renderAdminReport(reportEvent: DittoEvent, opts: RenderAdminReportOpts) {
const { viewerPubkey, action_taken = false } = opts;
const { viewerPubkey, actionTaken = false } = opts;
// The category is present in both the 'e' and 'p' tag, however, it is possible to report a user without reporting a note, so it's better to get the category from the 'p' tag
const category = reportEvent.tags.find(([name]) => name === 'p')?.[2];
@ -51,7 +51,7 @@ async function renderAdminReport(reportEvent: DittoEvent, opts: RenderAdminRepor
return {
id: reportEvent.id,
action_taken,
action_taken: actionTaken,
action_taken_at: null,
category,
comment: reportEvent.content,