1
0
Fork 0
mirror of https://git.sr.ht/~ashkeel/strimertul-website synced 2024-11-21 21:22:21 +00:00
This commit is contained in:
Ash Keel 2023-11-05 13:23:00 +01:00
parent 87073a2ce0
commit 90b2afee92
No known key found for this signature in database
GPG key ID: 53A9E9A6035DD109
4 changed files with 1764 additions and 21 deletions

View file

@ -1,7 +1,7 @@
--- ---
menu: apiversions menu: apiversions
title: v3.1 - v3.3 title: v3.1 / v3.2
version: v31 version: v31
aliases: aliases:
- latest - latest

9
content/api/v33.md Normal file
View file

@ -0,0 +1,9 @@
---
menu: apiversions
title: v3.3
version: v33
aliases:
- latest
- api/
---

1675
data/api/v33/api.json Normal file

File diff suppressed because it is too large Load diff

View file

@ -73,17 +73,17 @@
const startingEl = document.getElementById("starting"); const startingEl = document.getElementById("starting");
const tableEl = document.getElementById("logs"); const tableEl = document.getElementById("logs");
// Click handler (open file select) if (!mainEl || !startingEl || !tableEl) {
startingEl?.addEventListener("click", (ev) => { throw new Error("Missing elements");
// Create temporary file input and click it }
const fileSelect = document.createElement("input");
fileSelect.type = "file"; /**
fileSelect.accept = ".log"; * Reads a log file and populates a table with the parsed logs.
fileSelect.addEventListener("change", (ev) => { *
if (ev.target instanceof HTMLInputElement && ev.target.files) { * @param {File} file - The log file to be read.
const file = ev.target.files[0]; * @return {void}
startingEl.innerHTML = "Loading..."; */
if (file) { function readLogFile(file) {
const reader = new FileReader(); const reader = new FileReader();
reader.addEventListener("load", (ev) => { reader.addEventListener("load", (ev) => {
const logs = const logs =
@ -97,29 +97,88 @@
}) || []; }) || [];
tableEl?.querySelector("tbody")?.replaceChildren(...logs); tableEl?.querySelector("tbody")?.replaceChildren(...logs);
tableEl?.classList.remove("hidden"); tableEl?.classList.remove("hidden");
startingEl.classList.add("hidden"); startingEl?.classList.add("hidden");
}); });
reader.readAsText(file); reader.readAsText(file);
} }
// Click handler (open file select)
startingEl.addEventListener("click", (ev) => {
// Create temporary file input and click it
const fileSelect = document.createElement("input");
fileSelect.type = "file";
fileSelect.accept = ".log";
fileSelect.addEventListener("change", (ev) => {
if (ev.target instanceof HTMLInputElement && ev.target.files) {
const file = ev.target.files[0];
startingEl.innerHTML = "Loading...";
if (file) {
readLogFile(file);
}
} }
}); });
fileSelect.click(); fileSelect.click();
}); });
// Drag and drop handler
mainEl.addEventListener("dragover", (ev) => {
ev.preventDefault();
});
mainEl.addEventListener("drop", (ev) => {
ev.preventDefault();
if (ev.dataTransfer?.files) {
const file = ev.dataTransfer.files[0];
startingEl.innerHTML = "Loading...";
if (file) {
readLogFile(file);
}
}
});
/**
* Creates a log entry as a table row element.
*
* @param log - An object representing a log entry with properties level, ts, caller, msg, and data.
*
* @returns A table row element representing the log entry.
*/
function makeLog(log) { function makeLog(log) {
const tr = document.createElement("tr"); const tr = document.createElement("tr");
const { level, ts, caller, msg, ...data } = log; const { level, ts, caller, msg, ...data } = log;
tr.appendChild(makeCell(level)); tr.appendChild(makeCell(level));
tr.appendChild(makeCell(new Date(ts * 1000).toISOString())); tr.appendChild(makeCell(makeDateElement(new Date(ts * 1000))));
tr.appendChild(makeCell(caller)); tr.appendChild(makeCell(caller));
tr.appendChild(makeCell(msg)); tr.appendChild(makeCell(msg));
tr.appendChild(makeCell(JSON.stringify(data))); tr.appendChild(makeCell(JSON.stringify(data)));
return tr; return tr;
} }
function makeCell(text) { /**
* Creates a new date element with the given date.
*
* @param {Date} date - The date to be used for the new date element.
* @returns {HTMLTimeElement} The newly created date element.
*/
function makeDateElement(date) {
const time = document.createElement("time");
time.setAttribute("datetime", date.toISOString());
time.appendChild(document.createTextNode(date.toLocaleTimeString()));
return time;
}
/**
* Creates a table cell element with the given text as its content.
*
* @param {string | HTMLElement} el - A string or a DOM element to be used as the content of the cell.
* @returns {HTMLTableCellElement} - A table cell element with the given text as its content.
*/
function makeCell(el) {
const td = document.createElement("td"); const td = document.createElement("td");
td.appendChild(document.createTextNode(text)); if (typeof el === "string") {
td.appendChild(document.createTextNode(el));
} else {
td.appendChild(el);
}
return td; return td;
} }
</script> </script>