feat: Implement "more scanned" signature update
Update signatures only if the scan percentage is higher than existing records in the database.
This commit is contained in:
@@ -60,6 +60,12 @@ const SystemView = () => {
|
||||
throw new Error(`System ${systemName} not found`);
|
||||
};
|
||||
|
||||
const parseScannedPercentage = (scannedString?: string): number => {
|
||||
if (!scannedString) return 0;
|
||||
const match = scannedString.match(/(\d+(?:\.\d+)?)%/);
|
||||
return match ? parseFloat(match[1]) : 0;
|
||||
};
|
||||
|
||||
const saveSignature = async (signature: Signature): Promise<void> => {
|
||||
try {
|
||||
// Check if signature already exists
|
||||
@@ -67,15 +73,24 @@ const SystemView = () => {
|
||||
filter: `identifier='${signature.identifier}' && system='${signature.system}'`
|
||||
});
|
||||
|
||||
const newScannedPercentage = parseScannedPercentage(signature.scanned);
|
||||
|
||||
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,
|
||||
scanned: signature.scanned
|
||||
});
|
||||
// Update existing signature only if new scan percentage is higher
|
||||
const existingRecord = existingRecords.items[0];
|
||||
const existingScannedPercentage = parseScannedPercentage(existingRecord.scanned);
|
||||
|
||||
if (newScannedPercentage > existingScannedPercentage) {
|
||||
await pb.collection('signature').update(existingRecord.id, {
|
||||
name: signature.name,
|
||||
type: signature.type,
|
||||
dangerous: signature.dangerous,
|
||||
scanned: signature.scanned
|
||||
});
|
||||
console.log(`Updated signature ${signature.identifier}: ${existingScannedPercentage}% -> ${newScannedPercentage}%`);
|
||||
} else {
|
||||
console.log(`Skipped updating signature ${signature.identifier}: new scan ${newScannedPercentage}% is not better than existing ${existingScannedPercentage}%`);
|
||||
}
|
||||
} else {
|
||||
// Create new signature
|
||||
await pb.collection('signature').create({
|
||||
@@ -86,6 +101,7 @@ const SystemView = () => {
|
||||
dangerous: signature.dangerous,
|
||||
scanned: signature.scanned
|
||||
});
|
||||
console.log(`Created new signature ${signature.identifier} with ${newScannedPercentage}% scan`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to save signature:', error);
|
||||
|
Reference in New Issue
Block a user