MCPcopy Create free account
hub / github.com/dailydotdev/apps / fetchAdByPlacement

Function fetchAdByPlacement

packages/shared/src/lib/ads.ts:94–129  ·  view source on GitHub ↗
({
  placement,
  active = false,
  allowPostBoost = false,
  allowSquadBoost = false,
}: FetchAdByPlacementOptions)

Source from the content-addressed store, hash-verified

92};
93
94export const fetchAdByPlacement = async ({
95 placement,
96 active = false,
97 allowPostBoost = false,
98 allowSquadBoost = false,
99}: FetchAdByPlacementOptions): Promise<Ad | null> => {
100 switch (placement) {
101 case AdPlacement.PostComment:
102 return fetchAdRequest({ path: '/v1/a/post' });
103 case AdPlacement.SquadDirectory: {
104 const params = new URLSearchParams();
105 if (allowSquadBoost) {
106 params.set('allow_squad_boost', 'true');
107 }
108
109 return fetchAdRequest({ path: '/v1/a/squads_directory', params });
110 }
111 case AdPlacement.PostSidebar:
112 case AdPlacement.Feed:
113 default: {
114 const params = new URLSearchParams({
115 active: active ? 'true' : 'false',
116 });
117
118 if (allowPostBoost) {
119 params.append('allow_post_boost', 'true');
120 }
121
122 if (allowSquadBoost) {
123 params.append('allow_squad_boost', 'true');
124 }
125
126 return fetchAdRequest({ path: '/v1/a', params });
127 }
128 }
129};
130
131export const fetchAd = async (params: URLSearchParams): Promise<Ad | null> =>
132 fetchAdRequest({ path: '/v1/a', params });

Callers 5

ads.spec.tsFile · 0.90
useAdQueryFunction · 0.90
useFetchAdFunction · 0.90
fetchCommentAdFunction · 0.85
fetchDirectoryAdFunction · 0.85

Calls 1

fetchAdRequestFunction · 0.85

Tested by

no test coverage detected