import PQueue from 'p-queue'; import { POE_HOME, POE_LEAGUE_LIST_URL, POE_STASH_ITEMS_URL } from '../constants'; import { http } from '../http'; const queue = new PQueue({ concurrency: 1 }); const getStash = async (username: string, league: string, tabIndex: number | string): Promise => { const res = await http.get( `${POE_STASH_ITEMS_URL}?league=${league}&tabs=1&tabIndex=${tabIndex}&accountName=${username}`, ); return res.data; }; const priceCheck = async (item: any): Promise => { return new Promise(resolve => { queue.add(() => { return http .get(`https://poeprices.info/api?l=Incursion&i=${encodeURI(btoa(item))}`, { headers: { 'Cache-Control': 'max-age=600', }, }) .then(resolve); }); }); }; const getUsername = async (): Promise => { const res = await http.get(POE_HOME); const username = res.data.match(/\/account\/view-profile\/(.*?)\"/); return username[1]; }; const getLeagues = async (): Promise => { const res = await http.get(POE_LEAGUE_LIST_URL); return res.data; }; export const PoeService = { getLeagues, getStash, getUsername, priceCheck, };