initial commit
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: Inter, system-ui, sans-serif;
|
||||
background: #10141a;
|
||||
color: #e5e7eb;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 900px;
|
||||
margin: 2rem auto;
|
||||
padding: 0 1rem 2rem;
|
||||
}
|
||||
|
||||
textarea {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
border: 1px solid #334155;
|
||||
border-radius: 6px;
|
||||
background: #0f172a;
|
||||
color: #e2e8f0;
|
||||
padding: 0.75rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
button {
|
||||
background: #3b82f6;
|
||||
border: 0;
|
||||
color: white;
|
||||
border-radius: 6px;
|
||||
padding: 0.6rem 1rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.error {
|
||||
margin-top: 1rem;
|
||||
color: #fecaca;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
pre {
|
||||
background: #0b1220;
|
||||
border: 1px solid #334155;
|
||||
border-radius: 6px;
|
||||
padding: 1rem;
|
||||
overflow: auto;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #93c5fd;
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Scratchbox</title>
|
||||
<link rel="stylesheet" href="/static/app.css">
|
||||
</head>
|
||||
<body>
|
||||
<main class="container">
|
||||
<h1>Scratchbox</h1>
|
||||
<p>Create an unauthenticated scratch. It expires automatically.</p>
|
||||
|
||||
<form id="scratch-form">
|
||||
<label for="content">Text content</label>
|
||||
<textarea id="content" name="content" rows="14" placeholder="Paste text here"></textarea>
|
||||
<button type="submit">Create scratch</button>
|
||||
</form>
|
||||
|
||||
<section id="result" class="hidden">
|
||||
<h2>Created</h2>
|
||||
<p><strong>View:</strong> <a id="view-link" href="#" target="_blank" rel="noreferrer"></a></p>
|
||||
<p><strong>Raw:</strong> <a id="raw-link" href="#" target="_blank" rel="noreferrer"></a></p>
|
||||
<p id="expire-text"></p>
|
||||
</section>
|
||||
|
||||
<section id="error" class="error hidden"></section>
|
||||
</main>
|
||||
|
||||
<script>
|
||||
const form = document.getElementById("scratch-form");
|
||||
const result = document.getElementById("result");
|
||||
const error = document.getElementById("error");
|
||||
const viewLink = document.getElementById("view-link");
|
||||
const rawLink = document.getElementById("raw-link");
|
||||
const expireText = document.getElementById("expire-text");
|
||||
|
||||
form.addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
result.classList.add("hidden");
|
||||
error.classList.add("hidden");
|
||||
|
||||
const content = document.getElementById("content").value;
|
||||
try {
|
||||
const response = await fetch("/api/scratch", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "text/plain; charset=utf-8" },
|
||||
body: content
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const message = await response.text();
|
||||
throw new Error(message || `request failed (${response.status})`);
|
||||
}
|
||||
|
||||
const payload = await response.json();
|
||||
viewLink.href = payload.view_url;
|
||||
viewLink.textContent = payload.view_url;
|
||||
rawLink.href = payload.raw_url;
|
||||
rawLink.textContent = payload.raw_url;
|
||||
expireText.textContent = `Expires at: ${payload.expires_at}`;
|
||||
result.classList.remove("hidden");
|
||||
} catch (err) {
|
||||
error.textContent = err.message;
|
||||
error.classList.remove("hidden");
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,26 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Scratch {{ .ID }}</title>
|
||||
<link rel="stylesheet" href="/static/app.css">
|
||||
</head>
|
||||
<body>
|
||||
<main class="container">
|
||||
<h1>Scratch {{ .ID }}</h1>
|
||||
<p>Content type: <code>{{ .ContentType }}</code></p>
|
||||
<p>Expires at: {{ .ExpiresAt }}</p>
|
||||
<p><a href="{{ .RawURL }}">Open raw</a></p>
|
||||
|
||||
{{ if .Binary }}
|
||||
<p>This scratch looks binary and is not rendered in-page. Use the raw link.</p>
|
||||
{{ else }}
|
||||
<pre>{{ .Content }}</pre>
|
||||
{{ if .Truncated }}
|
||||
<p>Preview truncated to 2MB. Open raw for full content.</p>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user