import { Algorithm, hashingAlgoSlugSchema, slugFromHashingAlgo, useLibraryMutation, useLibraryQuery } from '@sd/client'; import { Button, Dialog, Select, SelectOption, UseDialogProps, useDialog } from '@sd/ui'; import { CheckBox, useZodForm, z } from '@sd/ui/src/forms'; import { showAlertDialog } from '~/components/AlertDialog'; import { usePlatform } from '~/util/Platform'; import { KeyListSelectOptions } from '../../KeyManager/List'; interface Props extends UseDialogProps { location_id: number; path_id: number; } const schema = z.object({ key: z.string(), encryptionAlgo: z.string(), hashingAlgo: hashingAlgoSlugSchema, metadata: z.boolean(), previewMedia: z.boolean(), outputPath: z.string() }); export default (props: Props) => { const dialog = useDialog(props); const platform = usePlatform(); const UpdateKey = (uuid: string) => { form.setValue('key', uuid); const hashAlg = keys.data?.find((key) => { return key.uuid === uuid; })?.hashing_algorithm; hashAlg && form.setValue('hashingAlgo', slugFromHashingAlgo(hashAlg)); }; const keys = useLibraryQuery(['keys.list']); const mountedUuids = useLibraryQuery(['keys.listMounted'], { onSuccess: (data) => { UpdateKey(data[0] ?? ''); } }); const encryptFile = useLibraryMutation('files.encryptFiles', { onSuccess: () => { showAlertDialog({ title: 'Success', value: 'The encryption job has started successfully. You may track the progress in the job overview panel.' }); }, onError: () => { showAlertDialog({ title: 'Error', value: 'The encryption job failed to start.' }); } }); const form = useZodForm({ defaultValues: { encryptionAlgo: 'XChaCha20Poly1305', outputPath: '' }, schema }); const onSubmit = form.handleSubmit((data) => encryptFile.mutateAsync({ algorithm: data.encryptionAlgo as Algorithm, key_uuid: data.key, location_id: props.location_id, path_id: props.path_id, metadata: data.metadata, preview_media: data.previewMedia, output_path: data.outputPath || null }) ); return (
Key
Output file
Encryption
Hashing
Metadata
Preview Media
); };