Files
poe-auto-pricer/app/services/poe.service.ts

45 lines
1.2 KiB
TypeScript

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<any> => {
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<any> => {
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<any> => {
const res = await http.get(POE_HOME);
const username = res.data.match(/\/account\/view-profile\/(.*?)\"/);
return username[1];
};
const getLeagues = async (): Promise<any> => {
const res = await http.get(POE_LEAGUE_LIST_URL);
return res.data;
};
export const PoeService = {
getLeagues,
getStash,
getUsername,
priceCheck,
};