Skip to content

Commit ce55108

Browse files
authored
Add passthrough mode to /api/v1/moderate (#131)
1 parent cbd11d4 commit ce55108

File tree

19 files changed

+114
-54
lines changed

19 files changed

+114
-54
lines changed

app/api/v1/moderate/route.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ export async function POST(req: NextRequest) {
2929
);
3030
}
3131

32+
const passthrough = data.passthrough;
33+
3234
let userRecord: typeof schema.userRecords.$inferSelect | undefined;
3335
if (data.user) {
3436
userRecord = await createOrUpdateUserRecord({
3537
clerkOrganizationId,
3638
clientId: data.user.clientId,
3739
clientUrl: data.user.clientUrl,
38-
email: data.user.email,
39-
name: data.user.name,
40-
username: data.user.username,
4140
initialProtected: data.user.protected,
4241
stripeAccountId: data.user.stripeAccountId,
4342
metadata: data.user.metadata,
43+
...(passthrough ? {} : { email: data.user.email, name: data.user.name, username: data.user.username }),
4444
});
4545
}
4646

@@ -49,13 +49,13 @@ export async function POST(req: NextRequest) {
4949
const record = await createOrUpdateRecord({
5050
clerkOrganizationId,
5151
clientId: data.clientId,
52-
name: data.name,
5352
entity: data.entity,
54-
text: content.text,
55-
imageUrls: content.imageUrls,
5653
clientUrl: data.clientUrl,
5754
userRecordId: userRecord?.id,
5855
metadata: data.metadata,
56+
...(passthrough
57+
? {}
58+
: { name: data.name, text: content.text, imageUrls: content.imageUrls, externalUrls: content.externalUrls }),
5959
});
6060

6161
if (record.protected) {
@@ -71,6 +71,14 @@ export async function POST(req: NextRequest) {
7171
const result = await moderate({
7272
clerkOrganizationId,
7373
recordId: record.id,
74+
passthroughContext: passthrough
75+
? {
76+
name: data.name,
77+
text: content.text,
78+
imageUrls: content.imageUrls ?? [],
79+
externalUrls: content.externalUrls ?? [],
80+
}
81+
: undefined,
7482
});
7583

7684
const moderation = await createModeration({

app/api/v1/moderate/schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export const ModerateRequestData = z
3333
metadata: MetadataSchema.optional(),
3434
})
3535
.optional(),
36+
passthrough: z.boolean().optional().default(false),
3637
})
3738
.strict();
3839

app/appeal/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Separator } from "@/components/ui/separator";
1111
import { findOrCreateOrganization } from "@/services/organizations";
1212
import { formatRecordStatus, formatUserActionStatus } from "@/lib/badges";
1313
import { desc, eq, and, isNull } from "drizzle-orm";
14+
import { formatRecord } from "@/lib/record";
1415

1516
// Ensure page is never cached
1617
export const dynamic = "force-dynamic";
@@ -135,7 +136,7 @@ export default async function Page(props: { searchParams: Promise<{ [key: string
135136
return (
136137
<TableRow key={record.id}>
137138
<TableCell>
138-
<div className="font-medium">{record.name}</div>
139+
<div className="font-medium">{formatRecord(record)}</div>
139140
</TableCell>
140141
<TableCell className="hidden sm:table-cell">
141142
<Badge variant="secondary">

app/dashboard/@sheet/(.)records/[recordId]/moderations/[moderationId]/page.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { authWithOrgSubscription } from "@/app/dashboard/auth";
22
import { ModerationDetail } from "@/app/dashboard/records/[recordId]/moderations/[moderationId]/moderation";
3-
import { redirect, notFound } from "next/navigation";
3+
import { notFound } from "next/navigation";
44
import { RouterSheet } from "@/components/router-sheet";
55
import { Metadata } from "next";
66
import db from "@/db";
77
import * as schema from "@/db/schema";
88
import { and, eq } from "drizzle-orm";
9+
import { formatRecord } from "@/lib/record";
910

1011
export async function generateMetadata({ params }: { params: Promise<{ moderationId: string }> }): Promise<Metadata> {
1112
const { orgId } = await authWithOrgSubscription();
@@ -24,7 +25,7 @@ export async function generateMetadata({ params }: { params: Promise<{ moderatio
2425
}
2526

2627
return {
27-
title: `${moderation.record.name} | Moderation | Iffy`,
28+
title: `${formatRecord(moderation.record)} | Moderation | Iffy`,
2829
};
2930
}
3031

app/dashboard/@sheet/(.)records/[recordId]/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { and, eq } from "drizzle-orm";
77
import { notFound } from "next/navigation";
88
import { Metadata } from "next";
99
import { authWithOrgSubscription } from "@/app/dashboard/auth";
10+
import { formatRecord } from "@/lib/record";
1011

1112
export async function generateMetadata({ params }: { params: Promise<{ recordId: string }> }): Promise<Metadata> {
1213
const { orgId } = await authWithOrgSubscription();
@@ -22,7 +23,7 @@ export async function generateMetadata({ params }: { params: Promise<{ recordId:
2223
}
2324

2425
return {
25-
title: `Record ${record.name} (${record.entity}) | Iffy`,
26+
title: `Record ${formatRecord(record)} (${record.entity}) | Iffy`,
2627
};
2728
}
2829

app/dashboard/inbox/appeal.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import { createAppealAction } from "./actions";
4949
import { trpc } from "@/lib/trpc";
5050
import Link from "next/link";
5151
import { useToast } from "@/hooks/use-toast";
52+
import { formatRecord } from "@/lib/record";
5253

5354
function makeAppealTimeline(
5455
actions: AppealAction[],
@@ -92,7 +93,7 @@ const ModerationItem = ({ item }: { item: AppealTimelineModeration; userRecord:
9293
<div className="text-sm text-gray-950 dark:text-white/80">
9394
{item.data.record.entity}{" "}
9495
<Link href={`/dashboard/records/${item.data.record.id}`} className="font-bold">
95-
{item.data.record.name}
96+
{formatRecord(item.data.record)}
9697
</Link>{" "}
9798
marked {formatModerationStatus(item.data)} via {formatVia(item.data)}
9899
</div>

app/dashboard/records/[recordId]/moderations/[moderationId]/moderation.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import * as schema from "@/db/schema";
1111
import { eq, and } from "drizzle-orm";
1212
import db from "@/db";
1313
import { notFound } from "next/navigation";
14+
import { formatRecord } from "@/lib/record";
1415

1516
export async function ModerationDetail({ clerkOrganizationId, id }: { clerkOrganizationId: string; id: string }) {
1617
const moderation = await db.query.moderations.findFirst({
@@ -41,7 +42,7 @@ export async function ModerationDetail({ clerkOrganizationId, id }: { clerkOrgan
4142
<HeaderContent>
4243
<HeaderPrimary>
4344
<Link href={`/dashboard/records/${moderation.record.id}`} className="hover:underline">
44-
{moderation.record.name}
45+
{formatRecord(moderation.record)}
4546
</Link>
4647
</HeaderPrimary>
4748
<HeaderSecondary>{moderation.record.entity}</HeaderSecondary>

app/dashboard/records/[recordId]/moderations/[moderationId]/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { ModerationDetail } from "./moderation";
55
import db from "@/db";
66
import * as schema from "@/db/schema";
77
import { and, eq } from "drizzle-orm";
8+
import { formatRecord } from "@/lib/record";
89

910
export async function generateMetadata({ params }: { params: Promise<{ moderationId: string }> }): Promise<Metadata> {
1011
const { orgId } = await authWithOrgSubscription();
@@ -23,7 +24,7 @@ export async function generateMetadata({ params }: { params: Promise<{ moderatio
2324
}
2425

2526
return {
26-
title: `${moderation.record.name} | Moderation | Iffy`,
27+
title: `${formatRecord(moderation.record)} | Moderation | Iffy`,
2728
};
2829
}
2930

app/dashboard/records/[recordId]/page.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { notFound, redirect } from "next/navigation";
1+
import { notFound } from "next/navigation";
22
import { RecordDetail } from "./record";
33
import { authWithOrgSubscription } from "@/app/dashboard/auth";
44
import { Metadata } from "next";
55
import db from "@/db";
66
import * as schema from "@/db/schema";
77
import { and, eq } from "drizzle-orm";
8+
import { formatRecord } from "@/lib/record";
89

910
export async function generateMetadata({ params }: { params: Promise<{ recordId: string }> }): Promise<Metadata> {
1011
const { orgId } = await authWithOrgSubscription();
@@ -20,7 +21,7 @@ export async function generateMetadata({ params }: { params: Promise<{ recordId:
2021
}
2122

2223
return {
23-
title: `${record.name} (${record.entity}) | Iffy`,
24+
title: `${formatRecord(record)} (${record.entity}) | Iffy`,
2425
};
2526
}
2627

app/dashboard/records/[recordId]/record.tsx

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import * as schema from "@/db/schema";
2020
import { eq, desc, and } from "drizzle-orm";
2121
import db from "@/db";
2222
import { parseMetadata } from "@/services/metadata";
23+
import { formatRecord } from "@/lib/record";
2324

2425
export async function RecordDetail({ clerkOrganizationId, id }: { clerkOrganizationId: string; id: string }) {
2526
const record = await db.query.records.findFirst({
@@ -53,7 +54,7 @@ export async function RecordDetail({ clerkOrganizationId, id }: { clerkOrganizat
5354
<div>
5455
<Header>
5556
<HeaderContent>
56-
<HeaderPrimary className={cn(record.deletedAt && "line-through")}>{record.name}</HeaderPrimary>
57+
<HeaderPrimary className={cn(record.deletedAt && "line-through")}>{formatRecord(record)}</HeaderPrimary>
5758
<HeaderSecondary>{record.entity}</HeaderSecondary>
5859
</HeaderContent>
5960
<HeaderActions className="flex items-center gap-4">
@@ -188,29 +189,33 @@ export async function RecordDetail({ clerkOrganizationId, id }: { clerkOrganizat
188189
</>
189190
)}
190191
<Separator className="my-2" />
191-
<Section>
192-
<SectionTitle>Content</SectionTitle>
193-
<SectionContent className="grid gap-3">
194-
<dl className="grid gap-3">
195-
{record.externalUrls && record.externalUrls.length > 0 && (
196-
<div className="grid grid-cols-2 gap-4">
197-
<dt className="text-stone-500 dark:text-zinc-500">External Links</dt>
198-
<dd>
199-
{record.externalUrls.map((url, index) => (
200-
<Button key={index} asChild variant="link" className="text-md -mx-4 -my-2 font-normal">
201-
<Link href={url} target="_blank" rel="noopener noreferrer">
202-
{formatLink(url)} <ExternalLink className="h-4 w-4" />
203-
</Link>
204-
</Button>
205-
))}
206-
</dd>
207-
</div>
208-
)}
209-
</dl>
210-
<Code>{record.text}</Code>
211-
{record.imageUrls.length > 0 ? <RecordImages imageUrls={record.imageUrls} /> : null}
212-
</SectionContent>
213-
</Section>
192+
{record.externalUrls.length > 0 ||
193+
record.text ||
194+
(record.imageUrls.length > 0 && (
195+
<Section>
196+
<SectionTitle>Content</SectionTitle>
197+
<SectionContent className="grid gap-3">
198+
<dl className="grid gap-3">
199+
{record.externalUrls.length > 0 && (
200+
<div className="grid grid-cols-2 gap-4">
201+
<dt className="text-stone-500 dark:text-zinc-500">External Links</dt>
202+
<dd>
203+
{record.externalUrls.map((url, index) => (
204+
<Button key={index} asChild variant="link" className="text-md -mx-4 -my-2 font-normal">
205+
<Link href={url} target="_blank" rel="noopener noreferrer">
206+
{formatLink(url)} <ExternalLink className="h-4 w-4" />
207+
</Link>
208+
</Button>
209+
))}
210+
</dd>
211+
</div>
212+
)}
213+
</dl>
214+
{record.text && <Code>{record.text}</Code>}
215+
{record.imageUrls.length > 0 ? <RecordImages imageUrls={record.imageUrls} /> : null}
216+
</SectionContent>
217+
</Section>
218+
))}
214219
{record.moderations.length > 0 && (
215220
<>
216221
<Separator className="my-2" />

0 commit comments

Comments
 (0)