diff --git a/src/components/SignatureIngest.tsx b/src/components/SignatureIngest.tsx deleted file mode 100644 index 947db99..0000000 --- a/src/components/SignatureIngest.tsx +++ /dev/null @@ -1,233 +0,0 @@ - -import { useState } from "react"; -import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; -import { Button } from "@/components/ui/button"; -import { Textarea } from "@/components/ui/textarea"; -import { Switch } from "@/components/ui/switch"; -import { Label } from "@/components/ui/label"; -import { Upload, Trash2 } from "lucide-react"; -import { toast } from "@/hooks/use-toast"; -import pb from "@/lib/pocketbase"; -import { useQueryClient } from "@tanstack/react-query"; - -interface Signature { - identifier: string; - type: string; - signame: string; - system: string; - sysid: string; - dangerous?: boolean; -} - -interface SignatureIngestProps { - system: string; - region: string; -} - -const SignatureIngest = ({ system, region }: SignatureIngestProps) => { - const [pasteData, setPasteData] = useState(""); - const [cleanMode, setCleanMode] = useState(false); - const [isSubmitting, setIsSubmitting] = useState(false); - const queryClient = useQueryClient(); - - const parseSignature = (text: string): Omit | null => { - const parts = text.split('\t'); - if (parts.length < 4) return null; - - return { - identifier: parts[0], - type: parts[2], - signame: parts[3], - dangerous: false // TODO: Implement dangerous signature detection - }; - }; - - const getSystemId = async (systemName: string): Promise => { - const url = `https://evebase.site.quack-lab.dev/api/collections/regionview/records?filter=(sysname='${encodeURIComponent(systemName)}')`; - const response = await fetch(url); - const data = await response.json(); - - if (data.items && data.items.length > 0) { - return data.items[0].id; - } - throw new Error(`System ${systemName} not found`); - }; - - const saveSignature = async (signature: Signature): Promise => { - // Check if signature already exists - const existingUrl = `https://evebase.site.quack-lab.dev/api/collections/sigview/records?filter=(identifier='${signature.identifier}' && system='${signature.system}')`; - const existingResponse = await fetch(existingUrl); - const existingData = await existingResponse.json(); - - if (existingData.items && existingData.items.length > 0) { - // Update existing signature - const existingId = existingData.items[0].id; - const updateUrl = `https://evebase.site.quack-lab.dev/api/collections/sigview/records/${existingId}`; - const updateResponse = await fetch(updateUrl, { - method: 'PATCH', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ - signame: signature.signame, - type: signature.type, - dangerous: signature.dangerous - }) - }); - - if (!updateResponse.ok) { - throw new Error(`Failed to update signature: ${updateResponse.status}`); - } - } else { - // Create new signature - const createUrl = 'https://evebase.site.quack-lab.dev/api/collections/sigview/records'; - const createResponse = await fetch(createUrl, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(signature) - }); - - if (!createResponse.ok) { - throw new Error(`Failed to create signature: ${createResponse.status}`); - } - } - }; - - const deleteSignature = async (signatureId: string): Promise => { - const deleteUrl = `https://evebase.site.quack-lab.dev/api/collections/sigview/records/${signatureId}`; - const response = await fetch(deleteUrl, { method: 'DELETE' }); - - if (!response.ok && response.status !== 204) { - throw new Error(`Failed to delete signature: ${response.status}`); - } - }; - - const handleSubmit = async () => { - if (!pasteData.trim()) { - toast({ - title: "No Data", - description: "Please paste signature data to submit.", - variant: "destructive" - }); - return; - } - - setIsSubmitting(true); - try { - const systemId = await getSystemId(system); - const lines = pasteData.trim().split('\n').filter(line => line.trim()); - const parsedSignatures: Signature[] = []; - - // Parse all signatures - for (const line of lines) { - const parsed = parseSignature(line); - if (parsed) { - parsedSignatures.push({ - ...parsed, - system, - sysid: systemId - }); - } - } - - if (parsedSignatures.length === 0) { - toast({ - title: "No Valid Signatures", - description: "No valid signatures found in the pasted data.", - variant: "destructive" - }); - return; - } - - // If clean mode is enabled, get existing signatures and delete ones not in the new list - if (cleanMode) { - const existingUrl = `https://evebase.site.quack-lab.dev/api/collections/sigview/records?filter=(system='${encodeURIComponent(system)}')`; - const existingResponse = await fetch(existingUrl); - const existingData = await existingResponse.json(); - - const newIdentifiers = new Set(parsedSignatures.map(sig => sig.identifier)); - const toDelete = existingData.items?.filter((item: any) => !newIdentifiers.has(item.identifier)) || []; - - // Delete signatures not in the new list - for (const item of toDelete) { - await deleteSignature(item.id); - } - } - - // Save all new/updated signatures - for (const signature of parsedSignatures) { - await saveSignature(signature); - } - - // Invalidate queries to refresh the data - queryClient.invalidateQueries({ queryKey: ['signatures', system] }); - - toast({ - title: "Success", - description: `${parsedSignatures.length} signatures processed${cleanMode ? ' (clean mode)' : ''}.` - }); - - setPasteData(""); - } catch (error) { - console.error('Failed to submit signatures:', error); - toast({ - title: "Error", - description: error instanceof Error ? error.message : "Failed to submit signatures.", - variant: "destructive" - }); - } finally { - setIsSubmitting(false); - } - }; - - const handlePaste = (e: React.ClipboardEvent) => { - const pastedText = e.clipboardData.getData('text'); - setPasteData(prev => prev + (prev ? '\n' : '') + pastedText); - }; - - return ( - - - - - Ingest Signatures - - - -
- -