1
0
mirror of https://github.com/hack-chat/main.git synced 2024-03-22 13:20:33 +08:00
hack-chat-main/main.mjs

66 lines
1.5 KiB
JavaScript
Raw Normal View History

import {
existsSync,
readFileSync,
} from 'node:fs';
import {
Low,
JSONFile,
} from 'lowdb';
import {
CoreApp,
} from 'hackchat-server';
2024-01-18 01:19:06 +08:00
import {
ChannelCheckInterval,
} from './commands/utility/_Constants.js';
import {
purgeInactiveChannels,
} from './commands/utility/_Channels.js';
2022-06-23 00:32:51 +08:00
// required file paths
const SessionLocation = './session.key';
const SaltLocation = './salt.key';
const AppConfigLocation = './config.json';
// verify required files exist
if (existsSync(SessionLocation) === false) {
2022-06-23 00:32:51 +08:00
throw Error('Missing session key, you may need to run: npm run config');
}
if (existsSync(SaltLocation) === false) {
2022-06-23 00:32:51 +08:00
throw Error('Missing salt key, you may need to run: npm run config');
}
if (existsSync(AppConfigLocation) === false) {
2022-06-23 00:32:51 +08:00
throw Error('Missing config, you may need to run: npm run config');
}
// build main hack chat server
const server = new CoreApp({
configPath: './.hcserver.json',
logErrDetailed: true,
lang: 'en',
});
// load sessoin key data
server.sessionKey = readFileSync(SessionLocation);
2022-06-23 00:32:51 +08:00
// load salt key data
server.saltKey = readFileSync(SaltLocation);
2022-06-23 00:32:51 +08:00
// load the configuration data
const adapter = new JSONFile(AppConfigLocation);
server.appConfig = new Low(adapter);
await server.appConfig.read();
2024-01-18 01:19:06 +08:00
// create channel memory management job
setInterval(() => {
purgeInactiveChannels(server.appConfig.data);
}, ChannelCheckInterval);
// @todo create storage management job
// start the server
2022-06-23 00:32:51 +08:00
server.init();
console.log('Websocket server ready');