import { AdSpotType } from '../runtime'; import type { Niche } from '../runtime'; import { NicheHelper } from './niche-helper'; import { PopunderHelper } from './popunder-helper'; /** Класс для работы с рекламой */ export class AdvertsHelper { /** Метод для получения текущего антиадблок домена */ public static async getAntiAdblockDomain(): Promise { const { state, update } = useAntiadBlockDomains(); if (!state.value.data) { await update(); } return state.value.data || ''; }; /** Метод для спота получения линка преролла по типу спота и нише */ public static async getPrerollVastLink(type: AdSpotType, niche?: Niche): Promise { const defaultValue = ''; if (!useRuntimeConfig().public.featureFlags.AdsPrerollEnabled) { return defaultValue; } const _niche = niche || NicheHelper.getSiteDefaultNiche(); const nicheConfig = useRuntimeConfig().public.adsConfig.Preroll[_niche]; if (nicheConfig) { const domain = await this.getAntiAdblockDomain(); return `https://${domain}/api/spots/${nicheConfig[type]}`; } else { return defaultValue; } } /** Метод для инициализации попандера */ public static async initPopunders(niche?: Niche): Promise { const type = PopunderHelper.hasQueryUtmParams() ? AdSpotType.Primary : AdSpotType.Secondary; if (!useRuntimeConfig().public.featureFlags.AdsPopunderEnabled || import.meta.server) { return; } const _niche = niche || NicheHelper.getSiteDefaultNiche(); const nicheConfig = useRuntimeConfig().public.adsConfig.Popunder[_niche]; if (nicheConfig) { await PopunderHelper.initPopunder(nicheConfig, type); } } /** Метод получения линка для нативки */ public static async initBanners(): Promise { if (!useRuntimeConfig().public.featureFlags.AdsNativeEnabled || import.meta.server) { return; } await BannerHelper.initBanner(); } /** Метод для инициализации рекламного слайдера по нише */ public static async initSlider(niche?: Niche): Promise { if (!useRuntimeConfig().public.featureFlags.AdsSliderEnabled) { return; } const _niche = niche || NicheHelper.getSiteDefaultNiche(); const nicheConfig = useRuntimeConfig().public.adsConfig.Slider[_niche]; await AdvSliderHelper.initSlider(nicheConfig, AdSpotType.Primary); } /** Запуск рекламы */ public static async initAdv() { await Promise.all([ AdvertsHelper.initBanners(), AdvertsHelper.initPopunders(), AdvertsHelper.initSlider(), ]); } }