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>
135 lines
4.3 KiB
JavaScript
135 lines
4.3 KiB
JavaScript
/**
|
||
* 直接向数据库添加Rola-IP平台配置
|
||
* 这个脚本会检查并插入Rola-IP配置数据
|
||
*/
|
||
|
||
const mysql = require('mysql2/promise');
|
||
|
||
// 数据库配置(基于项目配置)
|
||
const dbConfig = {
|
||
host: '127.0.0.1',
|
||
user: 'root',
|
||
password: '',
|
||
database: 'tg_manage',
|
||
port: 3306
|
||
};
|
||
|
||
async function addRolaIPToDB() {
|
||
let connection;
|
||
|
||
try {
|
||
console.log('🔌 连接数据库...');
|
||
connection = await mysql.createConnection(dbConfig);
|
||
|
||
// 检查是否已存在Rola-IP配置
|
||
console.log('🔍 检查现有Rola-IP配置...');
|
||
const [existingRows] = await connection.execute(
|
||
'SELECT COUNT(*) as count FROM proxy_platform WHERE platform = ?',
|
||
['rola-ip']
|
||
);
|
||
|
||
if (existingRows[0].count > 0) {
|
||
console.log('✅ Rola-IP配置已存在,无需重复添加');
|
||
return;
|
||
}
|
||
|
||
// 插入Rola-IP配置
|
||
console.log('📝 插入Rola-IP配置...');
|
||
const insertResult = await connection.execute(`
|
||
INSERT INTO proxy_platform (
|
||
platform,
|
||
description,
|
||
apiUrl,
|
||
authType,
|
||
apiKey,
|
||
username,
|
||
password,
|
||
proxyTypes,
|
||
countries,
|
||
concurrentLimit,
|
||
rotationInterval,
|
||
remark,
|
||
isEnabled,
|
||
createdAt,
|
||
updatedAt
|
||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW())
|
||
`, [
|
||
'rola-ip',
|
||
'Rola-IP专业代理IP服务平台,支持住宅IP、数据中心IP、移动IP等多种类型',
|
||
'https://admin.rola-ip.co',
|
||
'userPass',
|
||
'',
|
||
'',
|
||
'',
|
||
'residential,datacenter,mobile,static_residential,ipv6',
|
||
'US,UK,DE,FR,JP,KR,AU,CA,BR,IN,SG,HK,TW,RU,NL',
|
||
100,
|
||
300,
|
||
'支持多种代理类型和15个国家/地区,提供住宅IP、数据中心IP、移动IP、静态住宅IP和IPv6代理服务。需要在前端配置用户名和密码后启用。',
|
||
false
|
||
]);
|
||
|
||
console.log('✅ Rola-IP配置添加成功!');
|
||
console.log(`📊 插入ID: ${insertResult[0].insertId}`);
|
||
|
||
// 验证插入结果
|
||
console.log('🔍 验证插入结果...');
|
||
const [verifyRows] = await connection.execute(
|
||
'SELECT * FROM proxy_platform WHERE platform = ?',
|
||
['rola-ip']
|
||
);
|
||
|
||
if (verifyRows.length > 0) {
|
||
console.log('🎉 验证成功!Rola-IP配置详情:');
|
||
console.log(` - ID: ${verifyRows[0].id}`);
|
||
console.log(` - 平台: ${verifyRows[0].platform}`);
|
||
console.log(` - 描述: ${verifyRows[0].description}`);
|
||
console.log(` - API地址: ${verifyRows[0].apiUrl}`);
|
||
console.log(` - 认证方式: ${verifyRows[0].authType}`);
|
||
console.log(` - 支持类型: ${verifyRows[0].proxyTypes}`);
|
||
console.log(` - 支持地区: ${verifyRows[0].countries}`);
|
||
console.log(` - 启用状态: ${verifyRows[0].isEnabled ? '已启用' : '未启用'}`);
|
||
}
|
||
|
||
} catch (error) {
|
||
console.error('❌ 操作失败:', error.message);
|
||
|
||
if (error.code === 'ER_NO_SUCH_TABLE') {
|
||
console.log('💡 提示: proxy_platform表不存在,请先运行数据库迁移脚本');
|
||
} else if (error.code === 'ER_ACCESS_DENIED_ERROR') {
|
||
console.log('💡 提示: 数据库连接被拒绝,请检查用户名、密码和权限');
|
||
} else if (error.code === 'ECONNREFUSED') {
|
||
console.log('💡 提示: 无法连接到数据库,请检查数据库服务是否启动');
|
||
}
|
||
|
||
throw error;
|
||
} finally {
|
||
if (connection) {
|
||
await connection.end();
|
||
console.log('🔌 数据库连接已关闭');
|
||
}
|
||
}
|
||
}
|
||
|
||
// 直接运行
|
||
if (require.main === module) {
|
||
console.log('🚀 开始添加Rola-IP到数据库...');
|
||
console.log('⚠️ 请确保数据库服务正在运行,并且配置信息正确');
|
||
console.log('');
|
||
|
||
addRolaIPToDB()
|
||
.then(() => {
|
||
console.log('');
|
||
console.log('🎊 Rola-IP数据添加完成!');
|
||
console.log('💡 现在您可以在前端界面的"代理IP平台"页面看到Rola-IP选项了');
|
||
process.exit(0);
|
||
})
|
||
.catch((error) => {
|
||
console.log('');
|
||
console.log('💥 添加失败,请检查错误信息并重试');
|
||
console.log('📝 如果需要手动执行,可以使用add-rolaip-data.sql文件');
|
||
process.exit(1);
|
||
});
|
||
}
|
||
|
||
module.exports = addRolaIPToDB; |