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 changed files with 21 additions and 12 deletions
|
@ -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 [];
|
||||
},
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue