diff --git a/nginx.conf.template b/nginx.conf.template index b5c4dc1..f408ce4 100644 --- a/nginx.conf.template +++ b/nginx.conf.template @@ -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; diff --git a/src/market/appraisal/MarketTypePrice.ts b/src/market/appraisal/MarketTypePrice.ts new file mode 100644 index 0000000..1ed52c2 --- /dev/null +++ b/src/market/appraisal/MarketTypePrice.ts @@ -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; diff --git a/src/market/appraisal.ts b/src/market/appraisal/appraisal.ts similarity index 56% rename from src/market/appraisal.ts rename to src/market/appraisal/appraisal.ts index 8ecb4df..abf2c1b 100644 --- a/src/market/appraisal.ts +++ b/src/market/appraisal/appraisal.ts @@ -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>({}); - const getPricesUncached = async (types: MarketType[]): Promise => { - 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 => (await getPrices([type]))[0]; const getPrices = async (types: MarketType[]): Promise => { diff --git a/src/market/appraisal/evepraisal.ts b/src/market/appraisal/evepraisal.ts new file mode 100644 index 0000000..56103af --- /dev/null +++ b/src/market/appraisal/evepraisal.ts @@ -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 => { + 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 + })); +}; \ No newline at end of file diff --git a/src/market/appraisal/index.ts b/src/market/appraisal/index.ts new file mode 100644 index 0000000..6db8ae4 --- /dev/null +++ b/src/market/appraisal/index.ts @@ -0,0 +1,2 @@ +export * from './MarketTypePrice'; +export * from './appraisal'; diff --git a/src/service.ts b/src/service.ts index fb2a4ff..d1fa60c 100644 --- a/src/service.ts +++ b/src/service.ts @@ -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" diff --git a/vite.config.ts b/vite.config.ts index 1e68c0b..f4405d8 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -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,