diff --git a/messages/de.json b/messages/de.json index 58d2e65..58c991d 100644 --- a/messages/de.json +++ b/messages/de.json @@ -127,6 +127,14 @@ "Theme": { "toggleLabel": "Dark Mode" }, + "AiDisclosure": { + "question": "Enthält dieser Inhalt KI-generierte oder KI-bearbeitete Bilder/Texte?", + "none": "Nein", + "modified": "KI-bearbeitet", + "generated": "KI-generiert", + "modifiedBadgeAlt": "Mit KI bearbeitet", + "generatedBadgeAlt": "Mit KI generiert" + }, "Invite": { "title": "Freunde einladen", "subtitle": "Du hast {available} von {total} Einladungen verfügbar. Teile einen Link — jeder Code kann nur einmal verwendet werden.", diff --git a/messages/en.json b/messages/en.json index 12162a5..8a8691b 100644 --- a/messages/en.json +++ b/messages/en.json @@ -127,6 +127,14 @@ "Theme": { "toggleLabel": "Dark Mode" }, + "AiDisclosure": { + "question": "Does this content include AI-generated or AI-modified images/text?", + "none": "No", + "modified": "AI-modified", + "generated": "AI-generated", + "modifiedBadgeAlt": "AI-modified", + "generatedBadgeAlt": "AI-generated" + }, "Invite": { "title": "Invite friends", "subtitle": "You have {available} of {total} invites available. Share a link — each code can only be used once.", diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 5ab07c0..856a81a 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -185,6 +185,11 @@ model Pet { verificationRequests VerificationRequest[] + // Gitea #18 — legal AI-content disclosure. Set once at avatar upload, + // owner-immutable afterward; only a moderator can correct it (see + // admin.setAiDisclosure). Overlay-badge only, never baked into pixels. + aiDisclosure AiDisclosure @default(NONE) + @@index([ownerId]) @@index([speciesId]) @@index([breedId]) @@ -198,6 +203,13 @@ enum DmPolicy { FOLLOWERS_ONLY // only pets that this pet follows can send a DM } +// Gitea #18 — legal AI-content disclosure, shared across Post/Story/Pet. +enum AiDisclosure { + NONE + AI_MODIFIED + AI_GENERATED +} + // ─── Phase 2 Enums ─────────────────────────────────────────────────────────── enum PostType { @@ -268,6 +280,10 @@ model Post { commentCount Int @default(0) repostCount Int @default(0) + // Gitea #18 — legal AI-content disclosure, set once at creation, owner- + // immutable afterward. See admin.setAiDisclosure for moderator correction. + aiDisclosure AiDisclosure @default(NONE) + // Phase 3 back-relations reactions Reaction[] @relation("PostReactions") comments Comment[] @relation("PostComments") @@ -316,6 +332,9 @@ model Story { views StoryView[] createdAt DateTime @default(now()) + // Gitea #18 — legal AI-content disclosure, set once at creation. + aiDisclosure AiDisclosure @default(NONE) + @@index([petId, expiresAt]) // supports lazy-delete filter query } @@ -742,7 +761,7 @@ model AdRepost { model ModerationLog { id String @id @default(cuid()) - action String @db.VarChar(50) // DELETE_POST | DELETE_COMMENT | BAN_USER | UNBAN_USER | DELETE_IMAGE | DISMISS_REPORT | CREATE_AD | UPDATE_AD | DELETE_AD | GRANT_ROLE | REVOKE_ROLE | WARN_USER | VERIFY_PET | UNVERIFY_PET | DELETE_ACCOUNT | APPROVE_VERIFICATION_REQUEST | REJECT_VERIFICATION_REQUEST | HIDE_POST | UNHIDE_POST | SHADOWBAN_USER | UNSHADOWBAN_USER + action String @db.VarChar(50) // DELETE_POST | DELETE_COMMENT | BAN_USER | UNBAN_USER | DELETE_IMAGE | DISMISS_REPORT | CREATE_AD | UPDATE_AD | DELETE_AD | GRANT_ROLE | REVOKE_ROLE | WARN_USER | VERIFY_PET | UNVERIFY_PET | DELETE_ACCOUNT | APPROVE_VERIFICATION_REQUEST | REJECT_VERIFICATION_REQUEST | HIDE_POST | UNHIDE_POST | SHADOWBAN_USER | UNSHADOWBAN_USER | SET_AI_DISCLOSURE targetType String @db.VarChar(20) // POST | COMMENT | USER | IMAGE | AD | REPORT | PET targetId String reason String? @db.VarChar(500) diff --git a/public/badges/ai-generated.png b/public/badges/ai-generated.png new file mode 100644 index 0000000..4c2f82f Binary files /dev/null and b/public/badges/ai-generated.png differ diff --git a/public/badges/ai-modified.png b/public/badges/ai-modified.png new file mode 100644 index 0000000..c667e0c Binary files /dev/null and b/public/badges/ai-modified.png differ diff --git a/src/__tests__/admin.test.ts b/src/__tests__/admin.test.ts index 0e27cbd..ea538b0 100644 --- a/src/__tests__/admin.test.ts +++ b/src/__tests__/admin.test.ts @@ -481,3 +481,67 @@ describe("admin.getActiveAds", () => { await expect(caller.admin.getActiveAds({ petId: "pet-dog-1" })).resolves.toEqual([adUnfiltered]); }); }); + +// Gitea #18 — legal AI-content disclosure moderator correction. +describe("admin.setAiDisclosure", () => { + it("wraps the post update + moderation log write in a transaction, requiring a reason", async () => { + vi.stubEnv("ADMIN_OWNER_ID", "admin-1"); + const { caller, mockPrisma } = await createAdminCaller(); + mockPrisma.post.findUnique.mockResolvedValue({ id: "post-1" }); + mockPrisma.post.update.mockResolvedValue({ id: "post-1", aiDisclosure: "AI_GENERATED" }); + mockPrisma.moderationLog.create.mockResolvedValue({ id: "log-1" }); + + const result = await caller.admin.setAiDisclosure({ + postId: "post-1", + aiDisclosure: "AI_GENERATED", + reason: "Owner forgot to disclose", + }); + + expect(mockPrisma.$transaction).toHaveBeenCalledWith(expect.any(Array)); + expect(mockPrisma.post.update).toHaveBeenCalledWith({ + where: { id: "post-1" }, + data: { aiDisclosure: "AI_GENERATED" }, + }); + expect(mockPrisma.moderationLog.create).toHaveBeenCalledWith( + expect.objectContaining({ + data: expect.objectContaining({ + action: "SET_AI_DISCLOSURE", + targetType: "POST", + targetId: "post-1", + reason: "Owner forgot to disclose", + }), + }) + ); + expect(result).toEqual({ success: true }); + }); + + it("rejects an empty reason", async () => { + vi.stubEnv("ADMIN_OWNER_ID", "admin-1"); + const { caller } = await createAdminCaller(); + + await expect( + caller.admin.setAiDisclosure({ postId: "post-1", aiDisclosure: "NONE", reason: "" }) + ).rejects.toThrow(); + }); + + it("throws FORBIDDEN for a non-admin caller", async () => { + vi.stubEnv("ADMIN_OWNER_ID", "someone-else"); + const { caller, mockPrisma } = await createAdminCaller(); + mockPrisma.adminRole.findUnique.mockResolvedValue(null); + + await expect( + caller.admin.setAiDisclosure({ postId: "post-1", aiDisclosure: "NONE", reason: "test" }) + ).rejects.toThrow(TRPCError); + expect(mockPrisma.post.update).not.toHaveBeenCalled(); + }); + + it("throws NOT_FOUND when the post doesn't exist", async () => { + vi.stubEnv("ADMIN_OWNER_ID", "admin-1"); + const { caller, mockPrisma } = await createAdminCaller(); + mockPrisma.post.findUnique.mockResolvedValue(null); + + await expect( + caller.admin.setAiDisclosure({ postId: "missing", aiDisclosure: "NONE", reason: "test" }) + ).rejects.toThrow(TRPCError); + }); +}); diff --git a/src/__tests__/media-upload.test.ts b/src/__tests__/media-upload.test.ts index 39dfe4b..2084c23 100644 --- a/src/__tests__/media-upload.test.ts +++ b/src/__tests__/media-upload.test.ts @@ -197,7 +197,7 @@ describe("media.confirmUpload", () => { // Assert DB update was called with the correct avatarKey expect(mockPrisma.pet.update).toHaveBeenCalledWith({ where: { id: PET_ID }, - data: { avatarKey: AVATAR_KEY }, + data: { avatarKey: AVATAR_KEY, aiDisclosure: "NONE" }, }); // Assert return value contains the avatarKey diff --git a/src/app/(app)/pets/[petId]/page.tsx b/src/app/(app)/pets/[petId]/page.tsx index 73a315d..14344af 100644 --- a/src/app/(app)/pets/[petId]/page.tsx +++ b/src/app/(app)/pets/[petId]/page.tsx @@ -66,6 +66,7 @@ export default async function PetProfilePage({ params }: PageProps) { avatarUrl={pet.avatarKey ? getAvatarUrl(pet.avatarKey) : null} petName={pet.name} initials={getInitials(pet.name)} + aiDisclosure={pet.aiDisclosure} />

diff --git a/src/app/p/[secret]/posts/page.tsx b/src/app/p/[secret]/posts/page.tsx index f06cbf1..c7293f3 100644 --- a/src/app/p/[secret]/posts/page.tsx +++ b/src/app/p/[secret]/posts/page.tsx @@ -3,7 +3,7 @@ import { useEffect, useState } from "react"; import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { useTRPC } from "@/trpc/client"; -import { Trash2, MessageSquare, Loader2, ChevronDown, Play, ImageOff, PawPrint, EyeOff, Eye } from "lucide-react"; +import { Trash2, MessageSquare, Loader2, ChevronDown, Play, ImageOff, PawPrint, EyeOff, Eye, Sparkles } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from "@/components/ui/dialog"; @@ -11,6 +11,8 @@ import { getMediaUrl } from "@/lib/media-url"; import { BlurImage } from "@/components/ui/blur-image"; import { MILESTONE_META } from "@/lib/milestone-meta"; import { cn } from "@/lib/utils"; +import { AiDisclosureBadge } from "@/components/content/AiDisclosureBadge"; +import { AiDisclosureSelect, type AiDisclosureValue } from "@/components/content/AiDisclosureSelect"; const GRID_SIZES = [3, 5, 8] as const; type GridSize = (typeof GRID_SIZES)[number]; @@ -48,6 +50,9 @@ export default function AdminPostsPage() { const [hideTargetId, setHideTargetId] = useState(null); const [reason, setReason] = useState(""); const [hideReason, setHideReason] = useState(""); + const [aiTargetId, setAiTargetId] = useState(null); + const [aiValue, setAiValue] = useState("NONE"); + const [aiReason, setAiReason] = useState(""); const { data, fetchNextPage, hasNextPage, isFetchingNextPage, isLoading } = useInfiniteQuery( trpc.admin.listPosts.infiniteQueryOptions( @@ -105,11 +110,26 @@ export default function AdminPostsPage() { }) ); + const setAiDisclosure = useMutation( + trpc.admin.setAiDisclosure.mutationOptions({ + onSuccess: () => { + void qc.invalidateQueries({ queryKey: trpc.admin.listPosts.queryKey() }); + setAiTargetId(null); + setAiReason(""); + }, + }) + ); + function confirmHide() { if (!hideTargetId || !hideReason.trim()) return; hidePost.mutate({ postId: hideTargetId, reason: hideReason.trim() }); } + function confirmAiDisclosure() { + if (!aiTargetId || !aiReason.trim()) return; + setAiDisclosure.mutate({ postId: aiTargetId, aiDisclosure: aiValue, reason: aiReason.trim() }); + } + function confirmDelete() { if (!deleteTarget) return; if (deleteTarget.type === "post") { @@ -213,6 +233,7 @@ export default function AdminPostsPage() { )} +
@@ -262,6 +283,18 @@ export default function AdminPostsPage() { )} + + + + +
); } diff --git a/src/components/content/AiDisclosureBadge.tsx b/src/components/content/AiDisclosureBadge.tsx new file mode 100644 index 0000000..411852f --- /dev/null +++ b/src/components/content/AiDisclosureBadge.tsx @@ -0,0 +1,36 @@ +"use client"; + +import { useTranslations } from "next-intl"; +import { cn } from "@/lib/utils"; +import type { AiDisclosureValue } from "@/components/content/AiDisclosureSelect"; + +interface AiDisclosureBadgeProps { + value: AiDisclosureValue | null | undefined; + className?: string; +} + +const BADGE_SRC: Partial> = { + AI_MODIFIED: "/badges/ai-modified.png", + AI_GENERATED: "/badges/ai-generated.png", +}; + +// Overlay-only disclosure badge (Gitea #18) — renders nothing for NONE. +// Plain , not next/image: fixed small decorative asset, no responsive +// srcset needed. Default position (top-2 left-2) avoids the top-right +// corner already used by index indicators / play icons in feed cards. +export function AiDisclosureBadge({ value, className }: AiDisclosureBadgeProps) { + const t = useTranslations("AiDisclosure"); + + if (!value || value === "NONE") return null; + + const src = BADGE_SRC[value]; + if (!src) return null; + + return ( + {value + ); +} diff --git a/src/components/content/AiDisclosureSelect.tsx b/src/components/content/AiDisclosureSelect.tsx new file mode 100644 index 0000000..6aad88c --- /dev/null +++ b/src/components/content/AiDisclosureSelect.tsx @@ -0,0 +1,51 @@ +"use client"; + +import { useTranslations } from "next-intl"; +import { cn } from "@/lib/utils"; + +export type AiDisclosureValue = "NONE" | "AI_MODIFIED" | "AI_GENERATED"; + +interface AiDisclosureSelectProps { + value: AiDisclosureValue; + onChange: (value: AiDisclosureValue) => void; + className?: string; +} + +const OPTIONS: { value: AiDisclosureValue; labelKey: "none" | "modified" | "generated" }[] = [ + { value: "NONE", labelKey: "none" }, + { value: "AI_MODIFIED", labelKey: "modified" }, + { value: "AI_GENERATED", labelKey: "generated" }, +]; + +// Legal AI-content disclosure (Gitea #18) — exclusive 3-way choice, owner +// cannot change it after creation (see admin.setAiDisclosure for the only +// other write path). Segmented-control styling; no base-ui primitive +// wrapped here since this is the only 3-way selector in the app. +export function AiDisclosureSelect({ value, onChange, className }: AiDisclosureSelectProps) { + const t = useTranslations("AiDisclosure"); + + return ( +
+

{t("question")}

+
+ {OPTIONS.map((opt) => ( + + ))} +
+
+ ); +} diff --git a/src/components/feed/MilestoneCard.tsx b/src/components/feed/MilestoneCard.tsx index 5f8181b..11eb462 100644 --- a/src/components/feed/MilestoneCard.tsx +++ b/src/components/feed/MilestoneCard.tsx @@ -6,11 +6,14 @@ import { getAvatarUrl } from "@/lib/avatar-url"; import { getMediaUrl } from "@/lib/media-url"; import { BlurImage } from "@/components/ui/blur-image"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; +import { AiDisclosureBadge } from "@/components/content/AiDisclosureBadge"; +import type { AiDisclosureValue } from "@/components/content/AiDisclosureSelect"; type MilestoneCardPost = { id: string; caption: string | null; createdAt: Date | string; + aiDisclosure?: AiDisclosureValue; pet: { id: string; name: string; avatarKey: string | null }; images: { id: string; storageKey: string; position: number; blurhash?: string | null }[]; milestone: { milestoneType: MilestoneType; notes: string | null } | null; @@ -71,13 +74,14 @@ export function MilestoneCard({ post }: MilestoneCardProps) { {/* Optional photo */} {photo && ( -
+
+
)} diff --git a/src/components/feed/PostCard.tsx b/src/components/feed/PostCard.tsx index a89388d..fba22a8 100644 --- a/src/components/feed/PostCard.tsx +++ b/src/components/feed/PostCard.tsx @@ -48,6 +48,8 @@ import { PostDetailDialog } from "@/components/feed/PostDetailDialog"; import { RepostCard } from "@/components/feed/RepostCard"; import { BlockDialog } from "@/components/safety/BlockDialog"; import { ReportSheet } from "@/components/safety/ReportSheet"; +import { AiDisclosureBadge } from "@/components/content/AiDisclosureBadge"; +import type { AiDisclosureValue } from "@/components/content/AiDisclosureSelect"; import { useTranslations } from "next-intl"; /** @@ -93,6 +95,7 @@ export type PostCardPost = { id: string; type?: string | null; caption: string | null; + aiDisclosure?: AiDisclosureValue; createdAt: Date | string; pet: PostPet; images: PostImage[]; @@ -300,11 +303,14 @@ function PostCardImpl({ post, onDeleted, variant = "feed" }: PostCardProps) { {/* Video area — VIDEO posts */} {post.type === "VIDEO" && post.videoPost && ( - +
+ + +
)} {/* Image area — PHOTO posts */} @@ -336,6 +342,8 @@ function PostCardImpl({ post, onDeleted, variant = "feed" }: PostCardProps) { {currentSlide} / {images.length} + + {/* Dot indicators — bg-muted inactive / bg-foreground active (NOT orange — accent reservation) */}
{images.map((_, i) => ( @@ -354,13 +362,16 @@ function PostCardImpl({ post, onDeleted, variant = "feed" }: PostCardProps) {
) : ( /* Single image */ - setShowDetailDialog(true)} - /> +
+ setShowDetailDialog(true)} + /> + +
)} )} diff --git a/src/components/feed/PostDetailDialog.tsx b/src/components/feed/PostDetailDialog.tsx index fc8dbbc..c4d95cb 100644 --- a/src/components/feed/PostDetailDialog.tsx +++ b/src/components/feed/PostDetailDialog.tsx @@ -49,6 +49,7 @@ import type { PostCardPost } from "@/components/feed/PostCard"; import { useTranslations } from "next-intl"; import { BlockDialog } from "@/components/safety/BlockDialog"; import { ReportSheet } from "@/components/safety/ReportSheet"; +import { AiDisclosureBadge } from "@/components/content/AiDisclosureBadge"; interface PostDetailDialogProps { post: PostCardPost | null; @@ -309,8 +310,9 @@ export function PostDetailDialog({ post, open, onClose, onDeleted }: PostDetailD
{/* Image column — fixed 45dvh strip on mobile, flex-1 full-height on desktop */} -
+
{mediaContent} +
{/* Right panel: desktop header + scrollable body + sticky input */} diff --git a/src/components/pet/AvatarCropDialog.tsx b/src/components/pet/AvatarCropDialog.tsx index 3d8a8dd..8eda45a 100644 --- a/src/components/pet/AvatarCropDialog.tsx +++ b/src/components/pet/AvatarCropDialog.tsx @@ -12,12 +12,13 @@ import { } from "@/components/ui/dialog"; import { Button } from "@/components/ui/button"; import { getCroppedImageBlob } from "@/lib/crop-image"; +import { AiDisclosureSelect, type AiDisclosureValue } from "@/components/content/AiDisclosureSelect"; interface AvatarCropDialogProps { imageSrc: string; mimeType: string; onCancel: () => void; - onCropped: (blob: Blob) => void; + onCropped: (blob: Blob, aiDisclosure: AiDisclosureValue) => void; } /** @@ -36,6 +37,7 @@ export function AvatarCropDialog({ const [zoom, setZoom] = useState(1); const [cropAreaPixels, setCropAreaPixels] = useState(null); const [isProcessing, setIsProcessing] = useState(false); + const [aiDisclosure, setAiDisclosure] = useState("NONE"); const handleCropComplete = useCallback((_area: Area, areaPixels: Area) => { setCropAreaPixels(areaPixels); @@ -46,11 +48,11 @@ export function AvatarCropDialog({ setIsProcessing(true); try { const blob = await getCroppedImageBlob(imageSrc, cropAreaPixels, mimeType); - onCropped(blob); + onCropped(blob, aiDisclosure); } finally { setIsProcessing(false); } - }, [cropAreaPixels, imageSrc, mimeType, onCropped]); + }, [cropAreaPixels, imageSrc, mimeType, aiDisclosure, onCropped]); return (
+ + {avatarUrl && ( diff --git a/src/components/post-creation/MilestoneForm.tsx b/src/components/post-creation/MilestoneForm.tsx index 7403b3c..d31880c 100644 --- a/src/components/post-creation/MilestoneForm.tsx +++ b/src/components/post-creation/MilestoneForm.tsx @@ -18,6 +18,7 @@ import { } from "@/components/ui/popover"; import { MILESTONE_META, USER_INITIATED_MILESTONE_TYPES } from "@/lib/milestone-meta"; import { computeBlurhash } from "@/lib/blurhash"; +import { AiDisclosureSelect, type AiDisclosureValue } from "@/components/content/AiDisclosureSelect"; const ALLOWED_TYPES = ["image/jpeg", "image/png", "image/webp"] as const; type AllowedContentType = (typeof ALLOWED_TYPES)[number]; @@ -51,6 +52,7 @@ export function MilestoneForm({ onClose }: MilestoneFormProps) { >(null); const [notes, setNotes] = useState(""); const [caption, setCaption] = useState(""); + const [aiDisclosure, setAiDisclosure] = useState("NONE"); const [uploadState, setUploadState] = useState("idle"); const [uploadProgress, setUploadProgress] = useState(0); @@ -147,10 +149,11 @@ export function MilestoneForm({ onClose }: MilestoneFormProps) { milestoneType: selectedType, notes: selectedType === MilestoneType.LITTER ? notes.trim() || undefined : undefined, caption: caption.trim() || undefined, + aiDisclosure: uploadedKey ? aiDisclosure : "NONE", imageKey: uploadedKey ?? undefined, imageBlurhash: uploadedBlurhash, }); - }, [activePetId, selectedType, notes, caption, uploadedKey, uploadedBlurhash, createMutation]); + }, [activePetId, selectedType, notes, caption, aiDisclosure, uploadedKey, uploadedBlurhash, createMutation]); const selectedMeta = selectedType ? MILESTONE_META[selectedType] : null; @@ -266,6 +269,10 @@ export function MilestoneForm({ onClose }: MilestoneFormProps) { {uploadError &&

{uploadError}

} + {previewUrl && uploadedKey && ( + + )} + {/* Optional caption */}