diff --git a/src/components/SignatureCard.tsx b/src/components/SignatureCard.tsx index 2a971b6..9830509 100644 --- a/src/components/SignatureCard.tsx +++ b/src/components/SignatureCard.tsx @@ -1,8 +1,7 @@ - import { Card, CardContent } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Zap, Shield, Coins, HelpCircle } from "lucide-react"; -import { Signature } from "@/lib/types"; +import { SigviewRecord as Signature } from "@/lib/pbtypes"; interface SignatureCardProps { signature: Signature; diff --git a/src/components/SignatureListItem.tsx b/src/components/SignatureListItem.tsx index bb60422..31e84e3 100644 --- a/src/components/SignatureListItem.tsx +++ b/src/components/SignatureListItem.tsx @@ -1,6 +1,6 @@ import { Badge } from "@/components/ui/badge"; import { Zap, Shield, Coins, HelpCircle, Clock, AlertTriangle, Skull } from "lucide-react"; -import { Signature } from "@/lib/types"; +import { SigviewRecord as Signature } from "@/lib/pbtypes"; interface SignatureListItemProps { signature: Signature; @@ -86,7 +86,7 @@ export const SignatureListItem = ({ signature }: SignatureListItemProps) => { {/* Signature Name and ID */}
- {signature.id} + {signature.identifier}

{signature.signame || "Unnamed Signature"} {signature.dangerous && ( @@ -96,7 +96,6 @@ export const SignatureListItem = ({ signature }: SignatureListItemProps) => { )}

-
{signature.identifier}
{/* Dates */} diff --git a/src/components/SystemTracker.tsx b/src/components/SystemTracker.tsx index b78fe68..c5ad21b 100644 --- a/src/components/SystemTracker.tsx +++ b/src/components/SystemTracker.tsx @@ -7,11 +7,7 @@ import { Button } from "@/components/ui/button"; import { RefreshCw, AlertCircle, Radar } from "lucide-react"; import { SignatureListItem } from "@/components/SignatureListItem"; import { toast } from "@/hooks/use-toast"; -import { Signature } from "@/lib/types"; - -interface ApiResponse { - items: Signature[]; -} +import pb from "@/lib/pocketbase"; interface SystemTrackerProps { system: string; @@ -27,19 +23,7 @@ export const SystemTracker = ({ system }: SystemTrackerProps) => { queryKey: ['signatures', system], queryFn: async () => { if (!system) return null; - - const encodedSystem = encodeURIComponent(system); - const url = `https://evebase.site.quack-lab.dev/api/collections/sigview/records?filter=(system%3D'${encodedSystem}')`; - - console.log('Fetching signatures for system:', system); - console.log('API URL:', url); - - const response = await fetch(url); - if (!response.ok) { - throw new Error('Failed to fetch signatures'); - } - const data: ApiResponse = await response.json(); - return data; + return pb.collection('sigview').getFullList({ batch: 1000, filter: `(system='${system}')` }); }, enabled: !!system, refetchInterval: 5000, // Poll every 5 seconds @@ -53,7 +37,7 @@ export const SystemTracker = ({ system }: SystemTrackerProps) => { }); }; - const signatures = signaturesData?.items || []; + const signatures = signaturesData || []; const isLoading = signaturesLoading; // Sort signatures by date (newest first) and prioritize unknown types diff --git a/src/lib/pbtypes.ts b/src/lib/pbtypes.ts new file mode 100644 index 0000000..e4e479f --- /dev/null +++ b/src/lib/pbtypes.ts @@ -0,0 +1,202 @@ +/** +* This file was @generated using pocketbase-typegen +*/ + +import type PocketBase from 'pocketbase' +import type { RecordService } from 'pocketbase' + +export enum Collections { + Authorigins = "_authOrigins", + Externalauths = "_externalAuths", + Mfas = "_mfas", + Otps = "_otps", + Superusers = "_superusers", + Regionview = "regionview", + Signature = "signature", + Sigview = "sigview", + System = "system", + WormholeSystems = "wormholeSystems", +} + +// Alias types for improved usability +export type IsoDateString = string +export type RecordIdString = string +export type HTMLString = string + +type ExpandType = unknown extends T + ? T extends unknown + ? { expand?: unknown } + : { expand: T } + : { expand: T } + +// System fields +export type BaseSystemFields = { + id: RecordIdString + collectionId: string + collectionName: Collections +} & ExpandType + +export type AuthSystemFields = { + email: string + emailVisibility: boolean + username: string + verified: boolean +} & BaseSystemFields + +// Record types for each collection + +export type AuthoriginsRecord = { + collectionRef: string + created?: IsoDateString + fingerprint: string + id: string + recordRef: string + updated?: IsoDateString +} + +export type ExternalauthsRecord = { + collectionRef: string + created?: IsoDateString + id: string + provider: string + providerId: string + recordRef: string + updated?: IsoDateString +} + +export type MfasRecord = { + collectionRef: string + created?: IsoDateString + id: string + method: string + recordRef: string + updated?: IsoDateString +} + +export type OtpsRecord = { + collectionRef: string + created?: IsoDateString + id: string + password: string + recordRef: string + sentTo?: string + updated?: IsoDateString +} + +export type SuperusersRecord = { + created?: IsoDateString + email: string + emailVisibility?: boolean + id: string + password: string + tokenKey: string + updated?: IsoDateString + verified?: boolean +} + +export type RegionviewRecord = { + id: string + sigcount?: number + sysname: string + sysregion: string +} + +export type SignatureRecord = { + created?: IsoDateString + dangerous?: boolean + id: string + identifier: string + name?: string + scanned?: string + system: RecordIdString + type?: string + updated?: IsoDateString +} + +export type SigviewRecord = { + created?: IsoDateString + dangerous?: boolean + id: string + identifier: string + scanned?: string + signame?: string + sysid?: RecordIdString + system: string + type?: string + updated?: IsoDateString +} + +export type SystemRecord = { + connectedTo?: string + created?: IsoDateString + id: string + name: string + region: string + updated?: IsoDateString +} + +export type WormholeSystemsRecord = { + connectedSystems?: string + created?: IsoDateString + id: string + solarSystemName: string + updated?: IsoDateString + x: number + y: number +} + +// Response types include system fields and match responses from the PocketBase API +export type AuthoriginsResponse = Required & BaseSystemFields +export type ExternalauthsResponse = Required & BaseSystemFields +export type MfasResponse = Required & BaseSystemFields +export type OtpsResponse = Required & BaseSystemFields +export type SuperusersResponse = Required & AuthSystemFields +export type RegionviewResponse = Required & BaseSystemFields +export type SignatureResponse = Required & BaseSystemFields +export type SigviewResponse = Required & BaseSystemFields +export type SystemResponse = Required & BaseSystemFields +export type WormholeSystemsResponse = Required & BaseSystemFields + +// Types containing all Records and Responses, useful for creating typing helper functions + +export type CollectionRecords = { + _authOrigins: AuthoriginsRecord + _externalAuths: ExternalauthsRecord + _mfas: MfasRecord + _otps: OtpsRecord + _superusers: SuperusersRecord + regionview: RegionviewRecord + signature: SignatureRecord + sigview: SigviewRecord + system: SystemRecord + wormholeSystems: WormholeSystemsRecord +} + +export type CollectionResponses = { + _authOrigins: AuthoriginsResponse + _externalAuths: ExternalauthsResponse + _mfas: MfasResponse + _otps: OtpsResponse + _superusers: SuperusersResponse + regionview: RegionviewResponse + signature: SignatureResponse + sigview: SigviewResponse + system: SystemResponse + wormholeSystems: WormholeSystemsResponse +} + +// Type for usage with type asserted PocketBase instance +// https://github.com/pocketbase/js-sdk#specify-typescript-definitions + +export type TypedPocketBase = PocketBase & { + collection(idOrName: '_authOrigins'): RecordService + collection(idOrName: '_externalAuths'): RecordService + collection(idOrName: '_mfas'): RecordService + collection(idOrName: '_otps'): RecordService + collection(idOrName: '_superusers'): RecordService + collection(idOrName: 'regionview'): RecordService + collection(idOrName: 'signature'): RecordService + collection(idOrName: 'sigview'): RecordService + collection(idOrName: 'system'): RecordService + collection(idOrName: 'wormholeSystems'): RecordService +} diff --git a/src/lib/pocketbase.ts b/src/lib/pocketbase.ts index 3509cf7..bca13a0 100644 --- a/src/lib/pocketbase.ts +++ b/src/lib/pocketbase.ts @@ -1,6 +1,6 @@ - import PocketBase from 'pocketbase'; +import { TypedPocketBase } from './pbtypes'; -const pb = new PocketBase('https://evebase.site.quack-lab.dev'); +const pb = new PocketBase('https://evebase.site.quack-lab.dev') as TypedPocketBase; export default pb; diff --git a/src/lib/types.ts b/src/lib/types.ts index b27488b..010220f 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -27,16 +27,3 @@ export interface Connection { to: Position; color?: string; } - -export interface Signature { - id?: string; - identifier: string; - signame: string; - sysid: string; - system: string; - type: string; - updated?: string; - created?: string; - dangerous?: boolean; - scanned?: string; -} diff --git a/src/pages/SystemView.tsx b/src/pages/SystemView.tsx index 1079bf9..7618f50 100644 --- a/src/pages/SystemView.tsx +++ b/src/pages/SystemView.tsx @@ -10,7 +10,7 @@ import { Header } from "@/components/Header"; import { parseSignature, parseScannedPercentage } from "@/utils/signatureParser"; import { getSystemId } from "@/utils/systemApi"; import pb from "@/lib/pocketbase"; -import { Signature } from "@/lib/types"; +import { SigviewRecord as Signature } from "@/lib/pbtypes"; export const SystemView = () => { const { system, region } = useParams(); @@ -27,7 +27,7 @@ export const SystemView = () => { try { // Check if signature already exists const existingRecords = await pb.collection('signature').getList(1, 1, { - filter: `identifier='${signature.identifier}' && system='${signature.system}'` + filter: `(id='${signature.id}' && system='${signature.system}')` }); const newScannedPercentage = parseScannedPercentage(signature.scanned); @@ -84,7 +84,7 @@ export const SystemView = () => { try { const systemId = await getSystemId(system); const lines = pastedText.trim().split('\n').filter(line => line.trim()); - const parsedSignatures: Signature[] = []; + const parsedSignatures: Omit[] = []; // Parse all signatures for (const line of lines) { @@ -93,7 +93,8 @@ export const SystemView = () => { parsedSignatures.push({ ...parsed, system: systemId, - sysid: systemId + sysid: systemId, + identifier: parsed.identifier }); } } @@ -130,7 +131,7 @@ export const SystemView = () => { // Save all new/updated signatures for (const signature of parsedSignatures) { - await saveSignature(signature); + await saveSignature(signature as Signature); } // Invalidate queries to refresh the data diff --git a/src/utils/signatureParser.ts b/src/utils/signatureParser.ts index 0abd60e..c04bc45 100644 --- a/src/utils/signatureParser.ts +++ b/src/utils/signatureParser.ts @@ -1,6 +1,6 @@ -import { Signature } from "@/lib/types"; +import { SigviewRecord as Signature } from "@/lib/pbtypes"; -export const parseSignature = (text: string): Omit | null => { +export const parseSignature = (text: string): Omit | null => { const parts = text.split('\t'); if (parts.length < 4) return null;