This commit is contained in:
2026-03-04 22:42:20 +01:00
parent 43d0de3c5f
commit 70a475c36e
5 changed files with 45 additions and 8 deletions

View File

@@ -41,12 +41,20 @@
modal.classList.add('is-open');
modal.setAttribute('aria-hidden', 'false');
loadList();
startRefresh();
};
const close = () => {
modal.classList.remove('is-open');
modal.setAttribute('aria-hidden', 'true');
if (refreshTimer) {
clearInterval(refreshTimer);
refreshTimer = null;
}
};
let activeFile = null;
let refreshTimer = null;
const loadList = async () => {
try {
const res = await fetch('/debug?list=1', { cache: 'no-store' });
@@ -71,13 +79,37 @@
};
const loadFile = async (name) => {
activeFile = name;
try {
const res = await fetch(`/debug?raw=1&file=${encodeURIComponent(name)}`, { cache: 'no-store' });
const res = await fetch(`/debug?raw=1&file=${encodeURIComponent(name)}&tail=200`, { cache: 'no-store' });
const text = await res.text();
contentEl.textContent = text;
contentEl.textContent = formatLog(text);
} catch (e) {}
};
const formatLog = (text) => {
const lines = text.split(/\\r?\\n/).filter(Boolean);
const pretty = lines.map((line) => {
try {
const obj = JSON.parse(line);
return JSON.stringify(obj, null, 2);
} catch (e) {
return line;
}
});
return pretty.join('\\n\\n');
};
const startRefresh = () => {
if (refreshTimer) clearInterval(refreshTimer);
refreshTimer = setInterval(() => {
if (activeFile) loadFile(activeFile);
}, 3000);
};
openBtn.addEventListener('click', open);
closeEls.forEach((el) => el.addEventListener('click', close));
if (modal.classList.contains('is-open')) {
startRefresh();
}
})();