API POST /thing-translator

Method: POST Path: /thing-translator Controller: src/modules/thing-translator/thing-translator.controller.ts Service: src/modules/thing-translator/thing-translator.service.ts

Purpose

Accepts a base64-encoded image and a target language code, runs Google Cloud Vision label detection on the image to identify the primary object, then returns the detected label translated into the target language. Used by the Currency Lens and Thing Translator features in the iOS app.

Request

Body (ThingTranslateRequestDto):

FieldTypeRequiredDescription
imageBase64stringYesBase64-encoded image bytes (no data-URL prefix)
targetLangstringNoBCP-47 language code (e.g. "th", "ja"); defaults to "en" from config

Validation: ValidationPipe with whitelist: true, forbidNonWhitelisted: true, transform: true — applied globally in main.ts.

Response

200 OK:

{
  "label": "Coffee cup",
  "confidence": 0.9721,
  "translated": "แก้วกาแฟ"
}
FieldTypeDescription
labelstringPrimary label from Google Vision (English)
confidencenumberVision confidence score 0–1
translatedstringlabel translated to targetLang

Error: Throws the raw error from Google Cloud SDK — no custom HTTP status mapping; NestJS default exception filter returns 500.

Flow Diagram

External Dependencies

ServiceClientKey call
Google Cloud VisionGoogleVisionClient (@google-cloud/vision)client.labelDetection(imageBuffer) → first annotation
Google Cloud TranslateGoogleTranslateClient (@google-cloud/translate)client.translateText({ parent, contents, targetLanguageCode })

GCP credentials are resolved via Application Default Credentials (ADC) — no API key in code. projectId and location read from ConfigService (gcp.projectId, gcp.location).