Update
This commit is contained in:
@@ -57,14 +57,31 @@ const checkExtractorExpiry = async (character: any, planet: any, extractors: any
|
||||
}
|
||||
};
|
||||
|
||||
const checkStorageCapacity = async (character: any, planet: any, storage: any[], config: WebhookConfig) => {
|
||||
const checkStorageCapacity = async (character: any, planet: any, pins: any[], config: WebhookConfig) => {
|
||||
if (!config.enabled || !config.zulipUrl) return;
|
||||
|
||||
for (const storageItem of storage) {
|
||||
const fillPercentage = (storageItem.used / storageItem.capacity) * 100;
|
||||
// Import the storage constants
|
||||
const { STORAGE_IDS, STORAGE_CAPACITIES, PI_PRODUCT_VOLUMES } = await import('@/const');
|
||||
|
||||
// Find storage facilities using the same logic as AccountCard
|
||||
const storageFacilities = pins.filter((pin: any) =>
|
||||
STORAGE_IDS().some((storage: any) => storage.type_id === pin.type_id)
|
||||
);
|
||||
|
||||
for (const storage of storageFacilities) {
|
||||
const storageType = STORAGE_IDS().find((s: any) => s.type_id === storage.type_id)?.name;
|
||||
const storageCapacity = STORAGE_CAPACITIES[storage.type_id];
|
||||
|
||||
const totalVolume = storage.contents
|
||||
.reduce((sum: number, item: any) => {
|
||||
const volume = PI_PRODUCT_VOLUMES[item.type_id];
|
||||
return sum + (item.amount * volume);
|
||||
}, 0);
|
||||
|
||||
const fillPercentage = (totalVolume / storageCapacity) * 100;
|
||||
|
||||
if (fillPercentage >= config.storageCriticalThreshold) {
|
||||
const message = `🚨 Storage ${storageItem.type_name} is ${fillPercentage.toFixed(1)}% full!`;
|
||||
const message = `🚨 Storage ${storageType} is ${fillPercentage.toFixed(1)}% full!`;
|
||||
|
||||
await fetch('/api/zulip-webhook', {
|
||||
method: 'POST',
|
||||
@@ -82,7 +99,7 @@ const checkStorageCapacity = async (character: any, planet: any, storage: any[],
|
||||
})
|
||||
});
|
||||
} else if (fillPercentage >= config.storageWarningThreshold) {
|
||||
const message = `⚠️ Storage ${storageItem.type_name} is ${fillPercentage.toFixed(1)}% full`;
|
||||
const message = `⚠️ Storage ${storageType} is ${fillPercentage.toFixed(1)}% full`;
|
||||
|
||||
await fetch('/api/zulip-webhook', {
|
||||
method: 'POST',
|
||||
|
Reference in New Issue
Block a user