fix: use no-modules WASM target for simpler loading
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Momentry API Docs (WASM)</title>
|
||||
<title>Momentry API Docs</title>
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #f5f5f5; color: #333; }
|
||||
@@ -13,13 +13,10 @@ body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-
|
||||
.sidebar a { display: block; padding: 6px 0; color: #0066cc; text-decoration: none; font-size: 14px; cursor: pointer; }
|
||||
.sidebar a:hover { color: #003d80; }
|
||||
.sidebar .active { font-weight: 600; color: #003d80; }
|
||||
.sidebar .lang-toggle { margin: 12px 0; font-size: 12px; }
|
||||
.sidebar .lang-toggle a { display: inline; font-size: 12px; padding: 2px 6px; }
|
||||
.sidebar .logout { margin-top: auto; padding-top: 16px; border-top: 1px solid #eee; }
|
||||
.sidebar .logout a { font-size: 12px; color: #999; }
|
||||
.sidebar .logout a { font-size: 12px; color: #999; cursor: pointer; }
|
||||
.sidebar .logout a:hover { color: #cc0000; }
|
||||
.content { flex: 1; padding: 40px; max-width: 960px; }
|
||||
.content.loading { opacity: 0.5; }
|
||||
.content table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: 14px; }
|
||||
.content th, .content td { border: 1px solid #ddd; padding: 8px 12px; text-align: left; }
|
||||
.content th { background: #f0f0f0; font-weight: 600; }
|
||||
@@ -31,104 +28,89 @@ body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-
|
||||
.content h3 { font-size: 16px; margin: 16px 0 8px; color: #444; }
|
||||
.content p { line-height: 1.6; margin: 8px 0; }
|
||||
.content a { color: #0066cc; }
|
||||
.hidden { display: none; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<script src="/doc-wasm/pkg/md_wasm.js"></script>
|
||||
<div id="app">
|
||||
<div class="sidebar">
|
||||
<h1>Momentry Docs</h1>
|
||||
<div id="module-list"></div>
|
||||
<div class="logout">
|
||||
<a href="#" id="logout-btn">Logout</a>
|
||||
<a id="logout-btn">Logout</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="content" id="content">
|
||||
<p>Loading...</p>
|
||||
<p>Loading WASM...</p>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
const MODULES = [
|
||||
["01_auth","安全認證","Authentication"],
|
||||
["02_health","健康檢查","Health"],
|
||||
["03_register","檔案註冊","File Registration"],
|
||||
["04_lookup","檔案屬性查詢","File Lookup"],
|
||||
["05_process","處理流程","Processing"],
|
||||
["06_search","搜尋功能","Search"],
|
||||
["07_identity","身份識別","Identity"],
|
||||
["08_identity_agent","智能身份綁定","Smart Identity Binding"],
|
||||
["08_media","串流與截圖","Streaming & Thumbnails"],
|
||||
["09_tmdb","TMDb 整合","TMDb Integration"],
|
||||
["10_pipeline","生產線","Pipeline"],
|
||||
["12_agent","智慧代理","AI Agents"],
|
||||
];
|
||||
|
||||
<script type="module">
|
||||
import init, { render_markdown, module_list } from '/doc-wasm/pkg/doc_wasm.js';
|
||||
|
||||
const API = '';
|
||||
let currentModule = null;
|
||||
let modules = [];
|
||||
const el = document.getElementById('content');
|
||||
let wasm = null;
|
||||
|
||||
async function loadDoc(name) {
|
||||
const el = document.getElementById('content');
|
||||
el.classList.add('loading');
|
||||
el.innerHTML = '<p>Loading...</p>';
|
||||
try {
|
||||
const resp = await fetch(`/doc-wasm/modules/${name}.md`);
|
||||
if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
|
||||
const resp = await fetch('/doc-wasm/modules/' + name + '.md');
|
||||
if (!resp.ok) throw new Error('HTTP ' + resp.status);
|
||||
const md = await resp.text();
|
||||
el.innerHTML = render_markdown(md);
|
||||
el.classList.remove('loading');
|
||||
// highlight active module
|
||||
if (!wasm) throw new Error('WASM not initialized');
|
||||
el.innerHTML = wasm.render(md);
|
||||
document.querySelectorAll('.sidebar a.module-link').forEach(a => a.classList.remove('active'));
|
||||
const link = document.querySelector(`.sidebar a[data-module="${name}"]`);
|
||||
const link = document.querySelector('.sidebar a[data-module="' + name + '"]');
|
||||
if (link) link.classList.add('active');
|
||||
history.pushState(null, '', `#${name}`);
|
||||
history.pushState(null, '', '#' + name);
|
||||
} catch(e) {
|
||||
el.innerHTML = `<p style="color:red">Failed to load: ${e.message}</p>`;
|
||||
el.classList.remove('loading');
|
||||
el.innerHTML = '<p style="color:red">Error: ' + e.message + '</p>';
|
||||
}
|
||||
}
|
||||
|
||||
async function checkAuth() {
|
||||
const resp = await fetch(`${API}/api/v1/auth/login`, {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({username:'demo',password:'demo'})
|
||||
});
|
||||
return resp.ok;
|
||||
}
|
||||
|
||||
async function initApp() {
|
||||
const el = document.getElementById('content');
|
||||
async function init() {
|
||||
try {
|
||||
await init();
|
||||
el.innerHTML = '<p>WASM initialized. Loading modules...</p>';
|
||||
|
||||
// Parse module list
|
||||
modules = JSON.parse(module_list());
|
||||
el.innerHTML = '<p>Initializing WASM...</p>';
|
||||
wasm = await wasm_bindgen();
|
||||
el.innerHTML = '<p>Loading modules...</p>';
|
||||
const listEl = document.getElementById('module-list');
|
||||
modules.forEach(([name, cn, en]) => {
|
||||
const a = document.createElement('a');
|
||||
MODULES.forEach(function(m) {
|
||||
var a = document.createElement('a');
|
||||
a.className = 'module-link';
|
||||
a.dataset.module = name;
|
||||
a.textContent = `${cn} - ${en}`;
|
||||
a.onclick = (e) => { e.preventDefault(); loadDoc(name); };
|
||||
a.setAttribute('data-module', m[0]);
|
||||
a.textContent = m[0] + ' ' + m[1];
|
||||
a.onclick = function(e) { e.preventDefault(); loadDoc(m[0]); };
|
||||
listEl.appendChild(a);
|
||||
});
|
||||
|
||||
// Logout
|
||||
document.getElementById('logout-btn').onclick = async (e) => {
|
||||
e.preventDefault();
|
||||
await fetch(`${API}/api/v1/auth/logout`, {method:'POST'});
|
||||
document.getElementById('logout-btn').onclick = async function(e) {
|
||||
await fetch('/api/v1/auth/logout', {method:'POST'});
|
||||
window.location.reload();
|
||||
};
|
||||
|
||||
// Load initial module from hash or default
|
||||
const hash = location.hash.slice(1);
|
||||
if (hash) {
|
||||
loadDoc(hash);
|
||||
} else {
|
||||
loadDoc('01_auth');
|
||||
}
|
||||
var hash = location.hash.slice(1);
|
||||
loadDoc(hash || '01_auth');
|
||||
} catch(e) {
|
||||
el.innerHTML = `<p style="color:red">WASM init error: ${e.message}</p><pre>${e.stack}</pre>`;
|
||||
el.innerHTML = '<p style="color:red">Init error: ' + e.message + '</p>';
|
||||
}
|
||||
}
|
||||
|
||||
// Handle browser back/forward
|
||||
window.onpopstate = () => {
|
||||
const hash = location.hash.slice(1);
|
||||
window.onpopstate = function() {
|
||||
var hash = location.hash.slice(1);
|
||||
if (hash) loadDoc(hash);
|
||||
};
|
||||
|
||||
document.getElementById('content').innerHTML = '<p>Starting WASM...</p>';
|
||||
initApp();
|
||||
init();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user