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": "金融街融汇景苑" }, { "id": "s3", "cityId": "1", "districtId": "d2", "name": "华兴里" }, { "id": "s4", "cityId": "1", "districtId": "d2", "name": "华兴南里" }, { "id": "s5", "cityId": "1", "districtId": "mqugyhc6", "name": "意境兰庭" } ]; conn.on('ready', () => { console.log('=== 重新写入站点数据 ===\n'); const jsonStr = JSON.stringify(cleanStations, null, 2); conn.exec(`echo "${jsonStr.replace(/"/g, '\\"')}" > /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', (err, stream2) => { if (err) { console.log('ERR:', err); conn.end(); return; } let output = ''; stream2.on('data', (d) => output += d.toString()); stream2.on('close', () => { console.log('\n验证数据:'); console.log(output); conn.exec('docker restart huishou-backend', (err, stream3) => { if (err) { console.log('ERR:', err); conn.end(); return; } stream3.on('close', () => { console.log('\n容器重启完成'); conn.end(); }); }); }); }); }); }); }); conn.on('error', (err) => { console.log('连接错误:', err.message); }); conn.connect({ host: 'hs.yifenbao.cn', port: 22, username: 'root', password: 'Torch1112' });