import { Client } from 'ssh2'; const conn = new Client(); const cleanStations = [ { "id": "mrk7uhka", "cityId": "1", "districtId": "d1", "name": "金融街融汇景苑" }, { "id": "mrmyqn5z", "cityId": "1", "districtId": "d1", "name": "景瑞誉景天地" }, { "id": "mrn2hu0d", "cityId": "1", "districtId": "d1", "name": "富御园" }, { "id": "mrltf4b3j65gh", "cityId": "1", "districtId": "d2", "name": "金融街融汇景苑" } ]; conn.on('ready', () => { console.log('=== 清理站点数据 ===\n'); conn.exec('docker stop huishou-backend && rm -rf /www/huishou/server/data/stations.json', (err, stream) => { if (err) { console.log('ERR:', err); conn.end(); return; } stream.on('close', () => { console.log('容器已停止,文件已删除'); conn.exec(`cat > /www/huishou/server/data/stations.json << 'EOF'\n${JSON.stringify(cleanStations, null, 2)}\nEOF`, (err, stream2) => { if (err) { console.log('ERR:', err); conn.end(); return; } stream2.on('close', () => { console.log('站点数据已写入'); conn.exec('docker start huishou-backend', (err, stream3) => { if (err) { console.log('ERR:', err); conn.end(); return; } stream3.on('close', () => { console.log('容器启动完成'); setTimeout(() => { conn.exec('curl -s http://localhost:4000/api/regions/stations', (err, stream4) => { if (err) { console.log('ERR:', err); conn.end(); return; } let output = ''; stream4.on('data', (d) => output += d.toString()); stream4.on('close', () => { console.log('\nAPI返回:'); console.log(output); conn.end(); }); }); }, 5000); }); }); }); }); }); }); }); conn.on('error', (err) => { console.log('连接错误:', err.message); }); conn.connect({ host: 'hs.yifenbao.cn', port: 22, username: 'root', password: 'Torch1112' });