feat(legal): AI-content disclosure for user uploads (Gitea #18)

Owners can now optionally mark uploaded content as AI_MODIFIED or
AI_GENERATED (mutually exclusive, defaults to NONE) across every upload
surface — photo posts, video posts, milestones, stories, and pet avatars.
Once set, the choice is owner-immutable; only a moderator can correct it
via a new admin.setAiDisclosure mutation (Posts admin page), which
requires a reason and writes to ModerationLog like every other
moderation action.

The disclosure renders as a UI-only overlay badge (the two provided
label assets) wherever the content is shown — feed, post detail, story
viewer, milestone cards, and the pet profile avatar — never baked into
the image pixels.

New shared components: AiDisclosureSelect (the 3-way picker used in all
five upload forms) and AiDisclosureBadge (the overlay renderer).
This commit is contained in:
admin committed 2026-08-13 13:44:16 +02:00
1 parent 2d0e390c76
commit 50e2848312
28 files changed
+389 -32

No files matched your search

+8
View File
@@ -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.",
+8
View File
@@ -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.",
+20 -1
View File
@@ -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)
Binary file not shown.

After

Width:  |  Height:  |  Size: 144 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 KiB

+64
View File
@@ -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);
});
});
+1 -1
View File
@@ -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
+1
View File
@@ -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}
/>
<h1 className="flex items-center gap-1.5 text-xl font-semibold text-center">
+69 -1
View File
@@ -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<string | null>(null);
const [reason, setReason] = useState("");
const [hideReason, setHideReason] = useState("");
const [aiTargetId, setAiTargetId] = useState<string | null>(null);
const [aiValue, setAiValue] = useState<AiDisclosureValue>("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() {
</span>
</div>
)}
<AiDisclosureBadge value={post.aiDisclosure} />
</div>
<div className="flex flex-1 flex-col gap-2 p-3">
@@ -262,6 +283,18 @@ export default function AdminPostsPage() {
<EyeOff className="h-4 w-4" />
</Button>
)}
<Button
size="sm"
variant="ghost"
className="text-zinc-400 hover:text-zinc-100"
onClick={() => {
setAiTargetId(post.id);
setAiValue(post.aiDisclosure ?? "NONE");
setAiReason("");
}}
>
<Sparkles className="h-4 w-4" />
</Button>
<Button
size="sm"
variant="ghost"
@@ -403,6 +436,41 @@ export default function AdminPostsPage() {
</DialogFooter>
</DialogContent>
</Dialog>
{/* AI-disclosure correction dialog */}
<Dialog
open={!!aiTargetId}
onOpenChange={(o) => { if (!o) { setAiTargetId(null); setAiReason(""); } }}
>
<DialogContent className="bg-zinc-900 border-zinc-800 text-zinc-100 max-w-sm">
<DialogHeader>
<DialogTitle>Correct AI-content disclosure</DialogTitle>
</DialogHeader>
<p className="text-sm text-zinc-400">
Owners cannot change this after posting — use this only to correct a forgotten
or incorrect disclosure. Requires a reason for the audit log.
</p>
<AiDisclosureSelect value={aiValue} onChange={setAiValue} />
<Input
placeholder="Reason (required)"
value={aiReason}
onChange={(e) => setAiReason(e.target.value)}
className="bg-zinc-800 border-zinc-700 text-zinc-100 placeholder:text-zinc-500"
/>
<DialogFooter className="gap-2">
<Button variant="ghost" className="text-zinc-400" onClick={() => setAiTargetId(null)}>
Cancel
</Button>
<Button
onClick={confirmAiDisclosure}
disabled={setAiDisclosure.isPending || !aiReason.trim()}
>
{setAiDisclosure.isPending && <Loader2 className="h-4 w-4 animate-spin mr-2" />}
Save
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</div>
);
}
@@ -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<Record<AiDisclosureValue, string>> = {
AI_MODIFIED: "/badges/ai-modified.png",
AI_GENERATED: "/badges/ai-generated.png",
};
// Overlay-only disclosure badge (Gitea #18) — renders nothing for NONE.
// Plain <img>, 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 (
<img
src={src}
alt={value === "AI_GENERATED" ? t("generatedBadgeAlt") : t("modifiedBadgeAlt")}
className={cn("absolute top-2 left-2 h-5 w-auto select-none pointer-events-none", className)}
/>
);
}
@@ -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 (
<div className={cn("space-y-1.5", className)}>
<p className="text-xs text-muted-foreground">{t("question")}</p>
<div className="inline-flex rounded-lg border border-border p-0.5" role="radiogroup" aria-label={t("question")}>
{OPTIONS.map((opt) => (
<button
key={opt.value}
type="button"
role="radio"
aria-checked={value === opt.value}
onClick={() => onChange(opt.value)}
className={cn(
"rounded-[calc(var(--radius-lg)-2px)] px-2.5 py-1 text-xs font-medium transition-colors",
value === opt.value
? "bg-primary text-primary-foreground"
: "text-muted-foreground hover:bg-muted hover:text-foreground"
)}
>
{t(opt.labelKey)}
</button>
))}
</div>
</div>
);
}
+5 -1
View File
@@ -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 && (
<div className="w-full">
<div className="relative w-full">
<BlurImage
src={getMediaUrl(photo.storageKey) ?? ""}
blurhash={photo.blurhash}
alt={caption ?? `${pet.name}'s milestone`}
className="w-full object-cover max-h-[400px]"
/>
<AiDisclosureBadge value={post.aiDisclosure} />
</div>
)}
+23 -12
View File
@@ -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 && (
<VideoCard
postId={post.id}
initialStatus={post.videoPost.status}
initialPlaybackId={post.videoPost.muxPlaybackId}
/>
<div className="relative">
<VideoCard
postId={post.id}
initialStatus={post.videoPost.status}
initialPlaybackId={post.videoPost.muxPlaybackId}
/>
<AiDisclosureBadge value={post.aiDisclosure} />
</div>
)}
{/* Image area — PHOTO posts */}
@@ -336,6 +342,8 @@ function PostCardImpl({ post, onDeleted, variant = "feed" }: PostCardProps) {
{currentSlide} / {images.length}
</span>
<AiDisclosureBadge value={post.aiDisclosure} />
{/* Dot indicators — bg-muted inactive / bg-foreground active (NOT orange — accent reservation) */}
<div className="flex items-center justify-center gap-2 py-2">
{images.map((_, i) => (
@@ -354,13 +362,16 @@ function PostCardImpl({ post, onDeleted, variant = "feed" }: PostCardProps) {
</div>
) : (
/* Single image */
<BlurImage
src={getMediaUrl(images[0].storageKey) ?? ""}
blurhash={images[0].blurhash}
alt={currentCaption ?? `${pet.name}'s post`}
className="w-full object-cover max-h-[560px] cursor-pointer"
onClick={() => setShowDetailDialog(true)}
/>
<div className="relative">
<BlurImage
src={getMediaUrl(images[0].storageKey) ?? ""}
blurhash={images[0].blurhash}
alt={currentCaption ?? `${pet.name}'s post`}
className="w-full object-cover max-h-[560px] cursor-pointer"
onClick={() => setShowDetailDialog(true)}
/>
<AiDisclosureBadge value={post.aiDisclosure} />
</div>
)}
</>
)}
+3 -1
View File
@@ -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
</div>
{/* Image column — fixed 45dvh strip on mobile, flex-1 full-height on desktop */}
<div className="shrink-0 h-[45dvh] md:h-full md:flex-1 md:min-w-0 bg-black flex items-center justify-center">
<div className="relative shrink-0 h-[45dvh] md:h-full md:flex-1 md:min-w-0 bg-black flex items-center justify-center">
{mediaContent}
<AiDisclosureBadge value={post.aiDisclosure} />
</div>
{/* Right panel: desktop header + scrollable body + sticky input */}
+7 -3
View File
@@ -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<Area | null>(null);
const [isProcessing, setIsProcessing] = useState(false);
const [aiDisclosure, setAiDisclosure] = useState<AiDisclosureValue>("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 (
<Dialog
@@ -92,6 +94,8 @@ export function AvatarCropDialog({
/>
</div>
<AiDisclosureSelect value={aiDisclosure} onChange={setAiDisclosure} className="px-1" />
<DialogFooter>
<Button type="button" variant="outline" onClick={onCancel} disabled={isProcessing}>
{t("cropCancel")}
+5 -4
View File
@@ -10,6 +10,7 @@ import { Avatar, AvatarImage, AvatarFallback } from "@/components/ui/avatar";
import { Progress } from "@/components/ui/progress";
import { uploadFileWithProgress } from "@/lib/upload-xhr";
import { AvatarCropDialog } from "@/components/pet/AvatarCropDialog";
import type { AiDisclosureValue } from "@/components/content/AiDisclosureSelect";
/**
* AvatarUpload — five-state upload zone for pet avatars.
@@ -84,7 +85,7 @@ export function AvatarUpload({
}, []);
const uploadFile = useCallback(
async (file: File) => {
async (file: File, aiDisclosure: AiDisclosureValue) => {
// Type-narrowing guard — selectFile() already gates on petId before the
// crop dialog ever opens, so this only protects the TS type of petId.
if (!petId) {
@@ -113,7 +114,7 @@ export function AvatarUpload({
});
// Step 3: Confirm upload — write avatarKey to Pet DB row
await confirmUploadMutation.mutateAsync({ petId, key });
await confirmUploadMutation.mutateAsync({ petId, key, aiDisclosure });
// Step 4: Show CDN avatar URL immediately (no page reload needed)
const cdnUrl = `${process.env.NEXT_PUBLIC_SUPABASE_URL}/storage/v1/object/public/pet-avatars/${key}`;
@@ -165,14 +166,14 @@ export function AvatarUpload({
}, [pendingCrop]);
const handleCropped = useCallback(
(blob: Blob) => {
(blob: Blob, aiDisclosure: AiDisclosureValue) => {
if (!pendingCrop) return;
const croppedFile = new File([blob], pendingCrop.file.name, {
type: pendingCrop.file.type,
});
URL.revokeObjectURL(pendingCrop.objectUrl);
setPendingCrop(null);
void uploadFile(croppedFile);
void uploadFile(croppedFile, aiDisclosure);
},
[pendingCrop, uploadFile]
);
+7 -3
View File
@@ -3,11 +3,14 @@
import { useState } from "react";
import { Avatar, AvatarImage, AvatarFallback } from "@/components/ui/avatar";
import { Dialog, DialogContent } from "@/components/ui/dialog";
import { AiDisclosureBadge } from "@/components/content/AiDisclosureBadge";
import type { AiDisclosureValue } from "@/components/content/AiDisclosureSelect";
interface PetAvatarZoomProps {
avatarUrl: string | null;
petName: string;
initials: string;
aiDisclosure?: AiDisclosureValue;
}
/**
@@ -15,7 +18,7 @@ interface PetAvatarZoomProps {
* Reuses DialogContent's built-in zoom-in-95 + fade entrance animation for
* the lightbox transition rather than hand-rolling a new one.
*/
export function PetAvatarZoom({ avatarUrl, petName, initials }: PetAvatarZoomProps) {
export function PetAvatarZoom({ avatarUrl, petName, initials, aiDisclosure }: PetAvatarZoomProps) {
const [open, setOpen] = useState(false);
return (
@@ -27,14 +30,15 @@ export function PetAvatarZoom({ avatarUrl, petName, initials }: PetAvatarZoomPro
aria-label={avatarUrl ? `${petName}'s profile photo, tap to zoom` : undefined}
className={
avatarUrl
? "rounded-full transition-transform duration-150 hover:scale-105 active:scale-100 cursor-zoom-in"
: "cursor-default"
? "relative rounded-full transition-transform duration-150 hover:scale-105 active:scale-100 cursor-zoom-in"
: "relative cursor-default"
}
>
<Avatar className="w-32 h-32 text-2xl">
{avatarUrl && <AvatarImage src={avatarUrl} alt={petName} />}
<AvatarFallback className="text-2xl font-semibold">{initials}</AvatarFallback>
</Avatar>
<AiDisclosureBadge value={aiDisclosure} className="top-auto -bottom-1 left-1/2 -translate-x-1/2" />
</button>
{avatarUrl && (
@@ -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<AiDisclosureValue>("NONE");
const [uploadState, setUploadState] = useState<UploadState>("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 && <p className="text-xs text-destructive">{uploadError}</p>}
</div>
{previewUrl && uploadedKey && (
<AiDisclosureSelect value={aiDisclosure} onChange={setAiDisclosure} />
)}
{/* Optional caption */}
<div className="space-y-1.5">
<label className="text-sm font-medium text-foreground">
@@ -10,6 +10,7 @@ import { useActivePet } from "@/context/ActivePetContext";
import { Button } from "@/components/ui/button";
import { MentionTextarea } from "@/components/ui/mention-textarea";
import { MultiImageUpload } from "@/components/post-creation/MultiImageUpload";
import { AiDisclosureSelect, type AiDisclosureValue } from "@/components/content/AiDisclosureSelect";
/**
* PhotoPostForm — multi-image upload + caption form for creating photo posts.
@@ -47,6 +48,7 @@ export function PhotoPostForm({ onClose }: PhotoPostFormProps) {
const [images, setImages] = useState<{ key: string; blurhash: string | null }[]>([]);
const [caption, setCaption] = useState("");
const [captionError, setCaptionError] = useState<string | null>(null);
const [aiDisclosure, setAiDisclosure] = useState<AiDisclosureValue>("NONE");
const createMutation = useMutation(
trpc.posts.create.mutationOptions({
@@ -83,9 +85,10 @@ export function PhotoPostForm({ onClose }: PhotoPostFormProps) {
createMutation.mutate({
petId: activePetId,
caption: caption.trim() || null,
aiDisclosure,
images,
});
}, [activePetId, images, caption, createMutation, t]);
}, [activePetId, images, caption, aiDisclosure, createMutation, t]);
if (!activePetId) {
return (
@@ -103,6 +106,8 @@ export function PhotoPostForm({ onClose }: PhotoPostFormProps) {
onImagesChange={setImages}
/>
<AiDisclosureSelect value={aiDisclosure} onChange={setAiDisclosure} />
{/* Caption textarea */}
<div className="space-y-1">
<MentionTextarea
+8 -1
View File
@@ -10,6 +10,7 @@ import { useActivePet } from "@/context/ActivePetContext";
import { Button } from "@/components/ui/button";
import { Progress } from "@/components/ui/progress";
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];
@@ -43,6 +44,7 @@ export function StoryForm({ onClose }: StoryFormProps) {
const [uploadedKey, setUploadedKey] = useState<string | null>(null);
const [uploadedBlurhash, setUploadedBlurhash] = useState<string | null>(null);
const [errorMessage, setErrorMessage] = useState<string | null>(null);
const [aiDisclosure, setAiDisclosure] = useState<AiDisclosureValue>("NONE");
const getPresignedUrlMutation = useMutation(
trpc.stories.getPresignedUrl.mutationOptions()
@@ -142,8 +144,9 @@ export function StoryForm({ onClose }: StoryFormProps) {
petId: activePetId,
storageKey: uploadedKey,
blurhash: uploadedBlurhash,
aiDisclosure,
});
}, [activePetId, uploadedKey, uploadedBlurhash, createStoryMutation]);
}, [activePetId, uploadedKey, uploadedBlurhash, aiDisclosure, createStoryMutation]);
return (
<div className="px-4 pb-6 space-y-5">
@@ -218,6 +221,10 @@ export function StoryForm({ onClose }: StoryFormProps) {
<p className="text-xs text-destructive">{errorMessage}</p>
)}
{uploadState === "ready" && (
<AiDisclosureSelect value={aiDisclosure} onChange={setAiDisclosure} />
)}
<p className="text-xs text-muted-foreground text-center">
{t("disappearsNote")}
</p>
+6
View File
@@ -16,6 +16,7 @@ import {
import { getAvatarUrl } from "@/lib/avatar-url";
import { getMediaUrl } from "@/lib/media-url";
import { BlurImage } from "@/components/ui/blur-image";
import { AiDisclosureBadge } from "@/components/content/AiDisclosureBadge";
interface StoryViewerProps {
petId: string;
@@ -164,6 +165,11 @@ export function StoryViewer({
/>
)}
<AiDisclosureBadge
value={currentStory.aiDisclosure}
className="top-auto left-auto bottom-6 right-4"
/>
{/* Pet info — bottom left */}
<div className="absolute bottom-6 left-4 flex items-center gap-2">
<Avatar className="w-8 h-8 border border-white/50">
+7 -1
View File
@@ -11,6 +11,7 @@ import { uploadFileWithProgress } from "@/lib/upload-xhr";
import { Button } from "@/components/ui/button";
import { Textarea } from "@/components/ui/textarea";
import { Label } from "@/components/ui/label";
import { AiDisclosureSelect, type AiDisclosureValue } from "@/components/content/AiDisclosureSelect";
const ACCEPTED_TYPES = ["video/mp4", "video/quicktime", "video/webm"];
const MAX_FILE_SIZE = 500 * 1024 * 1024; // 500 MB
@@ -30,6 +31,7 @@ export function VideoUploadForm({ onClose }: VideoUploadFormProps) {
const [file, setFile] = useState<File | null>(null);
const [previewUrl, setPreviewUrl] = useState<string | null>(null);
const [caption, setCaption] = useState("");
const [aiDisclosure, setAiDisclosure] = useState<AiDisclosureValue>("NONE");
const [uploadState, setUploadState] = useState<UploadState>("idle");
const [uploadProgress, setUploadProgress] = useState(0);
@@ -79,6 +81,7 @@ export function VideoUploadForm({ onClose }: VideoUploadFormProps) {
const { uploadUrl } = await createUploadMutation.mutateAsync({
petId: activePetId,
caption: caption.trim() || null,
aiDisclosure,
});
// PUT file directly to Mux upload URL, tracking progress
@@ -96,7 +99,7 @@ export function VideoUploadForm({ onClose }: VideoUploadFormProps) {
setUploadState("error");
toast.error(t("uploadFailedToast", { msg }));
}
}, [file, activePetId, caption, createUploadMutation, onClose, t]);
}, [file, activePetId, caption, aiDisclosure, createUploadMutation, onClose, t]);
return (
<div className="p-4 space-y-4">
@@ -150,6 +153,9 @@ export function VideoUploadForm({ onClose }: VideoUploadFormProps) {
</button>
)}
{/* AI-disclosure */}
{file && <AiDisclosureSelect value={aiDisclosure} onChange={setAiDisclosure} />}
{/* Caption */}
{file && (
<div className="space-y-1.5">
+36
View File
@@ -428,6 +428,42 @@ export const adminRouter = router({
return { success: true };
}),
// Gitea #18 — legal AI-content disclosure correction. Owners cannot change
// their own aiDisclosure choice after posting; this is the only other
// write path, always requiring a reason for the audit trail.
setAiDisclosure: protectedProcedure
.input(
z.object({
postId: z.string().min(1),
aiDisclosure: z.enum(["NONE", "AI_MODIFIED", "AI_GENERATED"]),
reason: z.string().min(1).max(500),
})
)
.mutation(async ({ ctx, input }) => {
const callerRole = await assertAdmin(ctx.prisma, ctx.userId, AdminRoleType.MODERATOR);
const post = await ctx.prisma.post.findUnique({ where: { id: input.postId } });
if (!post) throw new TRPCError({ code: "NOT_FOUND" });
await ctx.prisma.$transaction([
ctx.prisma.post.update({
where: { id: input.postId },
data: { aiDisclosure: input.aiDisclosure },
}),
ctx.prisma.moderationLog.create({
data: {
action: "SET_AI_DISCLOSURE",
targetType: "POST",
targetId: input.postId,
reason: input.reason,
moderatorId: ctx.userId,
moderatorRole: callerRole,
ipAddress: ctx.ip,
},
}),
]);
return { success: true };
}),
// ─── Blacklist (Gitea #10 Phase 3) ────────────────────────────────────────────
listBlacklist: protectedProcedure
.input(z.object({ type: z.nativeEnum(BlacklistEntryType).optional() }))
+2 -1
View File
@@ -59,6 +59,7 @@ export const mediaRouter = router({
z.object({
petId: z.string(),
key: z.string().startsWith("avatars/"),
aiDisclosure: z.enum(["NONE", "AI_MODIFIED", "AI_GENERATED"]).default("NONE"),
})
)
.mutation(async ({ ctx, input }) => {
@@ -67,7 +68,7 @@ export const mediaRouter = router({
const updated = await ctx.prisma.pet.update({
where: { id: input.petId },
data: { avatarKey: input.key },
data: { avatarKey: input.key, aiDisclosure: input.aiDisclosure },
});
return { avatarKey: updated.avatarKey };
+2
View File
@@ -29,6 +29,7 @@ export const milestonesRouter = router({
milestoneType: z.enum(USER_INITIATED_MILESTONE_TYPES),
notes: z.string().max(500).optional(),
caption: z.string().max(500).optional(),
aiDisclosure: z.enum(["NONE", "AI_MODIFIED", "AI_GENERATED"]).default("NONE"),
imageKey: z.string().startsWith("posts/").optional(),
imageBlurhash: z.string().max(100).nullable().optional(),
})
@@ -41,6 +42,7 @@ export const milestonesRouter = router({
petId: input.petId,
type: "MILESTONE",
caption: input.caption ?? null,
aiDisclosure: input.aiDisclosure,
milestone: {
create: {
milestoneType: input.milestoneType,
+2
View File
@@ -96,6 +96,7 @@ export const postsRouter = router({
z.object({
petId: z.string().min(1),
caption: z.string().max(500).nullable().optional(),
aiDisclosure: z.enum(["NONE", "AI_MODIFIED", "AI_GENERATED"]).default("NONE"),
images: z
.array(
z.object({
@@ -117,6 +118,7 @@ export const postsRouter = router({
petId: input.petId,
type: "PHOTO",
caption: input.caption ?? null,
aiDisclosure: input.aiDisclosure,
images: {
create: input.images.map((img, position) => ({
storageKey: img.key,
+2
View File
@@ -53,6 +53,7 @@ export const storiesRouter = router({
petId: z.string().min(1),
storageKey: z.string().startsWith("stories/"),
blurhash: z.string().max(100).nullable().optional(),
aiDisclosure: z.enum(["NONE", "AI_MODIFIED", "AI_GENERATED"]).default("NONE"),
})
)
.mutation(async ({ ctx, input }) => {
@@ -66,6 +67,7 @@ export const storiesRouter = router({
petId: input.petId,
storageKey: input.storageKey,
blurhash: input.blurhash ?? null,
aiDisclosure: input.aiDisclosure,
expiresAt,
},
});
+2
View File
@@ -18,6 +18,7 @@ export const videosRouter = router({
z.object({
petId: z.string().min(1),
caption: z.string().max(500).nullable().optional(),
aiDisclosure: z.enum(["NONE", "AI_MODIFIED", "AI_GENERATED"]).default("NONE"),
})
)
.mutation(async ({ ctx, input }) => {
@@ -49,6 +50,7 @@ export const videosRouter = router({
petId: input.petId,
type: "VIDEO",
caption: input.caption ?? null,
aiDisclosure: input.aiDisclosure,
videoPost: {
create: {
muxUploadId: upload.id,