Improve the signature updating logic
So that types are inserted even forsignatures which are less scanned than existing
This commit is contained in:
@@ -9,6 +9,7 @@ import { parseSignature, parseScannedPercentage } from "@/utils/signatureParser"
|
|||||||
import { getSystemId } from "@/utils/systemApi";
|
import { getSystemId } from "@/utils/systemApi";
|
||||||
import pb from "@/lib/pocketbase";
|
import pb from "@/lib/pocketbase";
|
||||||
import { SigviewRecord as Signature } from "@/lib/pbtypes";
|
import { SigviewRecord as Signature } from "@/lib/pbtypes";
|
||||||
|
import { udpSocket } from "bun";
|
||||||
|
|
||||||
export const SystemView = () => {
|
export const SystemView = () => {
|
||||||
const { system, region } = useParams();
|
const { system, region } = useParams();
|
||||||
@@ -34,23 +35,19 @@ export const SystemView = () => {
|
|||||||
const newScannedPercentage = parseScannedPercentage(signature.scanned);
|
const newScannedPercentage = parseScannedPercentage(signature.scanned);
|
||||||
|
|
||||||
if (existingRecord) {
|
if (existingRecord) {
|
||||||
|
const updatedSignature: Pick<Signature, 'updated' | 'type' | 'signame' | 'scanned'> = {
|
||||||
|
updated: new Date().toISOString()
|
||||||
|
}
|
||||||
|
if (existingRecord.type == "" && signature.type != "")
|
||||||
|
updatedSignature.type = signature.type;
|
||||||
|
if (existingRecord.signame == "" && signature.signame != "")
|
||||||
|
updatedSignature.signame = signature.signame;
|
||||||
// Update existing signature only if new scan percentage is higher
|
// Update existing signature only if new scan percentage is higher
|
||||||
const existingScannedPercentage = parseScannedPercentage(existingRecord.scanned);
|
const existingScannedPercentage = parseScannedPercentage(existingRecord.scanned);
|
||||||
if (newScannedPercentage >= existingScannedPercentage) {
|
if (newScannedPercentage >= existingScannedPercentage)
|
||||||
await pb.collection('signature').update(existingRecord.id, {
|
updatedSignature.scanned = signature.scanned;
|
||||||
name: signature.signame,
|
await pb.collection('signature').update(existingRecord.id, updatedSignature);
|
||||||
type: signature.type,
|
console.log(`Updated signature ${signature.identifier}: ${existingScannedPercentage}% -> ${newScannedPercentage}%`);
|
||||||
dangerous: signature.dangerous,
|
|
||||||
scanned: signature.scanned
|
|
||||||
});
|
|
||||||
console.log(`Updated signature ${signature.identifier}: ${existingScannedPercentage}% -> ${newScannedPercentage}%`);
|
|
||||||
} else {
|
|
||||||
const updatedSignature: Pick<Signature, 'updated'> = {
|
|
||||||
updated: new Date().toISOString()
|
|
||||||
}
|
|
||||||
await pb.collection('signature').update(existingRecord.id, updatedSignature);
|
|
||||||
console.log(`Skipped updating signature ${signature.identifier}: new scan ${newScannedPercentage}% is not better than existing ${existingScannedPercentage}%`);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Create new signature
|
// Create new signature
|
||||||
await pb.collection('signature').create({
|
await pb.collection('signature').create({
|
||||||
|
Reference in New Issue
Block a user