<!doctype html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>{{TITLE}}</title>
  <style>
    html, body { height: 100%; margin: 0; }
  </style>
</head>
<body>
  <div id="redoc"></div>
  <script>
    window.__OPENAPI_SPEC__ = {{SPEC_JSON}};
  </script>
  <script>
    (function () {
      const urls = {{CDN_URLS_JSON}};

      function loadScript(url) {
        return new Promise((resolve, reject) => {
          const s = document.createElement("script");
          s.src = url;
          s.async = true;
          s.onload = resolve;
          s.onerror = reject;
          document.head.appendChild(s);
        });
      }

      async function boot() {
        for (const url of urls) {
          try {
            await loadScript(url);
            if (window.Redoc) break;
          } catch (_) {}
        }

        if (!window.Redoc) {
          document.body.innerHTML =
            '<div style="font-family: ui-sans-serif, system-ui; padding: 16px;">' +
            "<h2>Redoc 加载失败</h2>" +
            "<p>可能是网络/代理拦截了 CDN。请尝试换网络或在浏览器 Console 查看报错。</p>" +
            "</div>";
          return;
        }

        Redoc.init(window.__OPENAPI_SPEC__, {}, document.getElementById("redoc"));
      }

      boot();
    })();
  </script>
</body>
</html>

