extract evepraisal from apraisal

This commit is contained in:
2023-11-16 09:54:23 +01:00
parent f115381955
commit 98ce81dfb2
7 changed files with 43 additions and 30 deletions

View File

@@ -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;

View 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[]>;

View File

@@ -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[]> => {

View 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
}));
};

View File

@@ -0,0 +1,2 @@
export * from './MarketTypePrice';
export * from './appraisal';

View File

@@ -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"

View File

@@ -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,