From 1c3c33c72c5bc2af737ae2b053bce49fe9736633 Mon Sep 17 00:00:00 2001 From: alexandre Date: Mon, 22 Jul 2024 19:15:00 +0200 Subject: [PATCH] updat countries --- src/robotoff.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/robotoff.ts b/src/robotoff.ts index ca571e081..a2ec4acd0 100644 --- a/src/robotoff.ts +++ b/src/robotoff.ts @@ -1,6 +1,7 @@ import axios from "axios"; import { ROBOTOFF_API_URL, IS_DEVELOPMENT_MODE, OFF_IMAGE_URL } from "./const"; import { getLang } from "./localeStorageManager"; +import COUNTRIES from "./assets/countries.json"; import { reformatValueTag, removeEmptyKeys } from "./utils"; export interface QuestionInterface { @@ -16,6 +17,13 @@ export interface QuestionInterface { type GetQuestionsResponse = { count: number; questions: QuestionInterface[] }; +function countryId2countryCode(id: string | null) { + if (id === null) { + return null; + } + return COUNTRIES.find((c) => c.id === id)?.countryCode; +} + const robotoff = { annotate(insightId: string, annotation) { if (IS_DEVELOPMENT_MODE) { @@ -64,7 +72,9 @@ const robotoff = { insight_types: insightType, value_tag: valueTag, brands: reformatValueTag(brandFilter), - country: countryFilter !== "en:world" ? countryFilter : null, + countries: countryId2countryCode( + countryFilter !== "en:world" ? countryFilter : null, + ), campaign, predictor, order_by: sortByPopularity ? "popularity" : "random", @@ -227,6 +237,7 @@ const robotoff = { return axios.get( `${ROBOTOFF_API_URL}/questions/unanswered/?${Object.keys({ ...params, + countries: countryId2countryCode(params.country), page, }) .filter((key) => params[key] !== undefined)