Files
core/internal/api/ui_ingest.tmpl

96 lines
3.3 KiB
Cheetah

{{define "ingest"}}
<!DOCTYPE html>
<html lang="en">
{{template "head" .}}
<body>
{{template "topbar" .}}
{{template "breadcrumbs" .}}
<main class="container">
<section class="card">
<h2>Logbundle Ingest</h2>
<form class="form" data-endpoint="/ingest/logbundle">
<div class="field">
<label for="logbundle">Payload (JSON)</label>
<textarea class="input" id="logbundle" name="payload" rows="10">{{.LogbundlePayload}}</textarea>
</div>
<button class="button" type="submit">Send Logbundle</button>
<pre class="meta" data-response></pre>
</form>
</section>
<section class="card">
<h2>Failure Ingest</h2>
<form class="form" data-endpoint="/ingest/failures">
<div class="field">
<label for="failures">Payload (JSON)</label>
<textarea class="input" id="failures" name="payload" rows="10">{{.FailurePayload}}</textarea>
</div>
<button class="button" type="submit">Send Failures</button>
<pre class="meta" data-response></pre>
</form>
</section>
<section class="card">
<h2>Hardware Ingest</h2>
<form class="form" data-endpoint="/ingest/hardware">
<div class="field">
<label for="hardware">Payload (JSON)</label>
<textarea class="input" id="hardware" name="payload" rows="10">{{.HardwarePayload}}</textarea>
</div>
<div class="field">
<label for="hardwareFile">Upload a JSON snapshot (per INTEGRATION_GUIDE.md)</label>
<input class="input" id="hardwareFile" type="file" accept="application/json" />
</div>
<button class="button" type="submit">Send Hardware Snapshot</button>
<pre class="meta" data-response></pre>
</form>
</section>
</main>
<script>
const forms = document.querySelectorAll("form[data-endpoint]");
forms.forEach((form) => {
form.addEventListener("submit", async (event) => {
event.preventDefault();
const endpoint = form.getAttribute("data-endpoint");
const textarea = form.querySelector("textarea[name='payload']");
const output = form.querySelector("[data-response]");
if (!endpoint || !textarea || !output) return;
output.textContent = "Sending...";
try {
const response = await fetch(endpoint, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: textarea.value,
});
const text = await response.text();
output.textContent = `${response.status} ${response.statusText}\n${text}`;
} catch (err) {
output.textContent = `Request failed: ${err}`;
}
});
});
const hardwareFileInput = document.getElementById("hardwareFile");
const hardwareTextarea = document.getElementById("hardware");
if (hardwareFileInput && hardwareTextarea) {
hardwareFileInput.addEventListener("change", async () => {
const file = hardwareFileInput.files?.[0];
if (!file) {
return;
}
try {
const text = await file.text();
hardwareTextarea.value = text;
} catch (err) {
alert(`Failed to load file: ${err}`);
}
});
}
</script>
</body>
</html>
{{end}}