From f68730de20095db1da7371865af214ce8a37da51 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 8 Aug 2022 16:17:56 -0500 Subject: [PATCH] RumbleAdProvider: send Accept-Language header with request --- app/soapbox/features/ads/providers/rumble.ts | 33 +++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/app/soapbox/features/ads/providers/rumble.ts b/app/soapbox/features/ads/providers/rumble.ts index b39ee4cc9..249fc8547 100644 --- a/app/soapbox/features/ads/providers/rumble.ts +++ b/app/soapbox/features/ads/providers/rumble.ts @@ -1,3 +1,4 @@ +import { getSettings } from 'soapbox/actions/settings'; import { getSoapboxConfig } from 'soapbox/actions/soapbox'; import { normalizeCard } from 'soapbox/normalizers'; @@ -22,23 +23,31 @@ interface RumbleApiResponse { const RumbleAdProvider: AdProvider = { getAds: async(getState) => { const state = getState(); + const settings = getSettings(state); const soapboxConfig = getSoapboxConfig(state); const endpoint = soapboxConfig.extensions.getIn(['ads', 'endpoint']) as string | undefined; if (endpoint) { - const response = await fetch(endpoint); - const data = await response.json() as RumbleApiResponse; - return data.ads.map(item => ({ - impression: item.impression, - card: normalizeCard({ - type: item.type === 1 ? 'link' : 'rich', - image: item.asset, - url: item.click, - }), - })); - } else { - return []; + const response = await fetch(endpoint, { + headers: { + 'Accept-Language': settings.get('locale', '*') as string, + }, + }); + + if (response.ok) { + const data = await response.json() as RumbleApiResponse; + return data.ads.map(item => ({ + impression: item.impression, + card: normalizeCard({ + type: item.type === 1 ? 'link' : 'rich', + image: item.asset, + url: item.click, + }), + })); + } } + + return []; }, };