From 46b6555b33434ab922c92a9ddd4958fc6b297cb2 Mon Sep 17 00:00:00 2001 From: marzavec Date: Mon, 15 Jan 2024 11:28:30 -0800 Subject: [PATCH] add channel record removal --- commands/channels/unclaimchannel.js | 5 ++--- commands/utility/_Channels.js | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/commands/channels/unclaimchannel.js b/commands/channels/unclaimchannel.js index 854eb09..a187337 100644 --- a/commands/channels/unclaimchannel.js +++ b/commands/channels/unclaimchannel.js @@ -13,11 +13,10 @@ import { } from '../utility/_UAC.js'; import { Errors, - DefaultChannelSettings, } from '../utility/_Constants.js'; import { getChannelSettings, - updateChannelSettings, + deleteChannelSettings, } from '../utility/_Channels.js'; /** @@ -63,7 +62,7 @@ export async function run({ }, socket); } - updateChannelSettings(core.appConfig.data, socket.channel, DefaultChannelSettings); + deleteChannelSettings(core.appConfig.data, socket.channel); server.broadcast({ cmd: 'info', // @todo Add numeric info code as `id` diff --git a/commands/utility/_Channels.js b/commands/utility/_Channels.js index 6aac2f2..bac4bc4 100644 --- a/commands/utility/_Channels.js +++ b/commands/utility/_Channels.js @@ -12,6 +12,7 @@ import { existsSync, readFileSync, writeFile, + unlinkSync, } from 'node:fs'; import { createHash, @@ -62,7 +63,7 @@ export function getChannelHash(channel) { */ export function storeChannelSettings(config, channel) { const channelHash = getChannelHash(channel); - const configPath = `../../channels/${channelHash[0]}/${channelHash}.json`; + const configPath = `./channels/${channelHash[0]}/${channelHash}.json`; delete config.permissions[channelHash].channelHash; @@ -71,6 +72,26 @@ export function storeChannelSettings(config, channel) { return true; } +/** + * Deletes the target channel config file from storage and memory + * @public + * @param {string} config Server config object + * @param {string} channel Target channel + * @return {boolean} + */ +export function deleteChannelSettings(config, channel) { + const channelHash = getChannelHash(channel); + const configPath = `./channels/${channelHash[0]}/${channelHash}.json`; + + try { + unlinkSync(configPath); + } catch (e) { /* Error handling not needed */ } + + delete config.permissions[channelHash]; + + return true; +} + /** * Applies new settings into the specified channel settings * @public