Refactor: Complete barcodeImage removal and hub3aText migration
This commit completes the migration from storing bitmap barcodes to using decoded HUB-3A text strings, removing all legacy code while maintaining backward compatibility during the transition period. Database & Server Actions: - billActions: Removed commented legacy barcodeImage code - locationActions: Updated field references in projections - monthActions: Use hub3aText when copying bills to new months - printActions: Support both hub3aText and barcodeImage during migration - Added @deprecated annotation to barcodeImage field - Filter includes bills with either field - Pass both fields to support gradual migration Barcode Decoder: - Removed barcodeImage field from DecodeResult type - Deleted copyBarcodeImage() function (58 lines) - No longer generating bitmaps during decode - Barcodes now generated on-demand from hub3aText - Cleaner separation: decoder extracts text, component renders barcode UI Components: - Pdf417Barcode: Added optional className prop for styling flexibility - Removed unnecessary wrapper div - Conditional styling (use className or default dimensions) - PrintPreview: Use Pdf417Barcode component with fallback to legacy barcodeImage - ViewBillCard: Major cleanup and migration support - Removed unused imports (React, updateOrAddBill, useLocale) - Removed unused middleware function - Removed unused variables and hidden input - Prefer hub3aText with Pdf417Barcode, fallback to barcodeImage - Clear legacy support comments Migration Strategy: All rendering code now follows the pattern: 1. Prefer hub3aText (new field) when available 2. Fallback to barcodeImage (legacy field) if needed 3. Clear comments marking legacy support code 4. Allows gradual migration without breaking existing bills Benefits: - More efficient storage (text vs base64 bitmap) - Barcodes generated on-demand (not stored) - Cleaner, more maintainable code - Consistent use of Pdf417Barcode component - Removed ~60 lines of unused code 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -206,7 +206,6 @@ const pdf2canvas = async function (pdfFile:File): Promise<Array<HTMLCanvasElemen
|
||||
export type DecodeResult = {
|
||||
hub3aText: string,
|
||||
billInfo: BillInfo,
|
||||
barcodeImage: string,
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -278,7 +277,6 @@ const decodeFromCanvas = async (canvas:HTMLCanvasElement): Promise<Array<DecodeR
|
||||
codesFoundInSection.push({
|
||||
hub3aText,
|
||||
billInfo: parseHubText(hub3aText),
|
||||
barcodeImage: copyBarcodeImage(sectionCanvas, result)
|
||||
});
|
||||
}
|
||||
|
||||
@@ -311,58 +309,6 @@ const decodeFromCanvas = async (canvas:HTMLCanvasElement): Promise<Array<DecodeR
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies bar code from the given canvas
|
||||
*
|
||||
*/
|
||||
const copyBarcodeImage = (canvas:HTMLCanvasElement, decoderResult:Result):string => {
|
||||
|
||||
// get coordinates of bar code
|
||||
const points = decoderResult.getResultPoints();
|
||||
|
||||
// get outter coordinates of the bar code
|
||||
const codeLocation = points.reduce((acc, point) => {
|
||||
|
||||
const x = point.getX();
|
||||
const y = point.getY();
|
||||
let result = {
|
||||
top: y < acc.top ? y: acc.top,
|
||||
left: x < acc.left ? x: acc.left,
|
||||
bottom: y > acc.bottom ? y: acc.bottom,
|
||||
right: x > acc.right ? x: acc.right
|
||||
};
|
||||
|
||||
return({
|
||||
...result,
|
||||
width: result.right - result.left,
|
||||
height: result.bottom - result.top,
|
||||
});
|
||||
}, {
|
||||
top: Number.MAX_SAFE_INTEGER,
|
||||
left: Number.MAX_SAFE_INTEGER,
|
||||
bottom: 0,
|
||||
right: 0,
|
||||
width: 0,
|
||||
height: 0
|
||||
});
|
||||
|
||||
// copy section of the canvas containing bar code to another canvas
|
||||
const tempCanvas = document.createElement('canvas');
|
||||
const tempContext = tempCanvas.getContext('2d');
|
||||
|
||||
tempCanvas.width = codeLocation.width;
|
||||
tempCanvas.height = codeLocation.height;
|
||||
|
||||
// Draw the portion of the original canvas onto the temporary canvas
|
||||
// Assuming you want to copy a 100x100 pixels square starting from (50, 50) of the original canvas
|
||||
tempContext?.drawImage(canvas, codeLocation.left, codeLocation.top, codeLocation.width, codeLocation.height, 0, 0, codeLocation.width, codeLocation.height);
|
||||
|
||||
// Convert the temporary canvas to a data URL
|
||||
const dataURL = tempCanvas.toDataURL();
|
||||
|
||||
return(dataURL);
|
||||
}
|
||||
|
||||
/** Finds PDF417 code within a base64 encoded image and decodes it */
|
||||
export const decodeFromImage = async (imageBase64:string): Promise<DecodeResult[]|null> => {
|
||||
return(await decodeFromCanvas( await image2canvas(imageBase64) ));
|
||||
|
||||
Reference in New Issue
Block a user