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`);
|
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> => {
|
const saveSignature = async (signature: Signature): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
// Check if signature already exists
|
// Check if signature already exists
|
||||||
@@ -67,15 +73,24 @@ const SystemView = () => {
|
|||||||
filter: `identifier='${signature.identifier}' && system='${signature.system}'`
|
filter: `identifier='${signature.identifier}' && system='${signature.system}'`
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const newScannedPercentage = parseScannedPercentage(signature.scanned);
|
||||||
|
|
||||||
if (existingRecords.items && existingRecords.items.length > 0) {
|
if (existingRecords.items && existingRecords.items.length > 0) {
|
||||||
// Update existing signature
|
// Update existing signature only if new scan percentage is higher
|
||||||
const existingId = existingRecords.items[0].id;
|
const existingRecord = existingRecords.items[0];
|
||||||
await pb.collection('signature').update(existingId, {
|
const existingScannedPercentage = parseScannedPercentage(existingRecord.scanned);
|
||||||
|
|
||||||
|
if (newScannedPercentage > existingScannedPercentage) {
|
||||||
|
await pb.collection('signature').update(existingRecord.id, {
|
||||||
name: signature.name,
|
name: signature.name,
|
||||||
type: signature.type,
|
type: signature.type,
|
||||||
dangerous: signature.dangerous,
|
dangerous: signature.dangerous,
|
||||||
scanned: signature.scanned
|
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 {
|
} else {
|
||||||
// Create new signature
|
// Create new signature
|
||||||
await pb.collection('signature').create({
|
await pb.collection('signature').create({
|
||||||
@@ -86,6 +101,7 @@ const SystemView = () => {
|
|||||||
dangerous: signature.dangerous,
|
dangerous: signature.dangerous,
|
||||||
scanned: signature.scanned
|
scanned: signature.scanned
|
||||||
});
|
});
|
||||||
|
console.log(`Created new signature ${signature.identifier} with ${newScannedPercentage}% scan`);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to save signature:', error);
|
console.error('Failed to save signature:', error);
|
||||||
|
Reference in New Issue
Block a user