create-schematic-gen-site/site/files.js

36 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

const addInputButton = document.getElementById("add-input-button");
const schematicInputSectionTemplate = document.getElementById("schematic-input-section").cloneNode(true);
const schematicInputSectionContainer = document.getElementById("schematic-input-section").parentElement;
addInputButton.onclick = () => {
const newSection = schematicInputSectionTemplate.cloneNode(true);
schematicInputSectionContainer.appendChild(newSection);
};
const resultContainer = document.getElementById("result-container");
const form = document.getElementById("schematic-form");
2023-07-15 22:22:48 +00:00
form.onsubmit = async (e) => {
e.preventDefault();
2023-07-16 16:34:13 +00:00
resultContainer.innerHTML = "<p>Uploading and extracting contents...</p>";
2023-07-15 22:22:48 +00:00
const data = new FormData(form);
const processingTerminal = data.get("processing-terminal");
2023-07-15 22:22:48 +00:00
try {
const response = await fetch("/extracts", {
method: "POST",
body: data
});
if (response.status === 200) {
const result = await response.json();
const extractId = result.extractId;
const url = window.location.origin + "/extracts/" + extractId;
resultContainer.innerHTML = `<p>Copy this URL, and provide it to your computer extraction terminal: <a href="${url}">${url}</a></p>`;
form.reset();
} else {
const message = await response.text();
resultContainer.innerHTML = `<p>Submission failed: <em>${message}</em></p>`;
}
2023-07-15 22:22:48 +00:00
} catch (error) {
console.error("Error: " + error);
resultContainer.innerHTML = `<p>An error occurred: ${error}</p>`;
2023-07-15 22:22:48 +00:00
}
};