extract evepraisal from apraisal
This commit is contained in:
11
src/market/appraisal/MarketTypePrice.ts
Normal file
11
src/market/appraisal/MarketTypePrice.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { MarketType } from "../type";
|
||||
|
||||
|
||||
export type MarketTypePrice = {
|
||||
type: MarketType;
|
||||
buy: number;
|
||||
sell: number;
|
||||
orderCount: number;
|
||||
};
|
||||
|
||||
export type PriceGetter = (types: MarketType[]) => Promise<MarketTypePrice[]>;
|
||||
@@ -1,14 +1,8 @@
|
||||
import { evepraisalAxiosInstance } from '@/service';
|
||||
import { defineStore } from 'pinia';
|
||||
import { ref } from 'vue';
|
||||
import { MarketType } from "./type";
|
||||
|
||||
export type MarketTypePrice = {
|
||||
type: MarketType;
|
||||
buy: number,
|
||||
sell: number,
|
||||
orderCount: number
|
||||
}
|
||||
import { MarketType } from "../type";
|
||||
import { MarketTypePrice } from './MarketTypePrice';
|
||||
import { getEvepraisalPrices } from './evepraisal';
|
||||
|
||||
type MarketTypePriceCache = {
|
||||
price: MarketTypePrice,
|
||||
@@ -16,26 +10,11 @@ type MarketTypePriceCache = {
|
||||
}
|
||||
|
||||
const cacheDuration = 1000 * 60 * 5; // 5 minutes
|
||||
const batchSize = 100;
|
||||
|
||||
export const useApraisalStore = defineStore('appraisal', () => {
|
||||
const cache = ref<Record<number, MarketTypePriceCache>>({});
|
||||
|
||||
const getPricesUncached = async (types: MarketType[]): Promise<MarketTypePrice[]> => {
|
||||
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
|
||||
}));
|
||||
}
|
||||
const getPricesUncached = getEvepraisalPrices;
|
||||
|
||||
const getPrice = async (type: MarketType): Promise<MarketTypePrice> => (await getPrices([type]))[0];
|
||||
const getPrices = async (types: MarketType[]): Promise<MarketTypePrice[]> => {
|
||||
21
src/market/appraisal/evepraisal.ts
Normal file
21
src/market/appraisal/evepraisal.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { evepraisalAxiosInstance } from '@/service';
|
||||
import { MarketType } from "../type";
|
||||
import { MarketTypePrice, PriceGetter } from './MarketTypePrice';
|
||||
|
||||
const batchSize = 100;
|
||||
|
||||
export const getEvepraisalPrices: PriceGetter = async (types: MarketType[]): Promise<MarketTypePrice[]> => {
|
||||
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
|
||||
}));
|
||||
};
|
||||
2
src/market/appraisal/index.ts
Normal file
2
src/market/appraisal/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from './MarketTypePrice';
|
||||
export * from './appraisal';
|
||||
@@ -44,7 +44,7 @@ marbasAxiosInstance.interceptors.response.use(async r => {
|
||||
})
|
||||
|
||||
export const evepraisalAxiosInstance = axios.create({
|
||||
baseURL: '/appraisal/',
|
||||
baseURL: '/evepraisal/',
|
||||
headers: {
|
||||
'accept': 'application/json',
|
||||
"Content-Type": "application/json"
|
||||
|
||||
Reference in New Issue
Block a user