mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-15 07:35:27 +03:00
better filename
This commit is contained in:
parent
99386d159d
commit
c8153ec39a
@ -3,16 +3,30 @@ import { Button } from "@/components/ui/button";
|
|||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import ActivityIndicator from "../indicators/activity-indicator";
|
import ActivityIndicator from "../indicators/activity-indicator";
|
||||||
import { FaDownload } from "react-icons/fa";
|
import { FaDownload } from "react-icons/fa";
|
||||||
|
import { formatUnixTimestampToDateTime } from "@/utils/dateUtil";
|
||||||
|
|
||||||
type DownloadVideoButtonProps = {
|
type DownloadVideoButtonProps = {
|
||||||
source: string;
|
source: string;
|
||||||
|
camera: string;
|
||||||
|
startTime: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function DownloadVideoButton({ source }: DownloadVideoButtonProps) {
|
export function DownloadVideoButton({
|
||||||
|
source,
|
||||||
|
camera,
|
||||||
|
startTime,
|
||||||
|
}: DownloadVideoButtonProps) {
|
||||||
const [isDownloading, setIsDownloading] = useState(false);
|
const [isDownloading, setIsDownloading] = useState(false);
|
||||||
|
|
||||||
const handleDownload = async () => {
|
const handleDownload = async () => {
|
||||||
setIsDownloading(true);
|
setIsDownloading(true);
|
||||||
|
const formattedDate = formatUnixTimestampToDateTime(startTime, {
|
||||||
|
strftime_fmt: "%D-%T",
|
||||||
|
time_style: "medium",
|
||||||
|
date_style: "medium",
|
||||||
|
});
|
||||||
|
const filename = `${camera}_${formattedDate}.mp4`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(source);
|
const response = await fetch(source);
|
||||||
const blob = await response.blob();
|
const blob = await response.blob();
|
||||||
@ -20,7 +34,7 @@ export function DownloadVideoButton({ source }: DownloadVideoButtonProps) {
|
|||||||
const a = document.createElement("a");
|
const a = document.createElement("a");
|
||||||
a.style.display = "none";
|
a.style.display = "none";
|
||||||
a.href = url;
|
a.href = url;
|
||||||
a.download = "video.mp4";
|
a.download = filename;
|
||||||
document.body.appendChild(a);
|
document.body.appendChild(a);
|
||||||
a.click();
|
a.click();
|
||||||
window.URL.revokeObjectURL(url);
|
window.URL.revokeObjectURL(url);
|
||||||
|
|||||||
@ -169,6 +169,8 @@ export default function ReviewDetailDialog({
|
|||||||
<TooltipTrigger>
|
<TooltipTrigger>
|
||||||
<DownloadVideoButton
|
<DownloadVideoButton
|
||||||
source={`${baseUrl}api/${review.camera}/start/${review.start_time}/end/${review.end_time || Date.now() / 1000}/clip.mp4`}
|
source={`${baseUrl}api/${review.camera}/start/${review.start_time}/end/${review.end_time || Date.now() / 1000}/clip.mp4`}
|
||||||
|
camera={review.camera}
|
||||||
|
startTime={review.start_time}
|
||||||
/>
|
/>
|
||||||
</TooltipTrigger>
|
</TooltipTrigger>
|
||||||
<TooltipPortal>
|
<TooltipPortal>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user