forked from Github/frigate
Save exports to database (#11040)
* Save review thumbs in dedicated folder * Create exports table * Save exports to DB and save thumbnail for export * Save full frame always * Fix rounded corners * Save exports that are in progress * No need to remove spaces * Reorganize apis to use IDs * Use new apis for frontend * Get video playback working * Fix deleting and renaming * Import existing exports to DB * Implement downloading * Formatting
This commit is contained in:
@@ -1,38 +1,36 @@
|
||||
import { baseUrl } from "@/api/baseUrl";
|
||||
import ActivityIndicator from "../indicators/activity-indicator";
|
||||
import { LuPencil, LuTrash } from "react-icons/lu";
|
||||
import { LuTrash } from "react-icons/lu";
|
||||
import { Button } from "../ui/button";
|
||||
import { useMemo, useRef, useState } from "react";
|
||||
import { useState } from "react";
|
||||
import { isDesktop } from "react-device-detect";
|
||||
import { FaPlay } from "react-icons/fa";
|
||||
import { FaDownload, FaPlay } from "react-icons/fa";
|
||||
import Chip from "../indicators/Chip";
|
||||
import { Skeleton } from "../ui/skeleton";
|
||||
import { Dialog, DialogContent, DialogFooter, DialogTitle } from "../ui/dialog";
|
||||
import { Input } from "../ui/input";
|
||||
import useKeyboardListener from "@/hooks/use-keyboard-listener";
|
||||
import { Export } from "@/types/export";
|
||||
import { MdEditSquare } from "react-icons/md";
|
||||
import { baseUrl } from "@/api/baseUrl";
|
||||
|
||||
type ExportProps = {
|
||||
className: string;
|
||||
file: {
|
||||
name: string;
|
||||
};
|
||||
exportedRecording: Export;
|
||||
onSelect: (selected: Export) => void;
|
||||
onRename: (original: string, update: string) => void;
|
||||
onDelete: (file: string) => void;
|
||||
};
|
||||
|
||||
export default function ExportCard({
|
||||
className,
|
||||
file,
|
||||
exportedRecording,
|
||||
onSelect,
|
||||
onRename,
|
||||
onDelete,
|
||||
}: ExportProps) {
|
||||
const videoRef = useRef<HTMLVideoElement | null>(null);
|
||||
const [hovered, setHovered] = useState(false);
|
||||
const [playing, setPlaying] = useState(false);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const inProgress = useMemo(
|
||||
() => file.name.startsWith("in_progress"),
|
||||
[file.name],
|
||||
const [loading, setLoading] = useState(
|
||||
exportedRecording.thumb_path.length > 0,
|
||||
);
|
||||
|
||||
// editing name
|
||||
@@ -46,7 +44,7 @@ export default function ExportCard({
|
||||
editName != undefined ? ["Enter"] : [],
|
||||
(_, down, repeat) => {
|
||||
if (down && !repeat && editName && editName.update.length > 0) {
|
||||
onRename(editName.original, editName.update.replaceAll(" ", "_"));
|
||||
onRename(exportedRecording.id, editName.update);
|
||||
setEditName(undefined);
|
||||
}
|
||||
},
|
||||
@@ -84,10 +82,7 @@ export default function ExportCard({
|
||||
variant="select"
|
||||
disabled={(editName?.update?.length ?? 0) == 0}
|
||||
onClick={() => {
|
||||
onRename(
|
||||
editName.original,
|
||||
editName.update.replaceAll(" ", "_"),
|
||||
);
|
||||
onRename(exportedRecording.id, editName.update);
|
||||
setEditName(undefined);
|
||||
}}
|
||||
>
|
||||
@@ -102,75 +97,84 @@ export default function ExportCard({
|
||||
<div
|
||||
className={`relative aspect-video bg-black rounded-2xl flex justify-center items-center ${className}`}
|
||||
onMouseEnter={
|
||||
isDesktop && !inProgress ? () => setHovered(true) : undefined
|
||||
isDesktop && !exportedRecording.in_progress
|
||||
? () => setHovered(true)
|
||||
: undefined
|
||||
}
|
||||
onMouseLeave={
|
||||
isDesktop && !inProgress ? () => setHovered(false) : undefined
|
||||
isDesktop && !exportedRecording.in_progress
|
||||
? () => setHovered(false)
|
||||
: undefined
|
||||
}
|
||||
onClick={
|
||||
isDesktop || inProgress ? undefined : () => setHovered(!hovered)
|
||||
isDesktop || exportedRecording.in_progress
|
||||
? undefined
|
||||
: () => setHovered(!hovered)
|
||||
}
|
||||
>
|
||||
{hovered && (
|
||||
<>
|
||||
{!playing && (
|
||||
<div className="absolute inset-0 z-10 bg-black bg-opacity-60 rounded-2xl" />
|
||||
)}
|
||||
<div className="absolute inset-0 z-10 bg-black bg-opacity-60 rounded-2xl" />
|
||||
<div className="absolute top-1 right-1 flex items-center gap-2">
|
||||
<a
|
||||
className="z-20"
|
||||
download
|
||||
href={`${baseUrl}${exportedRecording.video_path.replace("/media/frigate/", "")}`}
|
||||
>
|
||||
<Chip className="bg-gradient-to-br from-gray-400 to-gray-500 bg-gray-500 rounded-md cursor-pointer">
|
||||
<FaDownload className="size-4 text-white" />
|
||||
</Chip>
|
||||
</a>
|
||||
<Chip
|
||||
className="bg-gradient-to-br from-gray-400 to-gray-500 bg-gray-500 rounded-md cursor-pointer"
|
||||
onClick={() => setEditName({ original: file.name, update: "" })}
|
||||
onClick={() =>
|
||||
setEditName({ original: exportedRecording.name, update: "" })
|
||||
}
|
||||
>
|
||||
<LuPencil className="size-4 text-white" />
|
||||
<MdEditSquare className="size-4 text-white" />
|
||||
</Chip>
|
||||
<Chip
|
||||
className="bg-gradient-to-br from-gray-400 to-gray-500 bg-gray-500 rounded-md cursor-pointer"
|
||||
onClick={() => onDelete(file.name)}
|
||||
onClick={() => onDelete(exportedRecording.id)}
|
||||
>
|
||||
<LuTrash className="size-4 text-destructive fill-destructive" />
|
||||
</Chip>
|
||||
</div>
|
||||
{!playing && (
|
||||
<Button
|
||||
className="absolute left-1/2 -translate-x-1/2 top-1/2 -translate-y-1/2 w-20 h-20 z-20 text-white hover:text-white hover:bg-transparent"
|
||||
variant="ghost"
|
||||
onClick={() => {
|
||||
setPlaying(true);
|
||||
videoRef.current?.play();
|
||||
}}
|
||||
>
|
||||
<FaPlay />
|
||||
</Button>
|
||||
)}
|
||||
|
||||
<Button
|
||||
className="absolute left-1/2 -translate-x-1/2 top-1/2 -translate-y-1/2 w-20 h-20 z-20 text-white hover:text-white hover:bg-transparent cursor-pointer"
|
||||
variant="ghost"
|
||||
onClick={() => {
|
||||
onSelect(exportedRecording);
|
||||
}}
|
||||
>
|
||||
<FaPlay />
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
{inProgress ? (
|
||||
{exportedRecording.in_progress ? (
|
||||
<ActivityIndicator />
|
||||
) : (
|
||||
<video
|
||||
ref={videoRef}
|
||||
className="absolute inset-0 aspect-video rounded-2xl"
|
||||
playsInline
|
||||
preload="auto"
|
||||
muted
|
||||
controls={playing}
|
||||
onLoadedData={() => setLoading(false)}
|
||||
>
|
||||
<source src={`${baseUrl}exports/${file.name}`} type="video/mp4" />
|
||||
</video>
|
||||
<>
|
||||
{exportedRecording.thumb_path.length > 0 ? (
|
||||
<img
|
||||
className="size-full absolute inset-0 object-contain aspect-video rounded-2xl"
|
||||
src={exportedRecording.thumb_path.replace("/media/frigate", "")}
|
||||
onLoad={() => setLoading(false)}
|
||||
/>
|
||||
) : (
|
||||
<div className="absolute inset-0 bg-secondary rounded-2xl" />
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
{loading && (
|
||||
<Skeleton className="absolute inset-0 aspect-video rounded-2xl" />
|
||||
)}
|
||||
{!playing && (
|
||||
<div className="absolute bottom-0 inset-x-0 rounded-b-l z-10 h-[20%] bg-gradient-to-t from-black/60 to-transparent pointer-events-none rounded-2xl">
|
||||
<div className="flex h-full justify-between items-end mx-3 pb-1 text-white text-sm capitalize">
|
||||
{file.name
|
||||
.substring(0, file.name.length - 4)
|
||||
.replaceAll("_", " ")}
|
||||
</div>
|
||||
<div className="absolute bottom-0 inset-x-0 rounded-b-l z-10 h-[20%] bg-gradient-to-t from-black/60 to-transparent pointer-events-none rounded-2xl">
|
||||
<div className="flex h-full justify-between items-end mx-3 pb-1 text-white text-sm capitalize">
|
||||
{exportedRecording.name.replaceAll("_", " ")}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user