Skip to content

Commit 0cc1152

Browse files
authored
TW-1251: Add API entries for permanent ads (#140)
1 parent 007cc24 commit 0cc1152

File tree

4 files changed

+372
-4
lines changed

4 files changed

+372
-4
lines changed

src/advertising/slise.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,29 @@ export interface SliseAdPlacesRule {
8989
stylesOverrides?: SliseAdStylesOverrides[];
9090
}
9191

92+
export interface PermanentSliseAdPlacesRule {
93+
urlRegexes: string[];
94+
adSelector: {
95+
isMultiple: boolean;
96+
cssString: string;
97+
parentDepth: number;
98+
};
99+
parentSelector: {
100+
isMultiple: boolean;
101+
cssString: string;
102+
parentDepth: number;
103+
};
104+
insertionIndex?: number;
105+
insertBeforeSelector?: string;
106+
insertAfterSelector?: string;
107+
insertionsCount?: number;
108+
shouldUseDivWrapper: boolean;
109+
divWrapperStyle?: Record<StylePropName, string>;
110+
elementToMeasureSelector?: string;
111+
stylesOverrides?: SliseAdStylesOverrides[];
112+
shouldHideOriginal?: boolean;
113+
}
114+
92115
export interface SliseAdProvidersByDomainRule {
93116
urlRegexes: string[];
94117
providers: string[];
@@ -98,6 +121,7 @@ const SLISE_AD_PLACES_RULES_KEY = 'slise_ad_places_rules';
98121
const SLISE_AD_PROVIDERS_BY_SITES_KEY = 'slise_ad_providers_by_sites';
99122
const SLISE_AD_PROVIDERS_ALL_SITES_KEY = 'slise_ad_providers_all_sites';
100123
const SLISE_AD_PROVIDERS_LIST_KEY = 'slise_ad_providers_list';
124+
const PERMANENT_SLISE_AD_PLACES_RULES_KEY = 'permanent_slise_ad_places_rules';
101125

102126
export const {
103127
getByKey: getSliseAdPlacesRulesByDomain,
@@ -120,6 +144,13 @@ export const {
120144
removeValues: removeProviders
121145
} = objectStorageMethodsFactory<string[]>(SLISE_AD_PROVIDERS_LIST_KEY, []);
122146

147+
export const {
148+
getByKey: getPermanentSliseAdPlacesRulesByDomain,
149+
getAllValues: getAllPermanentSliseAdPlacesRules,
150+
upsertValues: upsertPermanentSliseAdPlacesRules,
151+
removeValues: removePermanentSliseAdPlacesRules
152+
} = objectStorageMethodsFactory<PermanentSliseAdPlacesRule[]>(PERMANENT_SLISE_AD_PLACES_RULES_KEY, []);
153+
123154
export const getSliseAdProvidersForAllSites = async () => redisClient.smembers(SLISE_AD_PROVIDERS_ALL_SITES_KEY);
124155

125156
export const addSliseAdProvidersForAllSites = async (providers: string[]) =>

src/routers/slise-ad-rules/ad-places.ts

Lines changed: 256 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
import { Router } from 'express';
22

33
import {
4+
getAllPermanentSliseAdPlacesRules,
45
getAllSliseAdPlacesRules,
6+
getPermanentSliseAdPlacesRulesByDomain,
57
getSliseAdPlacesRulesByDomain,
8+
removePermanentSliseAdPlacesRules,
69
removeSliseAdPlacesRules,
10+
upsertPermanentSliseAdPlacesRules,
711
upsertSliseAdPlacesRules
812
} from '../../advertising/slise';
913
import { addObjectStorageMethodsToRouter } from '../../utils/express-helpers';
10-
import { hostnamesListSchema, sliseAdPlacesRulesDictionarySchema } from '../../utils/schemas';
14+
import {
15+
hostnamesListSchema,
16+
permanentSliseAdPlacesRulesDictionarySchema,
17+
sliseAdPlacesRulesDictionarySchema
18+
} from '../../utils/schemas';
1119

1220
/**
1321
* @swagger
22+
* tags:
23+
* name: Slise ad places
1424
* components:
1525
* schemas:
1626
* SliseAdPlacesRuleSelector:
@@ -115,15 +125,254 @@ import { hostnamesListSchema, sliseAdPlacesRulesDictionarySchema } from '../../u
115125
* cssString: 'div.left-container > app-pe-banner:nth-child(2)'
116126
* parentDepth: 0
117127
* shouldUseDivWrapper: true
128+
* PermanentSliseAdPlacesRule:
129+
* type: object
130+
* description: >
131+
* This object describes rules of replacing ads banners if they are found and inserting new ads banners if
132+
* they are not found. Exactly one of `insertionIndex`, `insertBeforeSelector` and `insertAfterSelector`
133+
* properties must be specified.
134+
* required:
135+
* - urlRegexes
136+
* - adSelector
137+
* - parentSelector
138+
* - shouldUseDivWrapper
139+
* properties:
140+
* urlRegexes:
141+
* type: array
142+
* items:
143+
* type: string
144+
* format: regex
145+
* adSelector:
146+
* type: object
147+
* description: >
148+
* This object describes rules of selecting ads banners in the parents of new ads banners selected
149+
* according to the rules described in the `parentSelector` property.
150+
* required:
151+
* - isMultiple
152+
* - cssString
153+
* - parentDepth
154+
* properties:
155+
* isMultiple:
156+
* type: boolean
157+
* description: Whether the selector should return multiple elements
158+
* cssString:
159+
* type: string
160+
* description: CSS selector
161+
* parentDepth:
162+
* type: number
163+
* min: 0
164+
* integer: true
165+
* description: >
166+
* Indicates the depth of the parent element of the selected element, i. e. 0 means that the selected
167+
* elements are ads banners themselves, 1 means that the selected elements are ads banners' direct
168+
* children and so on.
169+
* parentSelector:
170+
* type: object
171+
* required:
172+
* - isMultiple
173+
* - cssString
174+
* - parentDepth
175+
* properties:
176+
* isMultiple:
177+
* type: boolean
178+
* description: Whether the selector should return multiple elements
179+
* cssString:
180+
* type: string
181+
* description: CSS selector
182+
* parentDepth:
183+
* type: number
184+
* min: 0
185+
* integer: true
186+
* description: >
187+
* Indicates the depth of the parent element of the selected element, i. e. 0 means that the selected
188+
* elements are parents of new ads banners themselves, 1 means that the selected elements are their
189+
* direct children and so on.
190+
* insertionIndex:
191+
* type: number
192+
* integer: true
193+
* description: >
194+
* Describes where to insert new ads banners in the selected parents of new ads banners in case if original
195+
* ads banners are not found. If the value is negative, the insertion index will be calculated from the end.
196+
* The counting starts from 0.
197+
* insertBeforeSelector:
198+
* type: string
199+
* description: A selector for the element before which new ads banners should be inserted
200+
* insertAfterSelector:
201+
* type: string
202+
* description: A selector for the element after which new ads banners should be inserted
203+
* insertionsCount:
204+
* type: number
205+
* integer: true
206+
* min: 1
207+
* default: 1
208+
* description: >
209+
* Describes how many new ads banners should be inserted in case if original ads banners are not found.
210+
* shouldUseDivWrapper:
211+
* type: boolean
212+
* description: Whether the Slise ads banner should be wrapped in a div
213+
* divWrapperStyle:
214+
* type: object
215+
* description: Style of the div wrapper
216+
* additionalProperties:
217+
* type: string
218+
* elementToMeasureSelector:
219+
* type: string
220+
* description: A selector of the element which should be measured to define banner size
221+
* stylesOverrides:
222+
* type: array
223+
* items:
224+
* $ref: '#/components/schemas/SliseAdStylesOverrides'
225+
* shouldHideOriginal:
226+
* type: boolean
227+
* description: Whether original ads banners should be hidden but not removed
228+
* default: false
229+
* example:
230+
* urlRegexes:
231+
* - '^https://etherscan\.io/tx/'
232+
* adSelector:
233+
* isMultiple: false
234+
* cssString: '.coinzilla'
235+
* parentDepth: 0
236+
* parentSelector:
237+
* isMultiple: false
238+
* cssString: '#ContentPlaceHolder1_maintable > * > .row:nth-child(8) > :nth-child(2) > * > *'
239+
* parentDepth: 0
240+
* insertionIndex: 0
241+
* shouldUseDivWrapper: false
242+
* PermanentSliseAdPlacesRulesDictionary:
243+
* type: object
244+
* additionalProperties:
245+
* type: array
246+
* items:
247+
* $ref: '#/components/schemas/PermanentSliseAdPlacesRule'
248+
* example:
249+
* etherscan.io:
250+
* - urlRegexes:
251+
* - '^https://etherscan\.io/tx/'
252+
* adSelector:
253+
* isMultiple: false
254+
* cssString: '.coinzilla'
255+
* parentDepth: 0
256+
* parentSelector:
257+
* isMultiple: false
258+
* cssString: '#ContentPlaceHolder1_maintable > * > .row:nth-child(8) > :nth-child(2) > * > *'
259+
* parentDepth: 0
260+
* insertionIndex: 0
261+
* shouldUseDivWrapper: false
118262
*/
119263

120264
export const sliseAdPlacesRulesRouter = Router();
121265

266+
/**
267+
* @swagger
268+
* /api/slise-ad-rules/ad-places/permanent/{domain}:
269+
* get:
270+
* summary: Get rules for permanent ads places for the specified domain
271+
* tags:
272+
* - Slise ad places
273+
* parameters:
274+
* - in: path
275+
* name: domain
276+
* required: true
277+
* schema:
278+
* type: string
279+
* format: hostname
280+
* example: 'etherscan.io'
281+
* responses:
282+
* '200':
283+
* description: Rules list
284+
* content:
285+
* application/json:
286+
* schema:
287+
* type: array
288+
* items:
289+
* $ref: '#/components/schemas/PermanentSliseAdPlacesRule'
290+
* '500':
291+
* $ref: '#/components/responses/ErrorResponse'
292+
* /api/slise-ad-rules/ad-places/permanent:
293+
* get:
294+
* summary: Get all rules for permanent ads places
295+
* tags:
296+
* - Slise ad places
297+
* responses:
298+
* '200':
299+
* description: Domain - rules list dictionary
300+
* content:
301+
* application/json:
302+
* schema:
303+
* $ref: '#/components/schemas/PermanentSliseAdPlacesRulesDictionary'
304+
* '500':
305+
* $ref: '#/components/responses/ErrorResponse'
306+
* post:
307+
* summary: Add rules for permanent ads places. If rules for a domain already exist, they will be overwritten
308+
* tags:
309+
* - Slise ad places
310+
* security:
311+
* - basicAuth: []
312+
* requestBody:
313+
* description: Domain - rules list dictionary
314+
* content:
315+
* application/json:
316+
* schema:
317+
* $ref: '#/components/schemas/PermanentSliseAdPlacesRulesDictionary'
318+
* responses:
319+
* '200':
320+
* $ref: '#/components/responses/SuccessResponse'
321+
* '400':
322+
* $ref: '#/components/responses/ErrorResponse'
323+
* '401':
324+
* $ref: '#/components/responses/UnauthorizedError'
325+
* '500':
326+
* $ref: '#/components/responses/ErrorResponse'
327+
* delete:
328+
* summary: Remove rules for permanent ads places
329+
* tags:
330+
* - Slise ad places
331+
* security:
332+
* - basicAuth: []
333+
* requestBody:
334+
* description: List of domain names to remove rules for
335+
* content:
336+
* application/json:
337+
* schema:
338+
* type: array
339+
* items:
340+
* type: string
341+
* format: hostname
342+
* example:
343+
* - 'etherscan.io'
344+
* responses:
345+
* '200':
346+
* $ref: '#/components/responses/SuccessResponse'
347+
* '400':
348+
* $ref: '#/components/responses/ErrorResponse'
349+
* '401':
350+
* $ref: '#/components/responses/UnauthorizedError'
351+
* '500':
352+
* $ref: '#/components/responses/ErrorResponse'
353+
*/
354+
addObjectStorageMethodsToRouter(
355+
sliseAdPlacesRulesRouter,
356+
'/permanent',
357+
{
358+
getByKey: getPermanentSliseAdPlacesRulesByDomain,
359+
getAllValues: getAllPermanentSliseAdPlacesRules,
360+
upsertValues: upsertPermanentSliseAdPlacesRules,
361+
removeValues: removePermanentSliseAdPlacesRules
362+
},
363+
'domain',
364+
permanentSliseAdPlacesRulesDictionarySchema,
365+
hostnamesListSchema,
366+
entriesCount => `${entriesCount} entries have been removed`
367+
);
368+
122369
/**
123370
* @swagger
124371
* /api/slise-ad-rules/ad-places/{domain}:
125372
* get:
126373
* summary: Get rules for ads places for the specified domain
374+
* tags:
375+
* - Slise ad places
127376
* parameters:
128377
* - in: path
129378
* name: domain
@@ -146,6 +395,8 @@ export const sliseAdPlacesRulesRouter = Router();
146395
* /api/slise-ad-rules/ad-places:
147396
* get:
148397
* summary: Get all rules for ads places
398+
* tags:
399+
* - Slise ad places
149400
* responses:
150401
* '200':
151402
* description: Domain - rules list dictionary
@@ -157,6 +408,8 @@ export const sliseAdPlacesRulesRouter = Router();
157408
* $ref: '#/components/responses/ErrorResponse'
158409
* post:
159410
* summary: Add rules for ads places. If rules for a domain already exist, they will be overwritten
411+
* tags:
412+
* - Slise ad places
160413
* security:
161414
* - basicAuth: []
162415
* requestBody:
@@ -176,6 +429,8 @@ export const sliseAdPlacesRulesRouter = Router();
176429
* $ref: '#/components/responses/ErrorResponse'
177430
* delete:
178431
* summary: Remove rules for ads places
432+
* tags:
433+
* - Slise ad places
179434
* security:
180435
* - basicAuth: []
181436
* requestBody:

0 commit comments

Comments
 (0)