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 (
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.
Original media storage
{archiveStatus.settings.nfsShare} ·{" "} {archiveStatus.settings.archiveFolder}
{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.
{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.
{photo.filename}
{photo.eventTitle}
{bytesLabel(photo.sizeBytes)}
Video originals are kept under{" "} {storage.archivePath}/{storage.archiveFolder}/videos/ .