mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-11 05:35:25 +03:00
Use new apis for frontend
This commit is contained in:
parent
a87ec6b8ab
commit
82b16f3947
@ -159,7 +159,7 @@ class RecordingExporter(threading.Thread):
|
|||||||
export_id = f"{self.camera}_{''.join(random.choices(string.ascii_lowercase + string.digits, k=6))}"
|
export_id = f"{self.camera}_{''.join(random.choices(string.ascii_lowercase + string.digits, k=6))}"
|
||||||
export_name = (
|
export_name = (
|
||||||
self.user_provided_name
|
self.user_provided_name
|
||||||
or f"{self.camera} {self.get_datetime_from_timestamp(self.start_time)} {self.get_datetime_from_timestamp(self.end_time)}"
|
or f"{self.camera.replace("_", " ")} {self.get_datetime_from_timestamp(self.start_time)} {self.get_datetime_from_timestamp(self.end_time)}"
|
||||||
)
|
)
|
||||||
video_path = f"{EXPORT_DIR}/{export_id}.mp4"
|
video_path = f"{EXPORT_DIR}/{export_id}.mp4"
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import { Redirect } from "./components/navigation/Redirect";
|
|||||||
|
|
||||||
const Live = lazy(() => import("@/pages/Live"));
|
const Live = lazy(() => import("@/pages/Live"));
|
||||||
const Events = lazy(() => import("@/pages/Events"));
|
const Events = lazy(() => import("@/pages/Events"));
|
||||||
const Export = lazy(() => import("@/pages/Export"));
|
const Exports = lazy(() => import("@/pages/Exports"));
|
||||||
const SubmitPlus = lazy(() => import("@/pages/SubmitPlus"));
|
const SubmitPlus = lazy(() => import("@/pages/SubmitPlus"));
|
||||||
const ConfigEditor = lazy(() => import("@/pages/ConfigEditor"));
|
const ConfigEditor = lazy(() => import("@/pages/ConfigEditor"));
|
||||||
const System = lazy(() => import("@/pages/System"));
|
const System = lazy(() => import("@/pages/System"));
|
||||||
@ -38,7 +38,7 @@ function App() {
|
|||||||
<Route path="/" element={<Live />} />
|
<Route path="/" element={<Live />} />
|
||||||
<Route path="/events" element={<Redirect to="/review" />} />
|
<Route path="/events" element={<Redirect to="/review" />} />
|
||||||
<Route path="/review" element={<Events />} />
|
<Route path="/review" element={<Events />} />
|
||||||
<Route path="/export" element={<Export />} />
|
<Route path="/export" element={<Exports />} />
|
||||||
<Route path="/plus" element={<SubmitPlus />} />
|
<Route path="/plus" element={<SubmitPlus />} />
|
||||||
<Route path="/system" element={<System />} />
|
<Route path="/system" element={<System />} />
|
||||||
<Route path="/settings" element={<Settings />} />
|
<Route path="/settings" element={<Settings />} />
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
import { baseUrl } from "@/api/baseUrl";
|
|
||||||
import ActivityIndicator from "../indicators/activity-indicator";
|
import ActivityIndicator from "../indicators/activity-indicator";
|
||||||
import { LuPencil, LuTrash } from "react-icons/lu";
|
import { LuPencil, LuTrash } from "react-icons/lu";
|
||||||
import { Button } from "../ui/button";
|
import { Button } from "../ui/button";
|
||||||
import { useMemo, useRef, useState } from "react";
|
import { useRef, useState } from "react";
|
||||||
import { isDesktop } from "react-device-detect";
|
import { isDesktop } from "react-device-detect";
|
||||||
import { FaPlay } from "react-icons/fa";
|
import { FaPlay } from "react-icons/fa";
|
||||||
import Chip from "../indicators/Chip";
|
import Chip from "../indicators/Chip";
|
||||||
@ -10,19 +9,18 @@ import { Skeleton } from "../ui/skeleton";
|
|||||||
import { Dialog, DialogContent, DialogFooter, DialogTitle } from "../ui/dialog";
|
import { Dialog, DialogContent, DialogFooter, DialogTitle } from "../ui/dialog";
|
||||||
import { Input } from "../ui/input";
|
import { Input } from "../ui/input";
|
||||||
import useKeyboardListener from "@/hooks/use-keyboard-listener";
|
import useKeyboardListener from "@/hooks/use-keyboard-listener";
|
||||||
|
import { Export } from "@/types/export";
|
||||||
|
|
||||||
type ExportProps = {
|
type ExportProps = {
|
||||||
className: string;
|
className: string;
|
||||||
file: {
|
exportedRecording: Export;
|
||||||
name: string;
|
|
||||||
};
|
|
||||||
onRename: (original: string, update: string) => void;
|
onRename: (original: string, update: string) => void;
|
||||||
onDelete: (file: string) => void;
|
onDelete: (file: string) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function ExportCard({
|
export default function ExportCard({
|
||||||
className,
|
className,
|
||||||
file,
|
exportedRecording,
|
||||||
onRename,
|
onRename,
|
||||||
onDelete,
|
onDelete,
|
||||||
}: ExportProps) {
|
}: ExportProps) {
|
||||||
@ -30,10 +28,6 @@ export default function ExportCard({
|
|||||||
const [hovered, setHovered] = useState(false);
|
const [hovered, setHovered] = useState(false);
|
||||||
const [playing, setPlaying] = useState(false);
|
const [playing, setPlaying] = useState(false);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const inProgress = useMemo(
|
|
||||||
() => file.name.startsWith("in_progress"),
|
|
||||||
[file.name],
|
|
||||||
);
|
|
||||||
|
|
||||||
// editing name
|
// editing name
|
||||||
|
|
||||||
@ -102,13 +96,19 @@ export default function ExportCard({
|
|||||||
<div
|
<div
|
||||||
className={`relative aspect-video bg-black rounded-2xl flex justify-center items-center ${className}`}
|
className={`relative aspect-video bg-black rounded-2xl flex justify-center items-center ${className}`}
|
||||||
onMouseEnter={
|
onMouseEnter={
|
||||||
isDesktop && !inProgress ? () => setHovered(true) : undefined
|
isDesktop && !exportedRecording.in_progress
|
||||||
|
? () => setHovered(true)
|
||||||
|
: undefined
|
||||||
}
|
}
|
||||||
onMouseLeave={
|
onMouseLeave={
|
||||||
isDesktop && !inProgress ? () => setHovered(false) : undefined
|
isDesktop && !exportedRecording.in_progress
|
||||||
|
? () => setHovered(false)
|
||||||
|
: undefined
|
||||||
}
|
}
|
||||||
onClick={
|
onClick={
|
||||||
isDesktop || inProgress ? undefined : () => setHovered(!hovered)
|
isDesktop || exportedRecording.in_progress
|
||||||
|
? undefined
|
||||||
|
: () => setHovered(!hovered)
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{hovered && (
|
{hovered && (
|
||||||
@ -119,13 +119,15 @@ export default function ExportCard({
|
|||||||
<div className="absolute top-1 right-1 flex items-center gap-2">
|
<div className="absolute top-1 right-1 flex items-center gap-2">
|
||||||
<Chip
|
<Chip
|
||||||
className="bg-gradient-to-br from-gray-400 to-gray-500 bg-gray-500 rounded-md cursor-pointer"
|
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.id, update: "" })
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<LuPencil className="size-4 text-white" />
|
<LuPencil className="size-4 text-white" />
|
||||||
</Chip>
|
</Chip>
|
||||||
<Chip
|
<Chip
|
||||||
className="bg-gradient-to-br from-gray-400 to-gray-500 bg-gray-500 rounded-md cursor-pointer"
|
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" />
|
<LuTrash className="size-4 text-destructive fill-destructive" />
|
||||||
</Chip>
|
</Chip>
|
||||||
@ -144,20 +146,14 @@ export default function ExportCard({
|
|||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{inProgress ? (
|
{exportedRecording.in_progress ? (
|
||||||
<ActivityIndicator />
|
<ActivityIndicator />
|
||||||
) : (
|
) : (
|
||||||
<video
|
<img
|
||||||
ref={videoRef}
|
|
||||||
className="absolute inset-0 aspect-video rounded-2xl"
|
className="absolute inset-0 aspect-video rounded-2xl"
|
||||||
playsInline
|
src={exportedRecording.thumb_path.replace("/media/frigate", "")}
|
||||||
preload="auto"
|
onLoad={() => setLoading(false)}
|
||||||
muted
|
/>
|
||||||
controls={playing}
|
|
||||||
onLoadedData={() => setLoading(false)}
|
|
||||||
>
|
|
||||||
<source src={`${baseUrl}exports/${file.name}`} type="video/mp4" />
|
|
||||||
</video>
|
|
||||||
)}
|
)}
|
||||||
{loading && (
|
{loading && (
|
||||||
<Skeleton className="absolute inset-0 aspect-video rounded-2xl" />
|
<Skeleton className="absolute inset-0 aspect-video rounded-2xl" />
|
||||||
@ -165,9 +161,7 @@ export default function ExportCard({
|
|||||||
{!playing && (
|
{!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="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">
|
<div className="flex h-full justify-between items-end mx-3 pb-1 text-white text-sm capitalize">
|
||||||
{file.name
|
{exportedRecording.name}
|
||||||
.substring(0, file.name.length - 4)
|
|
||||||
.replaceAll("_", " ")}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
import { baseUrl } from "@/api/baseUrl";
|
|
||||||
import ExportCard from "@/components/card/ExportCard";
|
import ExportCard from "@/components/card/ExportCard";
|
||||||
import {
|
import {
|
||||||
AlertDialog,
|
AlertDialog,
|
||||||
@ -11,19 +10,13 @@ import {
|
|||||||
} from "@/components/ui/alert-dialog";
|
} from "@/components/ui/alert-dialog";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { Export } from "@/types/export";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
|
|
||||||
type ExportItem = {
|
function Exports() {
|
||||||
name: string;
|
const { data: exports, mutate } = useSWR<Export[]>("exports");
|
||||||
};
|
|
||||||
|
|
||||||
function Export() {
|
|
||||||
const { data: allExports, mutate } = useSWR<ExportItem[]>(
|
|
||||||
"exports/",
|
|
||||||
(url: string) => axios({ baseURL: baseUrl, url }).then((res) => res.data),
|
|
||||||
);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
document.title = "Export - Frigate";
|
document.title = "Export - Frigate";
|
||||||
@ -33,15 +26,17 @@ function Export() {
|
|||||||
|
|
||||||
const [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
|
|
||||||
const exports = useMemo(() => {
|
const filteredExports = useMemo(() => {
|
||||||
if (!search || !allExports) {
|
if (!search || !exports) {
|
||||||
return allExports;
|
return exports;
|
||||||
}
|
}
|
||||||
|
|
||||||
return allExports.filter((exp) =>
|
return exports.filter((exp) =>
|
||||||
exp.name.toLowerCase().includes(search.toLowerCase()),
|
exp.name
|
||||||
|
.toLowerCase()
|
||||||
|
.includes(search.toLowerCase().replaceAll(" ", "_")),
|
||||||
);
|
);
|
||||||
}, [allExports, search]);
|
}, [exports, search]);
|
||||||
|
|
||||||
// Deleting
|
// Deleting
|
||||||
|
|
||||||
@ -63,8 +58,8 @@ function Export() {
|
|||||||
// Renaming
|
// Renaming
|
||||||
|
|
||||||
const onHandleRename = useCallback(
|
const onHandleRename = useCallback(
|
||||||
(original: string, update: string) => {
|
(id: string, update: string) => {
|
||||||
axios.patch(`export/${original}/${update}`).then((response) => {
|
axios.patch(`export/${id}/${update}`).then((response) => {
|
||||||
if (response.status == 200) {
|
if (response.status == 200) {
|
||||||
setDeleteClip(undefined);
|
setDeleteClip(undefined);
|
||||||
mutate();
|
mutate();
|
||||||
@ -106,15 +101,15 @@ function Export() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="w-full overflow-hidden">
|
<div className="w-full overflow-hidden">
|
||||||
{allExports && exports && (
|
{exports && filteredExports && (
|
||||||
<div className="size-full grid gap-2 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 overflow-y-auto">
|
<div className="size-full grid gap-2 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 overflow-y-auto">
|
||||||
{Object.values(allExports).map((item) => (
|
{Object.values(exports).map((item) => (
|
||||||
<ExportCard
|
<ExportCard
|
||||||
key={item.name}
|
key={item.name}
|
||||||
className={
|
className={
|
||||||
search == "" || exports.includes(item) ? "" : "hidden"
|
search == "" || filteredExports.includes(item) ? "" : "hidden"
|
||||||
}
|
}
|
||||||
file={item}
|
exportedRecording={item}
|
||||||
onRename={onHandleRename}
|
onRename={onHandleRename}
|
||||||
onDelete={(file) => setDeleteClip(file)}
|
onDelete={(file) => setDeleteClip(file)}
|
||||||
/>
|
/>
|
||||||
@ -126,4 +121,4 @@ function Export() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Export;
|
export default Exports;
|
||||||
9
web/src/types/export.ts
Normal file
9
web/src/types/export.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
export type Export = {
|
||||||
|
id: string;
|
||||||
|
camera: string;
|
||||||
|
name: string;
|
||||||
|
date: number;
|
||||||
|
video_path: string;
|
||||||
|
thumb_path: string;
|
||||||
|
in_progress: boolean;
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue
Block a user