|
@@ -117,7 +117,7 @@ async function calculate(username: string, apiKey: string, supplyForDays: number
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async function getPrices(cx: string) {
|
|
async function getPrices(cx: string) {
|
|
|
- const rawPrices= await fetch('https://refined-prun.github.io/refined-prices/all.json').then(r => r.json());
|
|
|
|
|
|
|
+ const rawPrices= await cachedFetchJSON('https://refined-prun.github.io/refined-prices/all.json');
|
|
|
const prices = new Map<string, RawPrice>();
|
|
const prices = new Map<string, RawPrice>();
|
|
|
for (const p of rawPrices)
|
|
for (const p of rawPrices)
|
|
|
if (p.ExchangeCode === cx)
|
|
if (p.ExchangeCode === cx)
|
|
@@ -126,21 +126,21 @@ async function getPrices(cx: string) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async function getPlanets(username: string, apiKey: string) {
|
|
async function getPlanets(username: string, apiKey: string) {
|
|
|
- const fioBurns: FIOBurn[] = await fetch('https://rest.fnar.net/fioweb/burn/user/' + username,
|
|
|
|
|
- {headers: {'Authorization': apiKey}}).then(r => r.json());
|
|
|
|
|
|
|
+ const fioBurns: FIOBurn[] = await cachedFetchJSON('https://rest.fnar.net/fioweb/burn/user/' + username,
|
|
|
|
|
+ {headers: {'Authorization': apiKey}});
|
|
|
const planets = fioBurns.map(burn => new Planet(burn));
|
|
const planets = fioBurns.map(burn => new Planet(burn));
|
|
|
return planets;
|
|
return planets;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async function warehouseInventory(username: string, apiKey: string, whName: string): Promise<Map<string, number>> {
|
|
async function warehouseInventory(username: string, apiKey: string, whName: string): Promise<Map<string, number>> {
|
|
|
- const warehouses: Warehouse[] = await fetch('https://rest.fnar.net/sites/warehouses/' + username,
|
|
|
|
|
- {headers: {'Authorization': apiKey}}).then(r => r.json());
|
|
|
|
|
|
|
+ const warehouses: Warehouse[] = await cachedFetchJSON('https://rest.fnar.net/sites/warehouses/' + username,
|
|
|
|
|
+ {headers: {'Authorization': apiKey}});
|
|
|
|
|
|
|
|
const inventory = new Map<string, number>();
|
|
const inventory = new Map<string, number>();
|
|
|
for (const warehouse of warehouses)
|
|
for (const warehouse of warehouses)
|
|
|
if (warehouse.LocationNaturalId === whName) {
|
|
if (warehouse.LocationNaturalId === whName) {
|
|
|
- const storage: Storage = await fetch(`https://rest.fnar.net/storage/${username}/${warehouse.StoreId}`,
|
|
|
|
|
- {headers: {'Authorization': apiKey}}).then(r => r.json());
|
|
|
|
|
|
|
+ const storage: Storage = await cachedFetchJSON(`https://rest.fnar.net/storage/${username}/${warehouse.StoreId}`,
|
|
|
|
|
+ {headers: {'Authorization': apiKey}});
|
|
|
for (const item of storage.StorageItems)
|
|
for (const item of storage.StorageItems)
|
|
|
inventory.set(item.MaterialTicker, item.MaterialAmount);
|
|
inventory.set(item.MaterialTicker, item.MaterialAmount);
|
|
|
break;
|
|
break;
|
|
@@ -149,8 +149,8 @@ async function warehouseInventory(username: string, apiKey: string, whName: stri
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async function getBids(username: string, apiKey: string, cx: string) {
|
|
async function getBids(username: string, apiKey: string, cx: string) {
|
|
|
- const allOrders: ExchangeOrder[] = await fetch('https://rest.fnar.net/cxos/' + username,
|
|
|
|
|
- {headers: {'Authorization': apiKey}}).then(r => r.json());
|
|
|
|
|
|
|
+ const allOrders: ExchangeOrder[] = await cachedFetchJSON('https://rest.fnar.net/cxos/' + username,
|
|
|
|
|
+ {headers: {'Authorization': apiKey}});
|
|
|
const orders = allOrders.filter(order =>
|
|
const orders = allOrders.filter(order =>
|
|
|
order.OrderType === 'BUYING' && order.Status !== 'FILLED' && order.ExchangeCode === cx);
|
|
order.OrderType === 'BUYING' && order.Status !== 'FILLED' && order.ExchangeCode === cx);
|
|
|
const bids = new Map<string, number>();
|
|
const bids = new Map<string, number>();
|
|
@@ -159,6 +159,15 @@ async function getBids(username: string, apiKey: string, cx: string) {
|
|
|
return {bids, orders};
|
|
return {bids, orders};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+const fetchCache = new Map<string, any>();
|
|
|
|
|
+async function cachedFetchJSON(url: string, options?: RequestInit): Promise<any> {
|
|
|
|
|
+ if (fetchCache.has(url))
|
|
|
|
|
+ return fetchCache.get(url);
|
|
|
|
|
+ const response = await fetch(url, options).then((r) => r.json());
|
|
|
|
|
+ fetchCache.set(url, response);
|
|
|
|
|
+ return response;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
class Planet {
|
|
class Planet {
|
|
|
name: string;
|
|
name: string;
|
|
|
inventory: Map<string, number>;
|
|
inventory: Map<string, number>;
|