This commit is contained in:
2023-11-16 11:26:17 +01:00
parent 98ce81dfb2
commit a1bffa1cdb
8 changed files with 73 additions and 17 deletions

View File

@@ -28,10 +28,18 @@ server {
proxy_set_header X-Forwarded-Proto https; proxy_set_header X-Forwarded-Proto https;
} }
location /evepraisal/ { location /evepraisal/ {
proxy_pass https://${EVEPRAISAL_URL}/; proxy_pass https://${FUZZWORK_URL}/;
proxy_http_version 1.1; proxy_http_version 1.1;
rewrite /evepraisal/(.*) /$1 break; rewrite /evepraisal/(.*) /$1 break;
proxy_ssl_server_name on; 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 /fuzzwork/(.*) /$1 break;
proxy_ssl_server_name on;
proxy_set_header Host "${EVEPRAISAL_URL}"; proxy_set_header Host "${EVEPRAISAL_URL}";
proxy_set_header X-Forwarded-Proto https; proxy_set_header X-Forwarded-Proto https;
} }

View File

@@ -4,7 +4,7 @@
"version": "0.0.0", "version": "0.0.0",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite --host", "dev": "vite --host --debug",
"build": "vue-tsc && vite build", "build": "vue-tsc && vite build",
"preview": "vite preview" "preview": "vite preview"
}, },

View File

@@ -3,6 +3,7 @@ import { ref } from 'vue';
import { MarketType } from "../type"; import { MarketType } from "../type";
import { MarketTypePrice } from './MarketTypePrice'; import { MarketTypePrice } from './MarketTypePrice';
import { getEvepraisalPrices } from './evepraisal'; import { getEvepraisalPrices } from './evepraisal';
import { getfuzzworkPrices } from './fuzzwork';
type MarketTypePriceCache = { type MarketTypePriceCache = {
price: MarketTypePrice, price: MarketTypePrice,
@@ -10,11 +11,15 @@ type MarketTypePriceCache = {
} }
const cacheDuration = 1000 * 60 * 5; // 5 minutes const cacheDuration = 1000 * 60 * 5; // 5 minutes
const priceGetters = {
evepraisal: getEvepraisalPrices,
fuzzwork: getfuzzworkPrices
}
export const useApraisalStore = defineStore('appraisal', () => { export const useApraisalStore = defineStore('appraisal', () => {
const cache = ref<Record<number, MarketTypePriceCache>>({}); const cache = ref<Record<number, MarketTypePriceCache>>({});
const getPricesUncached = getEvepraisalPrices; const getPricesUncached = priceGetters.fuzzwork;
const getPrice = async (type: MarketType): Promise<MarketTypePrice> => (await getPrices([type]))[0]; const getPrice = async (type: MarketType): Promise<MarketTypePrice> => (await getPrices([type]))[0];
const getPrices = async (types: MarketType[]): Promise<MarketTypePrice[]> => { const getPrices = async (types: MarketType[]): Promise<MarketTypePrice[]> => {

View File

@@ -1,10 +1,20 @@
import { evepraisalAxiosInstance } from '@/service'; import { logResource } from '@/service';
import axios from 'axios';
import { MarketType } from "../type"; import { MarketType } from "../type";
import { MarketTypePrice, PriceGetter } from './MarketTypePrice'; import { PriceGetter } from './MarketTypePrice';
export const evepraisalAxiosInstance = axios.create({
baseURL: '/evepraisal/',
headers: {
'accept': 'application/json',
"Content-Type": "application/json"
},
})
logResource(evepraisalAxiosInstance)
const batchSize = 100; const batchSize = 100;
export const getEvepraisalPrices: PriceGetter = async (types: MarketType[]): Promise<MarketTypePrice[]> => { export const getEvepraisalPrices: PriceGetter = async types => {
const batches = []; const batches = [];
for (let i = 0; i < types.length; i += batchSize) { for (let i = 0; i < types.length; i += batchSize) {

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

View File

@@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { evepraisalAxiosInstance } from '@/service'; import { evepraisalAxiosInstance } from '@/market/appraisal/evepraisal';
import { useVModel } from '@vueuse/core'; import { useVModel } from '@vueuse/core';
interface Props { interface Props {

View File

@@ -2,7 +2,7 @@ import axios, { AxiosInstance } from 'axios';
import log from 'loglevel'; import log from 'loglevel';
const logResource = (a: AxiosInstance) => { export const logResource = (a: AxiosInstance) => {
a.interceptors.response.use(r => { a.interceptors.response.use(r => {
log.debug(`[${r.config.method?.toUpperCase()}] ${r.config.url}`); log.debug(`[${r.config.method?.toUpperCase()}] ${r.config.url}`);
return r; return r;
@@ -43,15 +43,6 @@ marbasAxiosInstance.interceptors.response.use(async r => {
return r; return r;
}) })
export const evepraisalAxiosInstance = axios.create({
baseURL: '/evepraisal/',
headers: {
'accept': 'application/json',
"Content-Type": "application/json"
},
})
logResource(evepraisalAxiosInstance)
export const esiAxiosInstance = axios.create({ export const esiAxiosInstance = axios.create({
baseURL: '/esi/', baseURL: '/esi/',
headers: { headers: {

View File

@@ -73,6 +73,12 @@ export default defineConfig(({ mode }) => {
followRedirects: true, followRedirects: true,
rewrite: path => path.replace(/^\/evepraisal/, ''), rewrite: path => path.replace(/^\/evepraisal/, ''),
}, },
'/fuzzwork/': {
target: env.FUZZWORK_URL,
changeOrigin: true,
followRedirects: true,
rewrite: path => path.replace(/^\/fuzzwork/, ''),
},
'/esi/': { '/esi/': {
target: env.ESI_URL, target: env.ESI_URL,
changeOrigin: true, changeOrigin: true,