zhilian-auto-hi
Version:
智联招聘自动打招呼工具 - 自动化招聘流程的命令行工具
121 lines (120 loc) • 4.39 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getRunModeDescription = getRunModeDescription;
exports.getGracefulShutdownConfig = getGracefulShutdownConfig;
exports.loadConfig = loadConfig;
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const index_1 = __importDefault(require("../logger/index"));
/**
* 配置文件处理服务
*/
/**
* 获取运行模式的中文描述
* @param mode 运行模式
* @returns 中文描述
*/
function getRunModeDescription(mode) {
switch (mode) {
case 'auto-greeting':
return '自动打招呼模式';
case 'browse':
return '刷浏览模式';
default:
return '未知模式';
}
}
/**
* 获取优雅关闭配置(固定配置,不再从配置文件读取)
* @returns 优雅关闭配置
*/
function getGracefulShutdownConfig() {
return {
timeout: 10000,
showStats: true,
signals: ['SIGINT', 'SIGTERM']
};
}
/**
* 读取配置文件
* @returns 配置对象
*/
function loadConfig() {
index_1.default.info('正在读取配置文件...');
try {
// 读取配置文件
const configPath = path.join(process.cwd(), 'config.json');
if (!fs.existsSync(configPath)) {
throw new Error(`配置文件不存在: ${configPath}`);
}
const configContent = fs.readFileSync(configPath, 'utf8');
const config = JSON.parse(configContent);
// 设置默认运行模式
if (!config.runMode) {
config.runMode = 'auto-greeting';
index_1.default.warning('配置文件中未指定运行模式,使用默认值: auto-greeting');
}
// 优雅关闭配置现在使用固定值,不再从配置文件读取
index_1.default.success('配置文件读取成功');
// 显示配置信息
const displayConfig = {
runMode: `${getRunModeDescription(config.runMode)} (${config.runMode})`,
keywords: config.keywords,
ignoreKeyWords: config.ignoreKeyWords,
minAge: config.minAge,
maxAge: config.maxAge,
gender: config.gender,
maxPages: config.maxPages || 50,
pageDelay: config.pageDelay || 2000
};
// 添加优雅关闭配置显示(使用固定配置)
const gracefulShutdownConfig = getGracefulShutdownConfig();
displayConfig.gracefulShutdown = {
timeout: `${gracefulShutdownConfig.timeout}ms`,
showStats: gracefulShutdownConfig.showStats,
signals: gracefulShutdownConfig.signals.join(', ')
};
index_1.default.config(displayConfig);
return config;
}
catch (error) {
index_1.default.error(`读取配置文件失败: ${error}`);
throw error;
}
}