window.PluginsModule = {
init: () => window.PluginsModule.refresh(),
refresh: async () => {
const list = document.getElementById('plugin-list');
if(!list) return;
list.innerHTML = '加载中...';
try {
const res = await fetch('./api/plugins', {credentials:'include'});
const data = await res.json();
if(!data.plugins?.length) { list.innerHTML = '
暂无已加载插件
'; return; }
list.innerHTML = data.plugins.map(p => `
${p.name} ${p.running?'RUNNING':'STOPPED'}
v${p.version||'1.0.0'} | ${p.enabled?'已启用':'已禁用'}
${p.running
? ``
: ``
}
`).join('');
} catch(e) { list.innerHTML = '加载失败'; }
},
act: async (name, action) => {
try {
await fetch(`./api/plugins/${name}/${action}`, {method:'POST', credentials:'include'});
setTimeout(window.PluginsModule.refresh, 500);
} catch(e) { alert('操作失败'); }
},
destroy: () => {}
};