31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import { logResource } from '@/service';
|
|
import axios from 'axios';
|
|
import { MarketType } from "../type";
|
|
import { PriceGetter } from './MarketTypePrice';
|
|
|
|
export const evepraisalAxiosInstance = axios.create({
|
|
baseURL: import.meta.env.VITE_EVEPRAISAL_URL,
|
|
headers: {
|
|
'accept': 'application/json',
|
|
"Content-Type": "application/json"
|
|
},
|
|
})
|
|
logResource(evepraisalAxiosInstance)
|
|
|
|
const batchSize = 100;
|
|
|
|
export const getEvepraisalPrices: PriceGetter = async types => {
|
|
const batches = [];
|
|
|
|
for (let i = 0; i < types.length; i += batchSize) {
|
|
batches.push(evepraisalAxiosInstance.post(`/appraisal.json?market=jita&persist=no&raw_textarea=${types.slice(i, i + batchSize).map(t => t.name).join("%0A")}`));
|
|
}
|
|
return (await Promise.all(batches))
|
|
.flatMap(b => b.data.appraisal.items)
|
|
.map((item: any) => ({
|
|
type: types.find(t => t.name === item.typeName) as MarketType,
|
|
buy: item.prices.buy.max,
|
|
sell: item.prices.sell.min,
|
|
orderCount: item.prices.all.order_count
|
|
}));
|
|
}; |