|
|
@@ -418,35 +418,33 @@ async function fetchPrices(): Promise<Record<string, RawPrice>> {
|
|
|
async function fetchSites(): Promise<Record<string, Set<string>>> {
|
|
|
if (!apiKey.value)
|
|
|
return {};
|
|
|
- const userSites: PUNUserSite[] = await fetch('https://api.punoted.net/v1/sites/?include_buildings=true',
|
|
|
+ const sites: PUNSite[] = await fetch('https://api.punoted.net/v1/sites/user?include_buildings=true',
|
|
|
{headers: {'X-Data-Token': apiKey.value}}).then((r) => r.json());
|
|
|
|
|
|
const buildingPlanets: Record<string, Set<string>> = {};
|
|
|
- for (const user of userSites)
|
|
|
- for (const site of user.Sites)
|
|
|
- for (const building of site.Buildings) {
|
|
|
- if (!buildingPlanets[building.BuildingTicker])
|
|
|
- buildingPlanets[building.BuildingTicker] = new Set();
|
|
|
- buildingPlanets[building.BuildingTicker].add(site.PlanetName);
|
|
|
- }
|
|
|
+ for (const site of sites)
|
|
|
+ for (const building of site.Buildings) {
|
|
|
+ if (!buildingPlanets[building.BuildingTicker])
|
|
|
+ buildingPlanets[building.BuildingTicker] = new Set();
|
|
|
+ buildingPlanets[building.BuildingTicker].add(site.PlanetName);
|
|
|
+ }
|
|
|
return buildingPlanets;
|
|
|
}
|
|
|
|
|
|
async function fetchStorage(): Promise<Storage> {
|
|
|
if (!apiKey.value)
|
|
|
return {allItems: {}, planetItems: {}};
|
|
|
- const userStores: PUNUserStore[] = await fetch('https://api.punoted.net/v1/storages/',
|
|
|
+ const storages: PUNStorage[] = await fetch('https://api.punoted.net/v1/storages/user',
|
|
|
{headers: {'X-Data-Token': apiKey.value}}).then((r) => r.json());
|
|
|
|
|
|
const allItems: Record<string, number> = {};
|
|
|
const planetItems: Record<string, Record<string, number>> = {};
|
|
|
- for (const user of userStores)
|
|
|
- for (const storage of user.Storages)
|
|
|
- for (const item of storage.StorageItems) {
|
|
|
- allItems[item.MaterialTicker] = (allItems[item.MaterialTicker] ?? 0) + item.MaterialAmount;
|
|
|
- const planetStorage = planetItems[storage.Location] ??= {};
|
|
|
- planetStorage[item.MaterialTicker] = (planetStorage[item.MaterialTicker] ?? 0) + item.MaterialAmount;
|
|
|
- }
|
|
|
+ for (const storage of storages)
|
|
|
+ for (const item of storage.StorageItems) {
|
|
|
+ allItems[item.MaterialTicker] = (allItems[item.MaterialTicker] ?? 0) + item.MaterialAmount;
|
|
|
+ const planetStorage = planetItems[storage.Location] ??= {};
|
|
|
+ planetStorage[item.MaterialTicker] = (planetStorage[item.MaterialTicker] ?? 0) + item.MaterialAmount;
|
|
|
+ }
|
|
|
return {allItems, planetItems};
|
|
|
}
|
|
|
|
|
|
@@ -518,21 +516,17 @@ interface Building {
|
|
|
scientists: number
|
|
|
}
|
|
|
|
|
|
-interface PUNUserStore {
|
|
|
- Storages: Array<{
|
|
|
- Location: string
|
|
|
- StorageItems: Array<{
|
|
|
- MaterialTicker: string
|
|
|
- MaterialAmount: number
|
|
|
- }>
|
|
|
+interface PUNStorage {
|
|
|
+ Location: string
|
|
|
+ StorageItems: Array<{
|
|
|
+ MaterialTicker: string
|
|
|
+ MaterialAmount: number
|
|
|
}>
|
|
|
}
|
|
|
|
|
|
-interface PUNUserSite {
|
|
|
- Sites: Array<{
|
|
|
- PlanetName: string
|
|
|
- Buildings: Array<{BuildingTicker: string}>
|
|
|
- }>
|
|
|
+interface PUNSite {
|
|
|
+ PlanetName: string
|
|
|
+ Buildings: Array<{BuildingTicker: string}>
|
|
|
}
|
|
|
|
|
|
type Production = Record<string, Record<string, number>>;
|