adds frontend
This commit is contained in:
153
public/assets/app.css
Normal file
153
public/assets/app.css
Normal file
@@ -0,0 +1,153 @@
|
||||
:root {
|
||||
color-scheme: light;
|
||||
--bg: #f6f5f1;
|
||||
--surface: #ffffff;
|
||||
--ink: #161616;
|
||||
--muted: #696963;
|
||||
--line: #d8d6ce;
|
||||
--accent: #2f7664;
|
||||
--accent-strong: #245d50;
|
||||
--danger: #a43d32;
|
||||
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
html,
|
||||
body {
|
||||
min-height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
background: var(--bg);
|
||||
color: var(--ink);
|
||||
}
|
||||
|
||||
button,
|
||||
input {
|
||||
font: inherit;
|
||||
letter-spacing: 0;
|
||||
}
|
||||
|
||||
.shell {
|
||||
min-height: 100vh;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.archive-box {
|
||||
width: min(680px, 100%);
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 8px;
|
||||
padding: 12px;
|
||||
box-shadow: 0 18px 42px rgba(28, 25, 19, 0.08);
|
||||
}
|
||||
|
||||
.input-row {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr auto;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
input {
|
||||
min-width: 0;
|
||||
width: 100%;
|
||||
height: 48px;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 6px;
|
||||
color: var(--ink);
|
||||
background: #fbfaf7;
|
||||
padding: 0 14px;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
input:focus {
|
||||
border-color: var(--accent);
|
||||
box-shadow: 0 0 0 3px rgba(47, 118, 100, 0.16);
|
||||
}
|
||||
|
||||
button {
|
||||
height: 48px;
|
||||
min-width: 112px;
|
||||
border: 0;
|
||||
border-radius: 6px;
|
||||
color: #ffffff;
|
||||
background: var(--accent);
|
||||
padding: 0 18px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background: var(--accent-strong);
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
cursor: wait;
|
||||
opacity: 0.72;
|
||||
}
|
||||
|
||||
.progress-wrap {
|
||||
padding-top: 12px;
|
||||
}
|
||||
|
||||
.progress-track {
|
||||
height: 6px;
|
||||
overflow: hidden;
|
||||
border-radius: 999px;
|
||||
background: #e7e4dc;
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
width: 0%;
|
||||
height: 100%;
|
||||
border-radius: inherit;
|
||||
background: var(--accent);
|
||||
transition: width 220ms ease;
|
||||
}
|
||||
|
||||
.status-line {
|
||||
min-height: 22px;
|
||||
margin-top: 8px;
|
||||
color: var(--muted);
|
||||
font-size: 14px;
|
||||
line-height: 22px;
|
||||
}
|
||||
|
||||
.status-line.error {
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap;
|
||||
clip-path: inset(50%);
|
||||
}
|
||||
|
||||
@media (max-width: 560px) {
|
||||
.shell {
|
||||
align-items: start;
|
||||
padding: 16px;
|
||||
padding-top: 20vh;
|
||||
}
|
||||
|
||||
.archive-box {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.input-row {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
button {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
169
public/assets/app.js
Normal file
169
public/assets/app.js
Normal file
@@ -0,0 +1,169 @@
|
||||
const form = document.querySelector("#archive-form");
|
||||
const input = document.querySelector("#archive-url");
|
||||
const button = document.querySelector("#archive-submit");
|
||||
const progressWrap = document.querySelector("#progress-wrap");
|
||||
const progressBar = document.querySelector("#progress-bar");
|
||||
const statusLine = document.querySelector("#status-line");
|
||||
|
||||
let pollTimer = null;
|
||||
let visualTimer = null;
|
||||
let startedAt = Date.now();
|
||||
|
||||
form.addEventListener("submit", (event) => {
|
||||
event.preventDefault();
|
||||
submitArchive(input.value);
|
||||
});
|
||||
|
||||
const pathUrl = urlFromPath();
|
||||
if (pathUrl) {
|
||||
input.value = pathUrl;
|
||||
submitArchive(pathUrl);
|
||||
} else {
|
||||
input.focus();
|
||||
}
|
||||
|
||||
async function submitArchive(rawUrl) {
|
||||
stopTimers();
|
||||
setBusy(true);
|
||||
setStatus("Checking", 8);
|
||||
|
||||
try {
|
||||
const response = await fetch("/api/archives", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"content-type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({ url: rawUrl })
|
||||
});
|
||||
const data = await readApiResponse(response);
|
||||
if (data.archive?.archiveUrl) {
|
||||
openArchive(data.archive.archiveUrl);
|
||||
return;
|
||||
}
|
||||
if (data.job?.id) {
|
||||
watchJob(data.job);
|
||||
return;
|
||||
}
|
||||
throw new Error(data.error || "Archive did not start");
|
||||
} catch (error) {
|
||||
setError(error.message || "Archive failed");
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
function watchJob(job) {
|
||||
startedAt = Date.parse(job.startedAt || job.createdAt) || Date.now();
|
||||
updateFromJob(job);
|
||||
visualTimer = window.setInterval(updateVisualProgress, 250);
|
||||
pollTimer = window.setInterval(async () => {
|
||||
try {
|
||||
const response = await fetch(`/api/jobs/${encodeURIComponent(job.id)}`);
|
||||
const data = await readApiResponse(response);
|
||||
updateFromJob(data.job);
|
||||
} catch (error) {
|
||||
stopTimers();
|
||||
setError(error.message || "Archive failed");
|
||||
setBusy(false);
|
||||
}
|
||||
}, 850);
|
||||
}
|
||||
|
||||
function updateFromJob(job) {
|
||||
if (job.status === "done" && job.archive?.archiveUrl) {
|
||||
stopTimers();
|
||||
setStatus("Opening", 100);
|
||||
openArchive(job.archive.archiveUrl);
|
||||
return;
|
||||
}
|
||||
|
||||
if (job.status === "failed") {
|
||||
stopTimers();
|
||||
setError(job.error || "Archive failed");
|
||||
setBusy(false);
|
||||
return;
|
||||
}
|
||||
|
||||
startedAt = Date.parse(job.startedAt || job.createdAt) || startedAt;
|
||||
const elapsed = Math.max(0, Math.round((Date.now() - startedAt) / 1000));
|
||||
const label = job.status === "queued" ? "Queued" : `Archiving ${elapsed}s`;
|
||||
setStatus(label, optimisticProgress());
|
||||
}
|
||||
|
||||
function updateVisualProgress() {
|
||||
if (!progressWrap.hidden) {
|
||||
progressBar.style.width = `${optimisticProgress()}%`;
|
||||
}
|
||||
}
|
||||
|
||||
function optimisticProgress() {
|
||||
const elapsed = Math.max(0, (Date.now() - startedAt) / 1000);
|
||||
if (elapsed < 1) {
|
||||
return 12;
|
||||
}
|
||||
if (elapsed < 12) {
|
||||
return Math.min(88, 12 + elapsed * 6.3);
|
||||
}
|
||||
return Math.min(96, 88 + (elapsed - 12) * 0.6);
|
||||
}
|
||||
|
||||
async function readApiResponse(response) {
|
||||
const data = await response.json().catch(() => null);
|
||||
if (!response.ok || data?.ok === false) {
|
||||
throw new Error(data?.error || `Request failed with ${response.status}`);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
function setBusy(isBusy) {
|
||||
button.disabled = isBusy;
|
||||
input.readOnly = isBusy;
|
||||
}
|
||||
|
||||
function setStatus(text, progress) {
|
||||
progressWrap.hidden = false;
|
||||
statusLine.classList.remove("error");
|
||||
statusLine.textContent = text;
|
||||
progressBar.style.width = `${Math.max(0, Math.min(100, progress))}%`;
|
||||
}
|
||||
|
||||
function setError(text) {
|
||||
progressWrap.hidden = false;
|
||||
statusLine.classList.add("error");
|
||||
statusLine.textContent = text;
|
||||
progressBar.style.width = "100%";
|
||||
}
|
||||
|
||||
function stopTimers() {
|
||||
if (pollTimer) {
|
||||
window.clearInterval(pollTimer);
|
||||
pollTimer = null;
|
||||
}
|
||||
if (visualTimer) {
|
||||
window.clearInterval(visualTimer);
|
||||
visualTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
function openArchive(archiveUrl) {
|
||||
window.location.assign(archiveUrl);
|
||||
}
|
||||
|
||||
function urlFromPath() {
|
||||
const rawPath = window.location.pathname.replace(/^\/+/, "");
|
||||
if (!rawPath || rawPath.startsWith("assets/") || rawPath.startsWith("api/") || rawPath.startsWith("archives/")) {
|
||||
return "";
|
||||
}
|
||||
|
||||
let decoded;
|
||||
try {
|
||||
decoded = decodeURIComponent(rawPath);
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (!/^https?:\/\//i.test(decoded)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return `${decoded}${window.location.search}${window.location.hash}`;
|
||||
}
|
||||
Reference in New Issue
Block a user