Merge branch 'ads-locale' into 'develop'
RumbleAdProvider: send Accept-Language header with request See merge request soapbox-pub/soapbox-fe!1715
This commit is contained in:
commit
70a84d74ad
|
@ -1,3 +1,4 @@
|
||||||
|
import { getSettings } from 'soapbox/actions/settings';
|
||||||
import { getSoapboxConfig } from 'soapbox/actions/soapbox';
|
import { getSoapboxConfig } from 'soapbox/actions/soapbox';
|
||||||
import { normalizeCard } from 'soapbox/normalizers';
|
import { normalizeCard } from 'soapbox/normalizers';
|
||||||
|
|
||||||
|
@ -22,11 +23,18 @@ interface RumbleApiResponse {
|
||||||
const RumbleAdProvider: AdProvider = {
|
const RumbleAdProvider: AdProvider = {
|
||||||
getAds: async(getState) => {
|
getAds: async(getState) => {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
|
const settings = getSettings(state);
|
||||||
const soapboxConfig = getSoapboxConfig(state);
|
const soapboxConfig = getSoapboxConfig(state);
|
||||||
const endpoint = soapboxConfig.extensions.getIn(['ads', 'endpoint']) as string | undefined;
|
const endpoint = soapboxConfig.extensions.getIn(['ads', 'endpoint']) as string | undefined;
|
||||||
|
|
||||||
if (endpoint) {
|
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;
|
const data = await response.json() as RumbleApiResponse;
|
||||||
return data.ads.map(item => ({
|
return data.ads.map(item => ({
|
||||||
impression: item.impression,
|
impression: item.impression,
|
||||||
|
@ -36,9 +44,10 @@ const RumbleAdProvider: AdProvider = {
|
||||||
url: item.click,
|
url: item.click,
|
||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
} else {
|
|
||||||
return [];
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue