mirror of
https://github.com/muerwre/vk-tg-bot.git
synced 2025-04-25 15:06:41 +07:00
added http and telegram api services
This commit is contained in:
parent
5453e884c6
commit
9433cc327a
18 changed files with 687 additions and 70 deletions
|
@ -1,20 +1,23 @@
|
|||
import yaml from 'js-yaml'
|
||||
import fs from 'fs'
|
||||
import path from 'path';
|
||||
import { Config } from './types';
|
||||
import { mergeRight } from 'ramda';
|
||||
import { validateConfig } from './validate';
|
||||
import logger from '../service/logger';
|
||||
import { getCmdArg } from '../utils/args';
|
||||
import yaml from "js-yaml";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { Config } from "./types";
|
||||
import { mergeRight } from "ramda";
|
||||
import { validateConfig } from "./validate";
|
||||
import { getCmdArg } from "../utils/args";
|
||||
|
||||
const configPath = getCmdArg('config')
|
||||
const defaultConfig = yaml.load<Config>(fs.readFileSync(path.join(__dirname, '../config.example.yml'), 'utf8'));
|
||||
const userConfig = yaml.load<Config>(fs.readFileSync(configPath || path.join(__dirname, '../config.yml'), 'utf8'));
|
||||
const configPath = getCmdArg("config");
|
||||
const defaultConfig = yaml.load<Config>(
|
||||
fs.readFileSync(path.join(__dirname, "../config.example.yml"), "utf8")
|
||||
);
|
||||
const userConfig = yaml.load<Config>(
|
||||
fs.readFileSync(configPath || path.join(__dirname, "../config.yml"), "utf8")
|
||||
);
|
||||
|
||||
const config = userConfig && mergeRight(defaultConfig, userConfig) || defaultConfig
|
||||
const config =
|
||||
(userConfig && mergeRight(defaultConfig, userConfig)) || defaultConfig;
|
||||
|
||||
export default function prepareConfig() {
|
||||
validateConfig(config)
|
||||
logger.debug('config is ok: ', config)
|
||||
return config
|
||||
validateConfig(config);
|
||||
return config;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import { TelegramConfig } from '../service/telegram/types';
|
||||
import { VkConfig } from '../service/vk/types';
|
||||
import { HttpConfig } from '../api/http/types';
|
||||
import { TelegramConfig } from "../service/telegram/types";
|
||||
import { VkConfig } from "../service/vk/types";
|
||||
import { HttpConfig } from "../api/http/types";
|
||||
import { LoggerConfig } from "../service/logger/types";
|
||||
|
||||
export interface Config extends Record<string, any>{
|
||||
http: HttpConfig
|
||||
telegram: TelegramConfig
|
||||
vk: VkConfig
|
||||
export interface Config extends Record<string, any> {
|
||||
http: HttpConfig;
|
||||
telegram: TelegramConfig;
|
||||
vk: VkConfig;
|
||||
logger?: LoggerConfig;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
import { object } from 'yup'
|
||||
import { httpConfigSchema } from '../api/http/validation';
|
||||
import { Config } from './types';
|
||||
import { vkConfigSchema } from '../service/vk/validation';
|
||||
import { telegramConfigSchema } from '../service/telegram/validation';
|
||||
import { object } from "yup";
|
||||
import { httpConfigSchema } from "../api/http/validation";
|
||||
import { Config } from "./types";
|
||||
import { vkConfigSchema } from "../service/vk/validation";
|
||||
import { telegramConfigSchema } from "../service/telegram/validation";
|
||||
import { loggerConfigSchema } from "../service/logger/config";
|
||||
|
||||
const configSchema = object<Config>().required().shape({
|
||||
http: httpConfigSchema,
|
||||
vk: vkConfigSchema,
|
||||
telegram: telegramConfigSchema,
|
||||
})
|
||||
logger: loggerConfigSchema,
|
||||
});
|
||||
|
||||
export const validateConfig = (config: Config) => configSchema.validateSync(config)
|
||||
export const validateConfig = (config: Config) =>
|
||||
configSchema.validateSync(config);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue