Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,6 @@ export class AiImportPhotoGalleryComponent {
});

if (imageData?.base64String) {
this.uiLog.log(
`AI Import Gallery: Camera returned base64, length: ${imageData.base64String.length}, format: ${imageData.format}`,
);

// Save to internal storage
const fileName = await this.uiFileHelper.generateInternalPath(
'photo',
Expand All @@ -152,9 +148,6 @@ export class AiImportPhotoGalleryComponent {

if (fileUri.path) {
this.photoPaths.push(fileUri.path);
this.uiLog.log(
`AI Import Gallery: Saved photo to ${fileUri.path}, total now: ${this.photoPaths.length}`,
);
this.updateSlider();

// Slide to the newly added photo
Expand Down Expand Up @@ -210,9 +203,6 @@ export class AiImportPhotoGalleryComponent {

if (fileUri.path) {
this.photoPaths.push(fileUri.path);
this.uiLog.log(
`AI Import Gallery: Clipboard image saved to ${fileUri.path}, total now: ${this.photoPaths.length}`,
);
this.updateSlider();
this.focusOnNewPhoto();
}
Expand Down
2 changes: 1 addition & 1 deletion src/data/ai-import/ai-cloud-prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Use "NOT_FOUND" for any field not clearly present.
"aromatics": "Comma-separated flavor/tasting notes",
"decaffeinated": true or false,
"cupping_points": numeric score (typically 80-100),
"roasting_date": "YYYY-MM-DD (use today's date to resolve ambiguous date formatsthe roasting date is most likely within the past year and never in the future)",
"roasting_date": "YYYY-MM-DD — the roasting date. Use today's date to resolve ambiguous date formats. If no explicit roast date is found but the label states a best-before/use-by/expiration date AND explicitly states the time between roasting and that date (e.g., 'roasted 12 months before best before date' — note this may be stated in the local language of the label), calculate the roast date by subtracting the stated period from the best-before date. The roasting date is most likely within the past year and never in the future. NOT_FOUND if neither an explicit roast date nor a calculable one is present.",
"bean_mix": "SINGLE_ORIGIN or BLEND",
"origins": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,7 @@ describe('CloudFieldExtractionService', () => {
await service.extractAllFields('sample OCR text', mockConfig, mockLogger);

// Assert
expect(mockLogger.log).toHaveBeenCalledWith(
'Cloud LLM response received, model: gpt-4o',
);
expect(mockLogger.log).toHaveBeenCalledWith('[Cloud LLM] model: gpt-4o');
expect(mockLogger.log).toHaveBeenCalledWith(
'Token usage: 100 prompt, 50 completion',
);
Expand Down
48 changes: 48 additions & 0 deletions src/services/aiBeanImport/__tests__/image-rotation.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { rotateBase64Image } from '../image-rotation';

/**
* Create a small non-square test JPEG as raw base64 using the browser Canvas API.
* Returns a 4×2 red image so rotation visibly swaps dimensions.
*/
function createTestJpegBase64(width = 4, height = 2): string {
const canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext('2d')!;
ctx.fillStyle = '#ff0000';
ctx.fillRect(0, 0, width, height);
const dataUrl = canvas.toDataURL('image/jpeg', 0.92);
return dataUrl.replace(/^data:image\/jpeg;base64,/, '');
}

describe('rotateBase64Image', () => {
let testBase64: string;

beforeAll(() => {
testBase64 = createTestJpegBase64();
});

[90, 270].forEach((degrees) => {
it(`should swap dimensions of a 4×2 image to 2×4 and return raw base64 when rotated by ${degrees}°`, async () => {
const result = await rotateBase64Image(testBase64, degrees as 90 | 270);
expect(result).toBeTruthy();
expect(result).not.toContain('data:image/jpeg;base64,');

const img = await new Promise<HTMLImageElement>((resolve, reject) => {
const image = new Image();
image.onload = () => resolve(image);
image.onerror = () => reject(new Error('Failed to load rotated image'));
image.src = `data:image/jpeg;base64,${result}`;
});

expect(img.naturalWidth).toBe(2);
expect(img.naturalHeight).toBe(4);
});
});

it('should reject with an error when given invalid base64', async () => {
await expectAsync(
rotateBase64Image('not-a-valid-image!!!', 90),
).toBeRejectedWithError('Failed to load image for rotation');
});
});
Loading
Loading