Initial commit: Telegram Management System
Some checks failed
Deploy / deploy (push) Has been cancelled
Some checks failed
Deploy / deploy (push) Has been cancelled
Full-stack web application for Telegram management - Frontend: Vue 3 + Vben Admin - Backend: NestJS - Features: User management, group broadcast, statistics 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
56
backend/init-proxy-platforms.js
Normal file
56
backend/init-proxy-platforms.js
Normal file
@@ -0,0 +1,56 @@
|
||||
require('module-alias/register');
|
||||
const Db = require("@src/config/Db");
|
||||
const Redis = require("redis");
|
||||
const RedisUtil = require("@src/util/RedisUtil");
|
||||
const Config = require("@src/config/Config");
|
||||
|
||||
const init = async () => {
|
||||
try {
|
||||
console.log("初始化代理平台数据...");
|
||||
|
||||
// 初始化数据库连接
|
||||
await Db.getInstance();
|
||||
|
||||
// 初始化Redis连接
|
||||
const redisClient = Redis.createClient({
|
||||
host: 'localhost',
|
||||
port: 6379,
|
||||
db: 6,
|
||||
password: Config.isDev ? undefined : Config.redisPassword
|
||||
});
|
||||
|
||||
redisClient.on('error', (err) => {
|
||||
console.error('Redis连接错误:', err);
|
||||
});
|
||||
|
||||
// 设置Redis实例
|
||||
RedisUtil.getInstance(redisClient);
|
||||
|
||||
// 等待连接稳定
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
// 动态加载服务,确保Redis已经初始化
|
||||
const MProxyPlatformService = require("@src/service/MProxyPlatformService");
|
||||
const proxyPlatformService = MProxyPlatformService.getInstance();
|
||||
|
||||
// 确保表存在
|
||||
await proxyPlatformService.getModel().sync({ alter: true });
|
||||
|
||||
// 初始化默认平台数据
|
||||
await proxyPlatformService.initializeDefaultPlatforms();
|
||||
|
||||
console.log("代理平台数据初始化完成!");
|
||||
|
||||
// 关闭Redis连接
|
||||
redisClient.quit();
|
||||
|
||||
setTimeout(() => {
|
||||
process.exit(0);
|
||||
}, 1000);
|
||||
} catch (error) {
|
||||
console.error("初始化失败:", error);
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
init();
|
||||
Reference in New Issue
Block a user