From 8f266459adfb9265a9c29fdf729b0dcbe221337b Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sat, 14 Jun 2025 16:13:31 +0000 Subject: [PATCH] Fix: Signature POST to PocketBase Use PocketBase SDK for signature creation and handle empty signature input. --- src/pages/SystemView.tsx | 74 +++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/src/pages/SystemView.tsx b/src/pages/SystemView.tsx index 1fabffb..4c6581c 100644 --- a/src/pages/SystemView.tsx +++ b/src/pages/SystemView.tsx @@ -5,14 +5,16 @@ import { toast } from "@/hooks/use-toast"; import { useQueryClient } from "@tanstack/react-query"; import SystemTracker from "@/components/SystemTracker"; import RegionMap from "@/components/RegionMap"; +import pb from "@/lib/pocketbase"; interface Signature { identifier: string; type: string; - signame: string; + name: string; system: string; sysid: string; dangerous?: boolean; + scanned?: string; } const SystemView = () => { @@ -29,10 +31,17 @@ const SystemView = () => { const parts = text.split('\t'); if (parts.length < 4) return null; + // Validate signature identifier format (3 letters, dash, 3 numbers) + const signatureIdentifierRegex = /^\w{3}-\d{3}$/; + if (!signatureIdentifierRegex.test(parts[0])) { + return null; + } + return { identifier: parts[0], type: parts[2], - signame: parts[3], + name: parts[3], + scanned: parts.length > 4 ? parts[4] : undefined, dangerous: false // TODO: Implement dangerous signature detection }; }; @@ -49,40 +58,35 @@ const SystemView = () => { }; 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(); + try { + // Check if signature already exists + const existingRecords = await pb.collection('signature').getList(1, 1, { + filter: `identifier='${signature.identifier}' && system='${signature.system}'` + }); - 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, + if (existingRecords.items && existingRecords.items.length > 0) { + // Update existing signature + const existingId = existingRecords.items[0].id; + await pb.collection('signature').update(existingId, { + name: signature.name, 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}`); + dangerous: signature.dangerous, + scanned: signature.scanned + }); + } else { + // Create new signature + await pb.collection('signature').create({ + system: signature.system, + identifier: signature.identifier, + name: signature.name, + type: signature.type, + dangerous: signature.dangerous, + scanned: signature.scanned + }); } + } catch (error) { + console.error('Failed to save signature:', error); + throw error; } }; @@ -101,7 +105,7 @@ const SystemView = () => { if (parsed) { parsedSignatures.push({ ...parsed, - system, + system: systemId, sysid: systemId }); } @@ -110,7 +114,7 @@ const SystemView = () => { if (parsedSignatures.length === 0) { toast({ title: "No Valid Signatures", - description: "No valid signatures found in the pasted data.", + description: "No valid signatures found in the pasted data. Signatures must follow the format: ABC-123.", variant: "destructive" }); return;