Greenlens/services/plantRecognitionService.ts

25 lines
671 B
TypeScript

import { IdentificationResult, Language } from '../types';
import { backendApiClient } from './backend/backendApiClient';
import { createIdempotencyKey } from '../utils/idempotency';
interface IdentifyOptions {
idempotencyKey?: string;
}
export const PlantRecognitionService = {
identify: async (
imageUri: string,
lang: Language = 'de',
options: IdentifyOptions = {},
): Promise<IdentificationResult> => {
const idempotencyKey = options.idempotencyKey || createIdempotencyKey('scan');
const response = await backendApiClient.scanPlant({
idempotencyKey,
imageUri,
language: lang,
});
return response.result;
},
};