bigbuffet-rw/app/soapbox/features/ads/providers/truth.ts

43 lines
957 B
TypeScript
Raw Normal View History

import axios from 'axios';
2022-10-20 14:29:14 -07:00
import { getSettings } from 'soapbox/actions/settings';
import { normalizeCard } from 'soapbox/normalizers';
import type { AdProvider } from '.';
import type { Card } from 'soapbox/types/entities';
/** TruthSocial ad API entity. */
interface TruthAd {
impression: string,
card: Card,
expires_at: string,
reason: string,
}
/** Provides ads from the TruthSocial API. */
const TruthAdProvider: AdProvider = {
getAds: async(getState) => {
const state = getState();
const settings = getSettings(state);
try {
const { data } = await axios.get<TruthAd[]>('/api/v2/truth/ads?device=desktop', {
headers: {
'Accept-Language': settings.get('locale', '*') as string,
},
});
2022-10-20 14:29:14 -07:00
return data.map(item => ({
...item,
card: normalizeCard(item.card),
}));
} catch (e) {
// do nothing
2022-10-20 14:29:14 -07:00
}
return [];
},
};
export default TruthAdProvider;