"use client" import {Alert, AlertDescription, AlertTitle} from "@/components/ui/alert"; import {Info} from "lucide-react"; import {ButtonWithLoading} from "@/components/common/button-with-loading"; import {useRouter} from "next/navigation"; import {Setting} from "@/db/schema/01_setting"; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, useZodForm } from "@/components/ui/form"; import {StorageChannelWith} from "@/db/schema/12_storage-channel"; import {Select, SelectContent, SelectItem, SelectTrigger, SelectValue} from "@/components/ui/select"; import {useMutation} from "@tanstack/react-query"; import { DefaultStorageSchema, DefaultStorageType } from "@/features/settings/schemas/storage.schema"; import {getChannelIcon} from "@/features/channel/components/channels-helpers"; import { updateStorageSettingsAction } from "@/features/settings/actions/storage.action"; import {toast} from "sonner"; import {Switch} from "@/components/ui/switch"; import {downloadMasterKeyAction} from "@/features/agents/actions/keys.action"; export type SettingsStorageSectionProps = { settings: Setting; storageChannels: StorageChannelWith[]; }; export const SettingsStorageSection = ({settings, storageChannels}: SettingsStorageSectionProps) => { const router = useRouter(); const form = useZodForm({ schema: DefaultStorageSchema, defaultValues: { storageChannelId: settings.defaultStorageChannelId ?? undefined, encryption: settings.encryption ?? false } }); const mutation = useMutation({ mutationFn: async (values: DefaultStorageType) => { const result = await updateStorageSettingsAction({name: "system", data: values}) const inner = result?.data; if (inner?.success) { toast.success(inner.actionSuccess?.message); router.refresh(); } else { toast.error(inner?.actionError?.message); } } }); const handleDownload = async () => { const result = await downloadMasterKeyAction(); if (!result?.success) { toast.error(result?.message ?? "Download failed"); return; } const byteCharacters = atob(result.data as string); const byteNumbers = new Array(byteCharacters.length) .fill(null) .map((_, i) => byteCharacters.charCodeAt(i)); const blob = new Blob([new Uint8Array(byteNumbers)], { type: "application/octet-stream", }); const url = window.URL.createObjectURL(blob); const a = document.createElement("a"); a.href = url; a.download = "master_key.bin"; document.body.appendChild(a); a.click(); a.remove(); window.URL.revokeObjectURL(url); }; return (
Informations The default storage channel will be used by default to store your backups if no storage policy is configured at the database level.
{ await mutation.mutateAsync(values); }} >
( Default Storage Provider )} /> ( Backups Encryption )} />
Confirm
Download instance
); };