Files
huishou/fix-server-file.js
T
2026-07-27 14:07:26 +08:00

70 lines
1.9 KiB
JavaScript

const { Client } = require('ssh2');
const config = {
host: 'hs.yifenbao.cn',
port: 22,
username: 'root',
password: 'Torch1112'
};
const conn = new Client();
conn.on('ready', () => {
console.log('SSH连接成功');
conn.exec('cat /www/huishou/dist/build/h5/assets/pages-order-list.CUBjj0jK.js', (err, stream) => {
if (err) {
console.error('执行命令错误:', err.message);
conn.end();
return;
}
let content = '';
stream.stdout.on('data', (data) => {
content += data.toString();
});
stream.on('close', () => {
const hasDebug = content.includes('debug-info');
console.log('文件是否包含调试信息:', hasDebug);
if (hasDebug) {
const newContent = content.replace(/,n\(a,\{class:"debug-info"\},\{default:o\(\(\)=>\[b\("tabBar:"\+h\(j\.value\)\+"px safeArea:"\+h\(F\.value\)\+"px",1\)\]\),_:1\)\)/g, '');
conn.exec(`echo '${newContent.replace(/'/g, "'\"'\"'")}' > /www/huishou/dist/build/h5/assets/pages-order-list.CUBjj0jK.js`, (err, stream) => {
if (err) {
console.error('写入文件失败:', err.message);
conn.end();
return;
}
stream.on('close', () => {
console.log('文件修复成功');
conn.exec('docker restart huishou', (err, stream) => {
if (err) {
console.error('重启容器失败:', err.message);
conn.end();
return;
}
stream.on('close', () => {
console.log('容器已重启');
conn.end();
});
});
});
});
} else {
console.log('文件中没有调试信息');
conn.end();
}
});
});
});
conn.on('error', (err) => {
console.error('SSH连接错误:', err.message);
});
conn.connect(config);