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