2024-10-15 00:23:02 +03:00
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import { toast } from "sonner";
|
|
|
|
|
import { FaDownload } from "react-icons/fa";
|
|
|
|
|
import { formatUnixTimestampToDateTime } from "@/utils/dateUtil";
|
2024-10-23 06:09:57 +03:00
|
|
|
import { cn } from "@/lib/utils";
|
2025-03-16 18:36:20 +03:00
|
|
|
import { useTranslation } from "react-i18next";
|
2024-10-15 00:23:02 +03:00
|
|
|
|
|
|
|
|
type DownloadVideoButtonProps = {
|
|
|
|
|
source: string;
|
|
|
|
|
camera: string;
|
|
|
|
|
startTime: number;
|
2024-10-23 06:09:57 +03:00
|
|
|
className?: string;
|
2024-10-15 00:23:02 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export function DownloadVideoButton({
|
|
|
|
|
source,
|
|
|
|
|
camera,
|
|
|
|
|
startTime,
|
2024-10-23 06:09:57 +03:00
|
|
|
className,
|
2024-10-15 00:23:02 +03:00
|
|
|
}: DownloadVideoButtonProps) {
|
2025-03-16 18:36:20 +03:00
|
|
|
const { t } = useTranslation(["components/input"]);
|
2024-10-15 02:53:25 +03:00
|
|
|
const formattedDate = formatUnixTimestampToDateTime(startTime, {
|
|
|
|
|
strftime_fmt: "%D-%T",
|
|
|
|
|
time_style: "medium",
|
|
|
|
|
date_style: "medium",
|
|
|
|
|
});
|
|
|
|
|
const filename = `${camera}_${formattedDate}.mp4`;
|
|
|
|
|
|
|
|
|
|
const handleDownloadStart = () => {
|
2025-03-16 18:36:20 +03:00
|
|
|
toast.success(t("button.downloadVideo.toast.success"), {
|
2024-10-15 02:53:25 +03:00
|
|
|
position: "top-center",
|
2024-10-15 00:23:02 +03:00
|
|
|
});
|
2024-10-15 02:53:25 +03:00
|
|
|
};
|
2024-10-15 00:23:02 +03:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex justify-center">
|
|
|
|
|
<Button
|
2024-10-15 02:53:25 +03:00
|
|
|
asChild
|
2024-10-15 00:23:02 +03:00
|
|
|
className="flex items-center gap-2"
|
|
|
|
|
size="sm"
|
2025-03-16 18:36:20 +03:00
|
|
|
aria-label={t("button.downloadVideo.label")}
|
2024-10-15 00:23:02 +03:00
|
|
|
>
|
2024-10-23 06:09:57 +03:00
|
|
|
<a href={source} download={filename} onClick={handleDownloadStart}>
|
2024-11-12 15:37:25 +03:00
|
|
|
<FaDownload
|
|
|
|
|
className={cn("size-4 text-secondary-foreground", className)}
|
|
|
|
|
/>
|
2024-10-15 02:53:25 +03:00
|
|
|
</a>
|
2024-10-15 00:23:02 +03:00
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|