Compare commits
3 Commits
088ea5d929
...
a1bffa1cdb
| Author | SHA1 | Date | |
|---|---|---|---|
| a1bffa1cdb | |||
| 98ce81dfb2 | |||
| f115381955 |
@@ -27,10 +27,18 @@ server {
|
||||
proxy_set_header Host "${POCKET_BASE_URL}";
|
||||
proxy_set_header X-Forwarded-Proto https;
|
||||
}
|
||||
location /appraisal/ {
|
||||
location /evepraisal/ {
|
||||
proxy_pass https://${FUZZWORK_URL}/;
|
||||
proxy_http_version 1.1;
|
||||
rewrite /evepraisal/(.*) /$1 break;
|
||||
proxy_ssl_server_name on;
|
||||
proxy_set_header Host "${FUZZWORK_URL}";
|
||||
proxy_set_header X-Forwarded-Proto https;
|
||||
}
|
||||
location /fuzzwork/ {
|
||||
proxy_pass https://${EVEPRAISAL_URL}/;
|
||||
proxy_http_version 1.1;
|
||||
rewrite /appraisal/(.*) /$1 break;
|
||||
rewrite /fuzzwork/(.*) /$1 break;
|
||||
proxy_ssl_server_name on;
|
||||
proxy_set_header Host "${EVEPRAISAL_URL}";
|
||||
proxy_set_header X-Forwarded-Proto https;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite --host",
|
||||
"dev": "vite --host --debug",
|
||||
"build": "vue-tsc && vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
|
||||
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,9 @@
|
||||
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';
|
||||
import { getfuzzworkPrices } from './fuzzwork';
|
||||
|
||||
type MarketTypePriceCache = {
|
||||
price: MarketTypePrice,
|
||||
@@ -16,26 +11,15 @@ type MarketTypePriceCache = {
|
||||
}
|
||||
|
||||
const cacheDuration = 1000 * 60 * 5; // 5 minutes
|
||||
const batchSize = 100;
|
||||
const priceGetters = {
|
||||
evepraisal: getEvepraisalPrices,
|
||||
fuzzwork: getfuzzworkPrices
|
||||
}
|
||||
|
||||
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 = priceGetters.fuzzwork;
|
||||
|
||||
const getPrice = async (type: MarketType): Promise<MarketTypePrice> => (await getPrices([type]))[0];
|
||||
const getPrices = async (types: MarketType[]): Promise<MarketTypePrice[]> => {
|
||||
31
src/market/appraisal/evepraisal.ts
Normal file
31
src/market/appraisal/evepraisal.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { logResource } from '@/service';
|
||||
import axios from 'axios';
|
||||
import { MarketType } from "../type";
|
||||
import { PriceGetter } from './MarketTypePrice';
|
||||
|
||||
export const evepraisalAxiosInstance = axios.create({
|
||||
baseURL: '/evepraisal/',
|
||||
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
|
||||
}));
|
||||
};
|
||||
36
src/market/appraisal/fuzzwork.ts
Normal file
36
src/market/appraisal/fuzzwork.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { logResource } from '@/service';
|
||||
import axios from 'axios';
|
||||
import { MarketType } from "../type";
|
||||
import { PriceGetter } from './MarketTypePrice';
|
||||
|
||||
export const fuzzworkAxiosInstance = axios.create({
|
||||
baseURL: '/fuzzwork/',
|
||||
headers: {
|
||||
'accept': 'application/json',
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
})
|
||||
logResource(fuzzworkAxiosInstance)
|
||||
|
||||
const batchSize = 100;
|
||||
|
||||
export const getfuzzworkPrices: PriceGetter = async types => {
|
||||
const batches = [];
|
||||
|
||||
for (let i = 0; i < types.length; i += batchSize) {
|
||||
batches.push(fuzzworkAxiosInstance.post(`/aggregates/?station=60003760&types=${types.slice(i, i + batchSize).map(t => t.id).join(",")}`));
|
||||
}
|
||||
return (await Promise.all(batches))
|
||||
.flatMap(b => Object.entries(b.data))
|
||||
.map(entry => {
|
||||
const id = parseInt(entry[0]);
|
||||
const prices = entry[1] as any;
|
||||
|
||||
return {
|
||||
type: types.find(t => t.id === id) as MarketType,
|
||||
buy: parseFloat(prices.buy.max),
|
||||
sell: parseFloat(prices.sell.min),
|
||||
orderCount: parseInt(prices.buy.order_count) + parseInt(prices.sell.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';
|
||||
@@ -73,7 +73,7 @@ watch(useRoute(), async route => {
|
||||
<hr>
|
||||
<div class="p-2 mb-4 flex">
|
||||
<img v-if="item.id" :src="`https://images.evetech.net/types/${item.id}/icon?size=64`" class="type-image inline-block me-2" />
|
||||
<div class="inline-block align-top">
|
||||
<div class="inline-block align-top w-full">
|
||||
<div class="flex">
|
||||
<span class="text-lg font-semibold">{{ item.name }}</span>
|
||||
<div class="ms-auto">
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { evepraisalAxiosInstance } from '@/service';
|
||||
import { evepraisalAxiosInstance } from '@/market/appraisal/evepraisal';
|
||||
import { useVModel } from '@vueuse/core';
|
||||
|
||||
interface Props {
|
||||
|
||||
@@ -2,7 +2,7 @@ import axios, { AxiosInstance } from 'axios';
|
||||
import log from 'loglevel';
|
||||
|
||||
|
||||
const logResource = (a: AxiosInstance) => {
|
||||
export const logResource = (a: AxiosInstance) => {
|
||||
a.interceptors.response.use(r => {
|
||||
log.debug(`[${r.config.method?.toUpperCase()}] ${r.config.url}`);
|
||||
return r;
|
||||
@@ -43,15 +43,6 @@ marbasAxiosInstance.interceptors.response.use(async r => {
|
||||
return r;
|
||||
})
|
||||
|
||||
export const evepraisalAxiosInstance = axios.create({
|
||||
baseURL: '/appraisal/',
|
||||
headers: {
|
||||
'accept': 'application/json',
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
})
|
||||
logResource(evepraisalAxiosInstance)
|
||||
|
||||
export const esiAxiosInstance = axios.create({
|
||||
baseURL: '/esi/',
|
||||
headers: {
|
||||
|
||||
@@ -67,11 +67,17 @@ 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/, ''),
|
||||
},
|
||||
'/fuzzwork/': {
|
||||
target: env.FUZZWORK_URL,
|
||||
changeOrigin: true,
|
||||
followRedirects: true,
|
||||
rewrite: path => path.replace(/^\/fuzzwork/, ''),
|
||||
},
|
||||
'/esi/': {
|
||||
target: env.ESI_URL,
|
||||
|
||||
Reference in New Issue
Block a user