RumbleAdProvider: send Accept-Language header with request

This commit is contained in:
Alex Gleason 2022-08-08 16:17:56 -05:00
parent 636e0d9eff
commit f68730de20
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -1,3 +1,4 @@
import { getSettings } from 'soapbox/actions/settings';
import { getSoapboxConfig } from 'soapbox/actions/soapbox';
import { normalizeCard } from 'soapbox/normalizers';
@ -22,11 +23,18 @@ 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 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,
@ -36,9 +44,10 @@ const RumbleAdProvider: AdProvider = {
url: item.click,
}),
}));
} else {
return [];
}
}
return [];
},
};