mirror of
https://github.com/hack-chat/main.git
synced 2024-03-22 13:20:33 +08:00
add channel record removal
This commit is contained in:
parent
dc841cb25e
commit
46b6555b33
|
@ -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`
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user