push to maple-street
This commit is contained in:
@@ -0,0 +1,263 @@
|
||||
import Link from "next/link";
|
||||
import {
|
||||
Clock3,
|
||||
FileImage,
|
||||
Film,
|
||||
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 {
|
||||
checkArchiveDestination,
|
||||
getStorageSettings,
|
||||
} from "@/db/storage-settings";
|
||||
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 checkArchiveDestination(storage);
|
||||
const canManage = hasPermission(role, "schedule.publish");
|
||||
const videoCards = videos.map((video) => videoView(video, origin));
|
||||
|
||||
return (
|
||||
<div className="space-y-8">
|
||||
<div>
|
||||
<h1 className="text-lg font-semibold tracking-tight">Media</h1>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
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.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<section className="space-y-3">
|
||||
<div className="flex flex-wrap items-end justify-between gap-2">
|
||||
<div>
|
||||
<h2 className="flex items-center gap-2 text-base font-semibold">
|
||||
<Film className="h-4 w-4" aria-hidden="true" />
|
||||
Videos
|
||||
</h2>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Camera originals live on the NFS archive; playback uses a generated
|
||||
MP4.
|
||||
</p>
|
||||
</div>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{videoCards.length} video{videoCards.length === 1 ? "" : "s"}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<VideoUploadForm
|
||||
events={events.map((event) => ({
|
||||
id: event.id,
|
||||
title: event.title,
|
||||
}))}
|
||||
canManage={canManage}
|
||||
archiveReady={archiveStatus.ready}
|
||||
/>
|
||||
|
||||
{videoCards.length === 0 ? (
|
||||
<StateMessage
|
||||
title="No videos yet"
|
||||
description="Upload a service recap, testimony, or event clip from an event you can access."
|
||||
/>
|
||||
) : (
|
||||
<div className="grid gap-4 sm:grid-cols-2 xl:grid-cols-3">
|
||||
{videoCards.map((video) => (
|
||||
<Link
|
||||
key={video.id}
|
||||
href={`/media/${video.id}`}
|
||||
className="group overflow-hidden rounded-lg border border-border bg-background transition-colors hover:border-primary/60"
|
||||
>
|
||||
<div className="relative aspect-video bg-black">
|
||||
{video.posterUrl && video.status !== "failed" ? (
|
||||
// eslint-disable-next-line @next/next/no-img-element
|
||||
<img
|
||||
src={video.posterUrl}
|
||||
alt=""
|
||||
loading="lazy"
|
||||
className="h-full w-full object-cover opacity-90 transition-opacity group-hover:opacity-100"
|
||||
/>
|
||||
) : (
|
||||
<div className="flex h-full items-center justify-center text-white/50">
|
||||
<Film className="h-10 w-10" aria-hidden="true" />
|
||||
</div>
|
||||
)}
|
||||
<span className="absolute bottom-2 right-2 rounded bg-black/75 px-1.5 py-0.5 font-mono text-[11px] text-white">
|
||||
{formatVideoDuration(video.durationMs)}
|
||||
</span>
|
||||
{(video.status !== "ready" || video.isShareable) && (
|
||||
<div className="absolute left-2 top-2 flex flex-wrap gap-1">
|
||||
{video.status !== "ready" && (
|
||||
<Badge variant="secondary">
|
||||
{video.status === "failed" ? "Failed" : "Processing"}
|
||||
</Badge>
|
||||
)}
|
||||
{video.isShareable && (
|
||||
<Badge variant="outline" className="bg-background/90">
|
||||
{video.visibility}
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<span className="absolute inset-0 flex items-center justify-center opacity-0 transition-opacity group-hover:opacity-100">
|
||||
<span className="flex h-12 w-12 items-center justify-center rounded-full bg-black/70 text-white">
|
||||
<Play className="h-5 w-5 fill-current" aria-hidden="true" />
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
<div className="space-y-1 p-3">
|
||||
<h3 className="line-clamp-2 text-sm font-semibold">
|
||||
{video.title}
|
||||
</h3>
|
||||
<p className="truncate text-xs text-muted-foreground">
|
||||
{video.eventTitle} · {day(new Date(video.eventStartsAt))}
|
||||
</p>
|
||||
<p className="text-[11px] text-muted-foreground">
|
||||
{bytesLabel(video.sizeBytes)} original
|
||||
</p>
|
||||
</div>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
|
||||
<section className="space-y-3">
|
||||
<div className="flex flex-wrap items-end justify-between gap-2">
|
||||
<div>
|
||||
<h2 className="flex items-center gap-2 text-base font-semibold">
|
||||
<ImageIcon className="h-4 w-4" aria-hidden="true" />
|
||||
Photos
|
||||
</h2>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Every photo in the event folders you can open. Download originals
|
||||
from the event folder.
|
||||
</p>
|
||||
</div>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{photos.length} photo{photos.length === 1 ? "" : "s"}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{photos.length === 0 ? (
|
||||
<StateMessage
|
||||
title="No photos yet"
|
||||
description="When photographers upload to an event you are assigned to, the frames appear here."
|
||||
/>
|
||||
) : (
|
||||
<div className="grid grid-cols-2 gap-3 sm:grid-cols-3 xl:grid-cols-5">
|
||||
{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 (
|
||||
<Link
|
||||
key={photo.id}
|
||||
href={`/events/${photo.eventId}/folders/${photo.folderId}`}
|
||||
className="group overflow-hidden rounded-md border border-border bg-background transition-colors hover:border-primary/60"
|
||||
>
|
||||
<div className="flex aspect-square items-center justify-center bg-muted/40">
|
||||
{previewable ? (
|
||||
// eslint-disable-next-line @next/next/no-img-element
|
||||
<img
|
||||
src={src}
|
||||
alt={photo.filename}
|
||||
loading="lazy"
|
||||
decoding="async"
|
||||
className="h-full w-full object-cover"
|
||||
/>
|
||||
) : (
|
||||
<span className="flex flex-col items-center gap-1 text-muted-foreground">
|
||||
<FileImage className="h-8 w-8" aria-hidden="true" />
|
||||
<span className="text-[11px] font-medium">
|
||||
{photo.filename.split(".").pop()?.toUpperCase() ??
|
||||
"FILE"}
|
||||
</span>
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="space-y-0.5 p-2">
|
||||
<p className="truncate text-xs font-medium" title={photo.filename}>
|
||||
{photo.filename}
|
||||
</p>
|
||||
<p className="truncate text-[11px] text-muted-foreground">
|
||||
{photo.eventTitle} · {photo.folderName}
|
||||
</p>
|
||||
<p className="text-[10px] text-muted-foreground">
|
||||
{bytesLabel(photo.sizeBytes)}
|
||||
</p>
|
||||
</div>
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
|
||||
<p className="flex items-center gap-1.5 text-xs text-muted-foreground">
|
||||
<Clock3 className="h-3.5 w-3.5" aria-hidden="true" />
|
||||
Video originals are kept under{" "}
|
||||
<span className="font-mono">
|
||||
{storage.archivePath}/{storage.archiveFolder}/videos/
|
||||
</span>
|
||||
.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user