From 4b7efedfac74248d89549370ca368cb61fb7a55e Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Mon, 28 Oct 2024 10:44:57 -0400 Subject: [PATCH] fix: unregister store monitor on unsubscribe --- src/controllers/storeController.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/controllers/storeController.ts b/src/controllers/storeController.ts index 34c32ba..b490e05 100644 --- a/src/controllers/storeController.ts +++ b/src/controllers/storeController.ts @@ -9,6 +9,7 @@ import { DigPeer, ServerCoin, NconfManager, + StoreMonitorRegistry } from "@dignetwork/dig-sdk"; import { getStorageLocation } from "../utils/storage"; import requestIp from 'request-ip'; @@ -66,10 +67,16 @@ export const unsubscribeToStore = async ( try { const { storeId } = req.body; + const storeMonitorRegistryInstance = StoreMonitorRegistry.getInstance(); + storeMonitorRegistryInstance.unregisterStore(storeId); + const pathToStore = path.resolve(getStorageLocation(), "stores", storeId); // Remove the store directory - setTimeout(() => fs.rmdirSync(pathToStore, { recursive: true }), 0); + setTimeout(() => { + fs.rmdirSync(pathToStore, { recursive: true }); + storeMonitorRegistryInstance.unregisterStore(storeId); + }, 0); res.status(200).json({ message: `Unsubscribed to store ${storeId}` }); } catch (error) {