import Link from "next/link"; import { Clock3, FileImage, Film, HardDrive, Image as ImageIcon, Play, } from "lucide-react"; import { auth } from "@/auth/config"; import { hasPermission } from "@/auth/permissions"; import type { SystemRole } from "@/auth/roles"; import { listEventsForUser } from "@/db/events"; import { listMediaPhotosForEvents } from "@/db/media"; import { listEventVideosForEvents } from "@/db/videos"; import { getStorageSettings } from "@/db/storage-settings"; import { mediaStorage } from "@/lib/media-storage"; import { formatVideoDuration } from "@/lib/event-videos"; import { isBrowserRenderablePhoto } from "@/lib/event-photos"; import { mediaOrigin } from "@/lib/media-url"; import { CHURCH_TIMEZONE, formatInTimezone } from "@/lib/tz"; import { videoView } from "@/lib/video-view"; import { Badge } from "@/components/ui/badge"; import { StateMessage } from "@/components/app/state-message"; import { VideoUploadForm } from "@/components/app/media/video-upload-form"; export const metadata = { title: "Media" }; export const dynamic = "force-dynamic"; function day(date: Date): string { return formatInTimezone(date, CHURCH_TIMEZONE, { timeZone: CHURCH_TIMEZONE, month: "short", day: "numeric", year: "numeric", }); } function bytesLabel(bytes: number): string { if (bytes < 1024 * 1024) return `${Math.round(bytes / 1024)} KB`; if (bytes < 1024 * 1024 * 1024) { return `${(bytes / (1024 * 1024)).toFixed(1)} MB`; } return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`; } /** * The media library: every event photo and video the signed-in user can open. * Photos remain protected by event access; video cards link to the watch/editor * page where managers can publish an unlisted/public version. */ export default async function MediaPage() { const session = await auth(); const user = session?.user as | { id?: string; systemRole?: SystemRole } | undefined; const role = user?.systemRole; const events = await listEventsForUser(user?.id ?? "", role); const eventIds = events.map((event) => event.id); const origin = await mediaOrigin(); const [videos, photos, storage] = await Promise.all([ listEventVideosForEvents(eventIds), listMediaPhotosForEvents(eventIds), getStorageSettings(), ]); const archiveStatus = await mediaStorage(); const archiveUsedBytes = archiveStatus.ok && archiveStatus.totalBytes !== null && archiveStatus.freeBytes !== null ? Math.max(0, archiveStatus.totalBytes - archiveStatus.freeBytes) : null; const archiveUsedPercent = archiveUsedBytes !== null && archiveStatus.ok && archiveStatus.totalBytes ? Math.min(100, Math.round((archiveUsedBytes / archiveStatus.totalBytes) * 100)) : null; const canManage = hasPermission(role, "schedule.publish"); const videoCards = videos.map((video) => videoView(video, origin)); return (

Media

An ad-free library of every event photo and video you can access. Videos stay private to the team until a manager publishes an unlisted or public version.

{archiveStatus.ok && (

{archiveStatus.settings.nfsShare} ·{" "} {archiveStatus.settings.archiveFolder}

{archiveUsedBytes !== null && archiveStatus.totalBytes !== null ? ( <>

{bytesLabel(archiveUsedBytes)} used of{" "} {bytesLabel(archiveStatus.totalBytes)} ·{" "} {bytesLabel(archiveStatus.freeBytes ?? 0)} free

) : (

Free space could not be read from this filesystem.

)} {archiveStatus.mount && (

Filesystem {archiveStatus.mount.fileSystem} on{" "} {archiveStatus.mount.mountPoint}

)}
)}

Camera originals are stored on the media storage share; playback uses a generated MP4.

{videoCards.length} video{videoCards.length === 1 ? "" : "s"}
({ id: event.id, title: event.title, }))} canManage={canManage} archiveReady={archiveStatus.ok} /> {videoCards.length === 0 ? ( ) : (
{videoCards.map((video) => (
{video.posterUrl && video.status !== "failed" ? ( // eslint-disable-next-line @next/next/no-img-element ) : (
)} {formatVideoDuration(video.durationMs)} {(video.status !== "ready" || video.isShareable) && (
{video.status !== "ready" && ( {video.status === "failed" ? "Failed" : "Processing"} )} {video.isShareable && ( {video.visibility} )}
)}

{video.title}

{video.eventTitle} · {day(new Date(video.eventStartsAt))}

{bytesLabel(video.sizeBytes)} original

))}
)}

Every photo in the events you can open. Download originals from the event page.

{photos.length} photo{photos.length === 1 ? "" : "s"}
{photos.length === 0 ? ( ) : (
{photos.map((photo) => { const previewable = Boolean(photo.editedAt) || isBrowserRenderablePhoto(photo.filename); const version = photo.editedAt ? Date.parse(photo.editedAt.toISOString()) : 0; const src = `/api/events/${photo.eventId}/folders/${photo.folderId}/photos/${photo.id}${ photo.editedAt ? `?variant=edited&v=${version}` : "" }`; return (
{previewable ? ( // eslint-disable-next-line @next/next/no-img-element {photo.filename} ) : ( )}

{photo.filename}

{photo.eventTitle}

{bytesLabel(photo.sizeBytes)}

); })}
)}

); }