Updated alignments and validation logics
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled

This commit is contained in:
dhanabalan
2026-05-13 17:41:22 +05:30
parent d19b8120e2
commit 6f93f2bd92
10 changed files with 119 additions and 82 deletions

View File

@@ -948,84 +948,80 @@ function cameraCapture() {
async verifyPhoto() {
if (!this.capturedPhoto) {
alert("Please capture a photo first!");
return;
}
if (!this.capturedPhoto) {
alert("Please capture a photo first!");
return;
}
if (!this.isWorkerReady) {
alert("OCR worker not ready yet!");
return;
}
if (!this.isWorkerReady) {
alert("OCR worker not ready yet!");
return;
}
try {
const img = new Image();
img.src = this.capturedPhoto;
try {
const img = new Image();
img.src = this.capturedPhoto;
img.onload = async () => {
img.onload = async () => {
// Reuse the same temp canvas (no memory leak)
this.tempCanvas.width = img.width;
this.tempCanvas.height = img.height;
this.tempCtx.drawImage(img, 0, 0);
// Reuse the same temp canvas (no memory leak)
this.tempCanvas.width = img.width;
this.tempCanvas.height = img.height;
this.tempCtx.drawImage(img, 0, 0);
// Worker OCR — much faster
const result = await this.ocrWorker.recognize(this.tempCanvas);
// Worker OCR — much faster
const result = await this.ocrWorker.recognize(this.tempCanvas);
const detectedText = result.data.text.trim();
console.log("Detected Text:", detectedText);
const detectedText = result.data.text.trim();
console.log("Detected Text:", detectedText);
// -------------------------------------------------------
// SERIAL EXTRACTION LOGIC — SAME AS YOUR ORIGINAL
// -------------------------------------------------------
const serialWithLabelRegex = /Serial\s*No[:\-]?\s*([A-Za-z0-9]+)/i;
const match = detectedText.match(serialWithLabelRegex);
const serialWithLabelRegex = /Serial\s*No[:\-]?\s*([A-Za-z0-9]+)/i;
const match = detectedText.match(serialWithLabelRegex);
if (match && match[1]) {
// "Serial No: XXXXX"
this.serialNumbers = [match[1].trim()];
console.log("Serial with Label:", this.serialNumbers[0]);
} else {
// Extract first 4 alphanumeric sequences of 4+ chars
const generalNums = detectedText.match(/[A-Za-z0-9]{4,}/g) || [];
this.serialNumbers = generalNums.slice(0, 4);
if (match && match[1]) {
this.serialNumbers = [match[1].trim()];
console.log("Serial with Label:", this.serialNumbers[0]);
}
else
{
const generalNums = detectedText.match(/[A-Za-z0-9]{4,}/g) || [];
this.serialNumbers = generalNums.slice(0, 4);
if (this.serialNumbers.length === 0) {
alert("No serial numbers detected!");
return;
if (this.serialNumbers.length == 0) {
alert("No serial numbers detected!");
return;
}
console.log("Serial Numbers List:", this.serialNumbers);
}
console.log("Serial Numbers List:", this.serialNumbers);
// Save into hidden input (your original logic)
this.$refs.hiddenInputSerials.value = JSON.stringify(this.serialNumbers);
alert("Serial numbers:\n" + this.$refs.hiddenInputSerials.value);
fetch('/save-serials-to-session', {
method: 'POST',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content,
},
body: JSON.stringify({
serial_numbers: this.serialNumbers,
}),
})
.then(response => response.json())
.then(data => {
console.log("Session Updated:", data);
alert("✅ Serial numbers saved to session!");
});
};
} catch (err) {
console.error("OCR verify error:", err);
alert("OCR verify failed:\n" + (err.message || err));
}
// Save into hidden input (your original logic)
this.$refs.hiddenInputSerials.value = JSON.stringify(this.serialNumbers);
alert("Serial numbers:\n" + this.$refs.hiddenInputSerials.value);
fetch('/save-serials-to-session', {
method: 'POST',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content,
},
body: JSON.stringify({
serial_numbers: this.serialNumbers,
}),
})
.then(response => response.json())
.then(data => {
console.log("Session Updated:", data);
alert("✅ Serial numbers saved to session!");
});
};
} catch (err) {
console.error("OCR verify error:", err);
alert("OCR verify failed:\n" + (err.message || err));
}
},
},
startDetection() {
if (this.textDetectionInterval) {