Initial commit: Telegram Management System
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:
你的用户名
2025-11-04 15:37:50 +08:00
commit 237c7802e5
3674 changed files with 525172 additions and 0 deletions

View File

@@ -0,0 +1,81 @@
-- 初始化数据库脚本
-- 设置字符集
SET NAMES utf8mb4;
SET CHARACTER SET utf8mb4;
-- 创建数据库(如果不存在)
CREATE DATABASE IF NOT EXISTS `tg_manage`
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;
-- 使用数据库
USE `tg_manage`;
-- 创建初始管理员用户
-- 密码是: admin123 (bcrypt加密)
INSERT IGNORE INTO `admins` (`id`, `username`, `password`, `role`, `status`, `created_at`, `updated_at`)
VALUES (
1,
'admin',
'$2b$12$LQv3c1yqBWVHxkd0LQ1u/ue5csar/oU8.vo/1B2F3nCpEHE.sN.K6',
'admin',
'active',
NOW(),
NOW()
);
-- 创建系统配置表数据
INSERT IGNORE INTO `configs` (`key`, `value`, `description`, `type`, `created_at`, `updated_at`)
VALUES
('system.name', 'Telegram管理系统', '系统名称', 'string', NOW(), NOW()),
('system.version', '2.0.0', '系统版本', 'string', NOW(), NOW()),
('system.maintenance', 'false', '维护模式', 'boolean', NOW(), NOW()),
('telegram.api_id', '', 'Telegram API ID', 'string', NOW(), NOW()),
('telegram.api_hash', '', 'Telegram API Hash', 'string', NOW(), NOW()),
('proxy.check_interval', '300000', '代理检查间隔(ms)', 'number', NOW(), NOW()),
('sms.default_platform', '1', '默认短信平台ID', 'number', NOW(), NOW()),
('task.max_concurrent', '5', '最大并发任务数', 'number', NOW(), NOW()),
('analytics.retention_days', '90', '分析数据保留天数', 'number', NOW(), NOW());
-- 创建索引优化
CREATE INDEX IF NOT EXISTS `idx_analytics_records_timestamp` ON `analytics_records` (`timestamp`);
CREATE INDEX IF NOT EXISTS `idx_analytics_records_event_type` ON `analytics_records` (`event_type`);
CREATE INDEX IF NOT EXISTS `idx_analytics_records_user_id` ON `analytics_records` (`user_id`);
CREATE INDEX IF NOT EXISTS `idx_analytics_summaries_date` ON `analytics_summaries` (`date`);
CREATE INDEX IF NOT EXISTS `idx_task_executions_status` ON `task_executions` (`status`);
CREATE INDEX IF NOT EXISTS `idx_proxy_check_logs_check_time` ON `proxy_check_logs` (`check_time`);
-- 创建视图用于快速查询
CREATE OR REPLACE VIEW `v_active_tg_accounts` AS
SELECT
id,
phone,
first_name,
last_name,
username,
status,
last_active_at,
created_at
FROM `tg_accounts`
WHERE `status` = 'active'
AND `deleted_at` IS NULL;
CREATE OR REPLACE VIEW `v_recent_tasks` AS
SELECT
t.id,
t.name,
t.type,
t.status,
t.created_at,
te.status as execution_status,
te.started_at,
te.completed_at,
te.error_message
FROM `tasks` t
LEFT JOIN `task_executions` te ON t.id = te.task_id
WHERE t.created_at >= DATE_SUB(NOW(), INTERVAL 7 DAY)
ORDER BY t.created_at DESC;
-- 插入示例数据(仅开发环境)
-- 这些数据在生产环境中应该被删除或注释掉

View File

@@ -0,0 +1,42 @@
[mysqld]
# 基础配置
default-storage-engine=InnoDB
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
init-connect='SET NAMES utf8mb4'
# 性能优化
innodb_buffer_pool_size=256M
innodb_log_file_size=64M
innodb_log_buffer_size=16M
innodb_flush_log_at_trx_commit=2
innodb_file_per_table=1
# 连接配置
max_connections=200
wait_timeout=28800
interactive_timeout=28800
# 查询缓存
query_cache_type=1
query_cache_size=32M
query_cache_limit=2M
# 慢查询日志
slow_query_log=1
slow_query_log_file=/var/log/mysql/slow.log
long_query_time=2
# 二进制日志
log-bin=/var/lib/mysql/mysql-bin
binlog_format=ROW
expire_logs_days=7
# 安全配置
skip-name-resolve=1
[mysql]
default-character-set=utf8mb4
[client]
default-character-set=utf8mb4

View File

@@ -0,0 +1,156 @@
# Nginx配置文件
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
use epoll;
multi_accept on;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
# 日志格式
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'rt=$request_time uct="$upstream_connect_time" '
'uht="$upstream_header_time" urt="$upstream_response_time"';
access_log /var/log/nginx/access.log main;
# 基础配置
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
client_max_body_size 50M;
# Gzip压缩
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_types
text/plain
text/css
text/xml
text/javascript
application/json
application/javascript
application/xml+rss
application/atom+xml
image/svg+xml;
# 上游服务器
upstream app_backend {
server app:3000;
keepalive 32;
}
# 限流配置
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
limit_req_zone $binary_remote_addr zone=login:10m rate=5r/m;
# 主服务器配置
server {
listen 80;
server_name localhost;
# 安全头
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header Referrer-Policy "strict-origin-when-cross-origin";
# API代理
location /api/ {
limit_req zone=api burst=20 nodelay;
proxy_pass http://app_backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
proxy_connect_timeout 5s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
}
# WebSocket代理
location /socket.io/ {
proxy_pass http://app_backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# 健康检查
location /health {
proxy_pass http://app_backend;
access_log off;
}
# API文档
location /api-docs {
proxy_pass http://app_backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# 登录限流
location /api/auth/login {
limit_req zone=login burst=5 nodelay;
proxy_pass http://app_backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# 静态文件
location /uploads/ {
alias /app/uploads/;
expires 1y;
add_header Cache-Control "public, immutable";
}
# 错误页面
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
# HTTPS配置 (如果需要SSL)
# server {
# listen 443 ssl http2;
# server_name localhost;
#
# ssl_certificate /etc/nginx/ssl/cert.pem;
# ssl_certificate_key /etc/nginx/ssl/key.pem;
# ssl_protocols TLSv1.2 TLSv1.3;
# ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384;
# ssl_prefer_server_ciphers off;
#
# # 其他配置与HTTP相同...
# }
}

View File

@@ -0,0 +1 @@
[rabbitmq_management,rabbitmq_prometheus,rabbitmq_shovel,rabbitmq_shovel_management].

View File

@@ -0,0 +1,46 @@
# Redis配置文件
# 网络配置
bind 0.0.0.0
port 6379
protected-mode no
# 内存配置
maxmemory 256mb
maxmemory-policy allkeys-lru
# 持久化配置
save 900 1
save 300 10
save 60 10000
# AOF持久化
appendonly yes
appendfsync everysec
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
# 日志配置
loglevel notice
logfile /data/redis.log
# 性能优化
tcp-keepalive 300
timeout 0
tcp-backlog 511
# 安全配置
# requirepass your-redis-password
# 客户端连接
maxclients 1000
# 慢查询日志
slowlog-log-slower-than 10000
slowlog-max-len 128
# 键空间通知
notify-keyspace-events Ex
# 数据库数量
databases 16