/** * Import Key Panel - Import existing SSH key */ import { Eye, EyeOff, Upload } from 'lucide-react'; import React,{ useCallback,useRef } from 'react'; import { useI18n } from '../../application/i18n/I18nProvider'; import { SSHKey } from '../../types'; import { Button } from '../ui/button'; import { Input } from '../ui/input'; import { Label } from '../ui/label'; import { Textarea } from '../ui/textarea'; import { detectKeyType } from './utils'; interface ImportKeyPanelProps { draftKey: Partial; setDraftKey: (key: Partial) => void; showPassphrase: boolean; setShowPassphrase: (show: boolean) => void; onImport: () => void; } export const ImportKeyPanel: React.FC = ({ draftKey, setDraftKey, showPassphrase, setShowPassphrase, onImport, }) => { const { t } = useI18n(); const fileInputRef = useRef(null); const handleFileImport = useCallback((event: React.ChangeEvent) => { const file = event.target.files?.[0]; if (!file) return; const reader = new FileReader(); reader.onload = (e) => { const content = e.target?.result as string; if (content) { const detectedType = detectKeyType(content); const label = file.name.replace(/\.(pem|key|pub|ppk)$/i, ''); setDraftKey({ ...draftKey, privateKey: content, label: draftKey.label || label, type: detectedType, }); } }; reader.readAsText(file); event.target.value = ''; }, [draftKey, setDraftKey]); const handleDrop = useCallback((event: React.DragEvent) => { event.preventDefault(); event.stopPropagation(); const file = event.dataTransfer.files?.[0]; if (!file) return; const reader = new FileReader(); reader.onload = (e) => { const content = e.target?.result as string; if (content) { const detectedType = detectKeyType(content); const label = file.name.replace(/\.(pem|key|pub|ppk)$/i, ''); setDraftKey({ ...draftKey, privateKey: content, label: draftKey.label || label, type: detectedType, }); } }; reader.readAsText(file); }, [draftKey, setDraftKey]); const handleDragOver = useCallback((event: React.DragEvent) => { event.preventDefault(); event.stopPropagation(); }, []); return ( <>
setDraftKey({ ...draftKey, label: e.target.value })} placeholder={t('keychain.field.labelPlaceholder')} />