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';
|
} from '../utility/_UAC.js';
|
||||||
import {
|
import {
|
||||||
Errors,
|
Errors,
|
||||||
DefaultChannelSettings,
|
|
||||||
} from '../utility/_Constants.js';
|
} from '../utility/_Constants.js';
|
||||||
import {
|
import {
|
||||||
getChannelSettings,
|
getChannelSettings,
|
||||||
updateChannelSettings,
|
deleteChannelSettings,
|
||||||
} from '../utility/_Channels.js';
|
} from '../utility/_Channels.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,7 +62,7 @@ export async function run({
|
||||||
}, socket);
|
}, socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateChannelSettings(core.appConfig.data, socket.channel, DefaultChannelSettings);
|
deleteChannelSettings(core.appConfig.data, socket.channel);
|
||||||
|
|
||||||
server.broadcast({
|
server.broadcast({
|
||||||
cmd: 'info', // @todo Add numeric info code as `id`
|
cmd: 'info', // @todo Add numeric info code as `id`
|
||||||
|
|
|
@ -12,6 +12,7 @@ import {
|
||||||
existsSync,
|
existsSync,
|
||||||
readFileSync,
|
readFileSync,
|
||||||
writeFile,
|
writeFile,
|
||||||
|
unlinkSync,
|
||||||
} from 'node:fs';
|
} from 'node:fs';
|
||||||
import {
|
import {
|
||||||
createHash,
|
createHash,
|
||||||
|
@ -62,7 +63,7 @@ export function getChannelHash(channel) {
|
||||||
*/
|
*/
|
||||||
export function storeChannelSettings(config, channel) {
|
export function storeChannelSettings(config, channel) {
|
||||||
const channelHash = getChannelHash(channel);
|
const channelHash = getChannelHash(channel);
|
||||||
const configPath = `../../channels/${channelHash[0]}/${channelHash}.json`;
|
const configPath = `./channels/${channelHash[0]}/${channelHash}.json`;
|
||||||
|
|
||||||
delete config.permissions[channelHash].channelHash;
|
delete config.permissions[channelHash].channelHash;
|
||||||
|
|
||||||
|
@ -71,6 +72,26 @@ export function storeChannelSettings(config, channel) {
|
||||||
return true;
|
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
|
* Applies new settings into the specified channel settings
|
||||||
* @public
|
* @public
|
||||||
|
|
Loading…
Reference in New Issue
Block a user