extract evepraisal from apraisal
This commit is contained in:
@@ -27,10 +27,10 @@ server {
|
||||
proxy_set_header Host "${POCKET_BASE_URL}";
|
||||
proxy_set_header X-Forwarded-Proto https;
|
||||
}
|
||||
location /appraisal/ {
|
||||
location /evepraisal/ {
|
||||
proxy_pass https://${EVEPRAISAL_URL}/;
|
||||
proxy_http_version 1.1;
|
||||
rewrite /appraisal/(.*) /$1 break;
|
||||
rewrite /evepraisal/(.*) /$1 break;
|
||||
proxy_ssl_server_name on;
|
||||
proxy_set_header Host "${EVEPRAISAL_URL}";
|
||||
proxy_set_header X-Forwarded-Proto https;
|
||||
|
||||
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"
|
||||
|
||||
@@ -67,11 +67,11 @@ export default defineConfig(({ mode }) => {
|
||||
followRedirects: true,
|
||||
rewrite: path => path.replace(/^\/pocketbase/, ''),
|
||||
},
|
||||
'/appraisal/': {
|
||||
'/evepraisal/': {
|
||||
target: env.EVEPRAISAL_URL,
|
||||
changeOrigin: true,
|
||||
followRedirects: true,
|
||||
rewrite: path => path.replace(/^\/appraisal/, ''),
|
||||
rewrite: path => path.replace(/^\/evepraisal/, ''),
|
||||
},
|
||||
'/esi/': {
|
||||
target: env.ESI_URL,
|
||||
|
||||
Reference in New Issue
Block a user