const { Client } = require('ssh2');
const conn = new Client();
function exec(conn, cmd) {
  return new Promise((resolve, reject) => {
    conn.exec(cmd, (err, stream) => {
      if (err) return reject(err);
      let out = '', e = '';
      stream.on('data', d => out += d);
      stream.stderr.on('data', d => e += d);
      stream.on('close', () => resolve({ out: out.trim(), err: e.trim() }));
    });
  });
}
conn.on('ready', async () => {
  // Реальный тайл через nginx (enduro/ → FastAPI, FastAPI отдаёт /terrain/)
  const r1 = await exec(conn, 'curl -o /dev/null -s -w "%{http_code}" "https://openclaw.mva154.duckdns.org/enduro/terrain/hypso/8/161/179.png"');
  console.log('nginx /enduro/terrain/hypso/8/161/179.png:', r1.out);

  // Прямо на FastAPI
  const r2 = await exec(conn, 'curl -o /dev/null -s -w "%{http_code}" "http://localhost:5558/terrain/hypso/8/161/179.png"');
  console.log('direct FastAPI /terrain/hypso/8/161/179.png:', r2.out);

  // Проверить hillshade статус
  const r3 = await exec(conn, 'find /home/slin/enduro-trails/data/terrain/hillshade -name "*.png" 2>/dev/null | wc -l');
  console.log('hillshade PNG count:', r3.out);

  const r4 = await exec(conn, 'pgrep -c gdal2tiles 2>/dev/null || echo 0');
  console.log('gdal2tiles procs:', r4.out);

  // Проверить зумы hillshade
  const r5 = await exec(conn, 'ls /home/slin/enduro-trails/data/terrain/hillshade/ 2>/dev/null | grep -v xml | sort -n | tr "\\n" " "');
  console.log('hillshade zooms:', r5.out || '(none)');

  conn.end();
});
conn.on('error', err => { console.error('error:', err.message); process.exit(1); });
conn.connect({ host: '82.22.50.71', username: 'slin', password: 'motoZ@yaz2010', readyTimeout: 15000 });
