Fix: Signature POST to PocketBase
Use PocketBase SDK for signature creation and handle empty signature input.
This commit is contained in:
@@ -5,14 +5,16 @@ import { toast } from "@/hooks/use-toast";
|
|||||||
import { useQueryClient } from "@tanstack/react-query";
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
import SystemTracker from "@/components/SystemTracker";
|
import SystemTracker from "@/components/SystemTracker";
|
||||||
import RegionMap from "@/components/RegionMap";
|
import RegionMap from "@/components/RegionMap";
|
||||||
|
import pb from "@/lib/pocketbase";
|
||||||
|
|
||||||
interface Signature {
|
interface Signature {
|
||||||
identifier: string;
|
identifier: string;
|
||||||
type: string;
|
type: string;
|
||||||
signame: string;
|
name: string;
|
||||||
system: string;
|
system: string;
|
||||||
sysid: string;
|
sysid: string;
|
||||||
dangerous?: boolean;
|
dangerous?: boolean;
|
||||||
|
scanned?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SystemView = () => {
|
const SystemView = () => {
|
||||||
@@ -29,10 +31,17 @@ const SystemView = () => {
|
|||||||
const parts = text.split('\t');
|
const parts = text.split('\t');
|
||||||
if (parts.length < 4) return null;
|
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 {
|
return {
|
||||||
identifier: parts[0],
|
identifier: parts[0],
|
||||||
type: parts[2],
|
type: parts[2],
|
||||||
signame: parts[3],
|
name: parts[3],
|
||||||
|
scanned: parts.length > 4 ? parts[4] : undefined,
|
||||||
dangerous: false // TODO: Implement dangerous signature detection
|
dangerous: false // TODO: Implement dangerous signature detection
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -49,40 +58,35 @@ const SystemView = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const saveSignature = async (signature: Signature): Promise<void> => {
|
const saveSignature = async (signature: Signature): Promise<void> => {
|
||||||
|
try {
|
||||||
// Check if signature already exists
|
// 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 existingRecords = await pb.collection('signature').getList(1, 1, {
|
||||||
const existingResponse = await fetch(existingUrl);
|
filter: `identifier='${signature.identifier}' && system='${signature.system}'`
|
||||||
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) {
|
if (existingRecords.items && existingRecords.items.length > 0) {
|
||||||
throw new Error(`Failed to update signature: ${updateResponse.status}`);
|
// Update existing signature
|
||||||
}
|
const existingId = existingRecords.items[0].id;
|
||||||
|
await pb.collection('signature').update(existingId, {
|
||||||
|
name: signature.name,
|
||||||
|
type: signature.type,
|
||||||
|
dangerous: signature.dangerous,
|
||||||
|
scanned: signature.scanned
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
// Create new signature
|
// Create new signature
|
||||||
const createUrl = 'https://evebase.site.quack-lab.dev/api/collections/sigview/records';
|
await pb.collection('signature').create({
|
||||||
const createResponse = await fetch(createUrl, {
|
system: signature.system,
|
||||||
method: 'POST',
|
identifier: signature.identifier,
|
||||||
headers: { 'Content-Type': 'application/json' },
|
name: signature.name,
|
||||||
body: JSON.stringify(signature)
|
type: signature.type,
|
||||||
|
dangerous: signature.dangerous,
|
||||||
|
scanned: signature.scanned
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!createResponse.ok) {
|
|
||||||
throw new Error(`Failed to create signature: ${createResponse.status}`);
|
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to save signature:', error);
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -101,7 +105,7 @@ const SystemView = () => {
|
|||||||
if (parsed) {
|
if (parsed) {
|
||||||
parsedSignatures.push({
|
parsedSignatures.push({
|
||||||
...parsed,
|
...parsed,
|
||||||
system,
|
system: systemId,
|
||||||
sysid: systemId
|
sysid: systemId
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -110,7 +114,7 @@ const SystemView = () => {
|
|||||||
if (parsedSignatures.length === 0) {
|
if (parsedSignatures.length === 0) {
|
||||||
toast({
|
toast({
|
||||||
title: "No Valid Signatures",
|
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"
|
variant: "destructive"
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user