import _ from 'lodash' ; import EmotesProvider , { Emote , EmoteProviderPrefix } from 'libs/EmotesProvider' ; /**
 * Ffz base API URL.
 */ const baseAPIUrl = 'https://api.frankerfacez.com/v1' ; /**
 * Ffz class.
 */ export default class Ffz { param channel return public static async fetchEmotes ( channel ) { const response = await Promise . all ( [ ( await Ffz . fetch ( `${ baseAPIUrl }/set/global` ) ) . json ( ) , ( await Ffz . fetch ( `${ baseAPIUrl }/room/${ channel }` ) ) . json ( ) , ] ) ; const [ globalResponse , channelResponse ] = response ; const rawEmotes = _ . reduce ( globalResponse . default_sets , ( acc , setId ) => { acc . push ( ... globalResponse . sets [ setId ] . emoticons ) ; return acc ; } , [ ] as FfzRawEmote [ ] ) ; const isChannelRegistered = ! _ . has ( channelResponse , 'error' ) && _ . has ( channelResponse , 'sets' ) ; if ( isChannelRegistered ) { _ . forEach ( channelResponse . sets , ( set ) => { rawEmotes . push ( ... set . emoticons ) ; } ) ; } return new EmotesProvider ( EmoteProviderPrefix . Ffz , Ffz . sanitizeRawEmotes ( rawEmotes ) ) ; } param rawEmotes return private static sanitizeRawEmotes ( rawEmotes ) { return _ . map ( rawEmotes , ( { id , name , urls , width } ) => { return { code : name , id : id . toString ( ) , urls , width , } ; } ) ; } param url return private static fetch ( url ) { const headers = new Headers ( { Accept : 'application/json' , } ) ; const request = new Request ( url , { headers } ) ; return fetch ( request ) ; } } /**
 * Ffz emote URLs.
 */ interface FfzEmoteUrls { 1 : string ; 2 ? : string ; 4 ? : string ; } /**
 * Ffz emote.
 */ export interface FfzEmote extends Emote { urls : FfzEmoteUrls ; width : number ; } /**
 * Ffz raw emote returned by the API.
 */ interface FfzRawEmote { id : number ; name : string ; urls : FfzEmoteUrls ; width : number ; }