/
hed1ad
/
CloudGuard_API_Security_Platform
Обзор
Документация
Войти
/
hed1ad
/
CloudGuard_API_Security_Platform
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
frontend/components/ScanForm.tsx
80 строк
2 KB
hed1ad
1.0.0
26 окт 2025, 14:25
26 окт 2025, 14:25
63b0f76
Код
Авторство
О чём код?
'use client'; import { useState } from 'react'; import { createScan, Scan } from '@/lib/api'; interface ScanFormProps { onScanCreated: (scan: Scan) => void; } export function ScanForm({ onScanCreated }: ScanFormProps) { const [targetUrl, setTargetUrl] = useState(''); const [endpoints, setEndpoints] = useState(''); const [loading, setLoading] = useState(false); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); try { const endpointList = endpoints .split('\n') .map(e => e.trim()) .filter(e => e.length > 0); if (endpointList.length === 0) { alert('Please provide at least one endpoint'); setLoading(false); return; } const scan = await createScan(targetUrl, endpointList); onScanCreated(scan); setTargetUrl(''); setEndpoints(''); } catch (error) { alert('Ошибка при создании скана: ' + (error as Error).message); } finally { setLoading(false); } }; return ( <form onSubmit={handleSubmit} className="space-y-4"> <div> <label className="block text-sm font-medium mb-2"> Target API URL </label> <input type="url" value={targetUrl} onChange={(e) => setTargetUrl(e.target.value)} placeholder="https://api.example.com" className="w-full border border-gray-300 rounded px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500" required /> </div> <div> <label className="block text-sm font-medium mb-2"> Endpoints (один на строку) </label> <textarea value={endpoints} onChange={(e) => setEndpoints(e.target.value)} placeholder="/api/users /api/posts /api/comments" className="w-full border border-gray-300 rounded px-3 py-2 h-32 focus:outline-none focus:ring-2 focus:ring-blue-500" required /> </div> <button type="submit" disabled={loading} className="bg-blue-600 text-white px-6 py-2 rounded hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors" > {loading ? 'Запуск...' : 'Начать сканирование'} </button> </form> ); }