Skip to content

Commit

Permalink
fix: unregister store monitor on unsubscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Oct 28, 2024
1 parent 4b970a5 commit 4b7efed
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/controllers/storeController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
DigPeer,
ServerCoin,
NconfManager,
StoreMonitorRegistry
} from "@dignetwork/dig-sdk";
import { getStorageLocation } from "../utils/storage";
import requestIp from 'request-ip';
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 4b7efed

Please sign in to comment.