11import { Router } from 'express' ;
22
33import {
4+ getAllPermanentSliseAdPlacesRules ,
45 getAllSliseAdPlacesRules ,
6+ getPermanentSliseAdPlacesRulesByDomain ,
57 getSliseAdPlacesRulesByDomain ,
8+ removePermanentSliseAdPlacesRules ,
69 removeSliseAdPlacesRules ,
10+ upsertPermanentSliseAdPlacesRules ,
711 upsertSliseAdPlacesRules
812} from '../../advertising/slise' ;
913import { 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
120264export 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