From 67849def05246dca036cba75fca2fbaa8fc2ebc2 Mon Sep 17 00:00:00 2001 From: whoswhip Date: Sat, 21 Nov 2026 18:05:30 -0500 Subject: [PATCH] moved to web, forgot to exclude in gitignore --- .gitignore | 3 +- web/static/css/main.css | 336 ++++++++++++++++++++++++++++++++++++ web/static/js/copy.js | 18 ++ web/static/js/dnd.js | 46 +++++ web/static/js/pow-worker.js | 32 ++++ web/static/js/report.js | 17 ++ web/templates/faq.html | 69 ++++++++ web/templates/header.html | 12 ++ web/templates/home.html | 73 ++++++++ web/templates/privacy.html | 47 +++++ web/templates/report.html | 49 ++++++ web/templates/result.html | 23 +++ web/templates/tos.html | 53 ++++++ web/templates/upload.html | 105 +++++++++++ 14 files changed, 881 insertions(+), 2 deletions(-) create mode 100644 web/static/css/main.css create mode 100644 web/static/js/copy.js create mode 100644 web/static/js/dnd.js create mode 100644 web/static/js/pow-worker.js create mode 100644 web/static/js/report.js create mode 100644 web/templates/faq.html create mode 100644 web/templates/header.html create mode 100644 web/templates/home.html create mode 100644 web/templates/privacy.html create mode 100644 web/templates/report.html create mode 100644 web/templates/result.html create mode 100644 web/templates/tos.html create mode 100644 web/templates/upload.html diff --git a/.gitignore b/.gitignore index 0661755..8d9031a 100644 --- a/.gitignore +++ b/.gitignore @@ -17,8 +17,7 @@ !README.md !LICENSE -!/templates/** -!/static/** +!web/** !.prettierrc !.env.example diff --git a/web/static/css/main.css b/web/static/css/main.css new file mode 100644 index 0000000..93b77c9 --- /dev/null +++ b/web/static/css/main.css @@ -0,0 +1,336 @@ +:root { + --bg: #191919; + --surface: #2a2a2a; + --surface-between: #3a3a3a; + --surface-hover: #4a4a4a; + --text: #eee; + --text-muted: #aaa; + --border: #4e4e4e; + --border-strong: #7e7e7e; +} + +* { + box-sizing: border-box; +} + +body { + min-height: 100vh; + background-color: var(--bg); + color: var(--text); + margin: 0; + font-family: Consolas, monospace; + font-size: 14px; + background-image: var(--qt-url); + background-repeat: no-repeat; + background-position: bottom right; + background-size: auto 256px; + background-attachment: fixed; +} + +b { + font-weight: bold; +} + +h1, +h2 { + margin: 0; + font-weight: 400; +} + +h4 { + margin: 6px 0; +} + +h1 { + font-size: 18px; + font-weight: 700; +} + +a { + color: var(--text); +} + +main { + width: min(100% - 36px, 720px); + margin: 0 auto; + padding: 11px 0 64px; +} + +.site-header { + width: min(100% - 36px, 720px); + margin: 0 auto; + padding: 44px 0 0; + display: flex; + justify-content: space-between; +} + +textarea { + background: var(--bg); + display: block; + width: 100%; + min-height: 120px; + height: 120px; + resize: vertical; + border: 1px solid var(--border); + font: inherit; + padding: 12px; + outline: none; + color: var(--text); + margin-bottom: 12px; +} + +textarea:focus { + border-color: var(--border-strong); +} + +input[type="text"] { + background: var(--bg); + display: block; + width: 100%; + border: 1px solid var(--border); + font: inherit; + padding: 12px; + outline: none; + color: var(--text); + margin-top: 6px; + margin-bottom: 12px; +} + +input[type="text"]:focus { + border-color: var(--border-strong); +} + +.upload-tabs { + display: flex; + flex-wrap: wrap; + gap: 0.75rem; +} + +.upload-tabs > label { + cursor: pointer; + border-bottom: 1px solid transparent; + color: var(--text-muted); +} + +.upload-tabs > input { + position: absolute; + width: 1px; + height: 1px; + overflow: hidden; + clip-path: inset(50%); +} + +.upload-tabs > input:checked + label { + border-bottom-color: currentColor; + color: var(--text); +} + +.upload-tabs > input:focus-visible + label { + border: 1px solid currentColor; +} + +.file-panel, +.paste-panel { + display: none; + width: 100%; +} + +#type-file:checked ~ .file-panel, +#type-paste:checked ~ .paste-panel { + display: block; +} + +input[type="file"] { + display: block; + border: 1px solid var(--border); + color: var(--text); + width: 100%; + cursor: pointer; + margin-bottom: 12px; + font: inherit; +} + +input[type="file"]:hover { + background-color: var(--surface); +} +input[type="file"]:hover::file-selector-button { + background-color: var(--surface-hover); +} + +input[type="file"]::file-selector-button { + background-color: var(--surface); + border: none; + color: var(--text); + padding: 10px; + font: inherit; +} + +.muted { + color: var(--text-muted); +} +select { + padding: 0 0 2px; + background: var(--bg); + border: none; + color: var(--text); + border-bottom: 1px solid var(--border-strong); + border-radius: 0; + font: inherit; + margin-bottom: 12px; +} + +option { + background-color: var(--bg); + font: inherit; +} + +.btn { + border-radius: 0; + border: none; + background-color: var(--text); + padding: 11px; + color: var(--surface); + font: inherit; + cursor: pointer; +} + +.btn:hover { + background-color: var(--text-muted); +} + +.btn:disabled { + background-color: var(--surface); + color: var(--text-muted); + cursor: not-allowed; +} + +.link-btn { + border: none; + background: none; + padding: 0; + text-decoration: underline; + color: var(--text); + cursor: pointer; + font: inherit; +} + +img, +video, +audio { + max-width: 100%; + max-height: 80dvh; +} + +.upload-links { + margin-top: 12px; + display: flex; + flex-direction: row; + gap: 12px; + align-items: baseline; +} + +.upload-links form { + margin: 0; +} + +body.dragging::after { + content: "drop file to select"; + position: fixed; + inset: 0; + z-index: 100; + display: grid; + place-items: center; + background: rgb(0 0 0 / 30%); + color: var(--text); + font-size: 1.5rem; + pointer-events: none; +} + +.upload-metadata { + width: 100%; + table-layout: fixed; + border-collapse: collapse; +} + +.upload-metadata th, +.upload-metadata td { + padding: 8px 0; + border-bottom: 1px solid var(--border); + text-align: left; + vertical-align: top; + overflow-wrap: anywhere; +} + +.upload-metadata th:first-child { + width: 20%; + padding-right: 16px; +} + +.upload-metadata th[scope="row"] { + color: var(--text-muted); + font-weight: bold; +} + +code { + background-color: var(--surface-between); + padding-inline: 3px; + border: 1px solid var(--surface-hover); +} + +.submit-container { + width: 100%; + display: flex; + justify-content: space-between; + align-items: center; +} + +.noscript { + border: var(--border-strong); + background-color: var(--surface-between); + width: 100%; + display: block; + font-size: larger; + padding: 0.5rem; + margin-bottom: 5px; +} + +.full-dropdown { + background: var(--bg); + display: block; + width: 100%; + border: 1px solid var(--border); + font: inherit; + padding: 12px; + outline: none; + color: var(--text); + margin-top: 6px; + margin-bottom: 12px; +} + +.loading { + position: relative; + overflow: hidden; + background: var(--surface); + isolation: isolate; +} + +.loading::before { + content: ""; + position: absolute; + inset: 0; + width: 200%; + background: repeating-linear-gradient( + 45deg, + var(--surface-hover) 0 25%, + transparent 25% 50% + ); + background-size: 1em 1em; + animation: barStripe 1s linear infinite; + z-index: -1; +} + +@keyframes barStripe { + to { + transform: translateX(-1em); + } +} \ No newline at end of file diff --git a/web/static/js/copy.js b/web/static/js/copy.js new file mode 100644 index 0000000..1293964 --- /dev/null +++ b/web/static/js/copy.js @@ -0,0 +1,18 @@ +const link = document.getElementById("copy-link"); + +if (link && navigator.clipboard?.writeText) { + link.style.display = ""; + link.hidden = false; + link.onclick = async (e) => { + e.preventDefault(); + try { + await navigator.clipboard.writeText(`${location.origin}/${link.dataset.id}${link.dataset.extension}`); + link.textContent = "copied"; + setTimeout(() => { + link.textContent = "copy link"; + }, 2000); + } catch (error) { + console.error("failed to copy link:", error); + } + }; +} diff --git a/web/static/js/dnd.js b/web/static/js/dnd.js new file mode 100644 index 0000000..80a5fa1 --- /dev/null +++ b/web/static/js/dnd.js @@ -0,0 +1,46 @@ +const fileInput = document.getElementById("upload-file"); + +function isFile(event) { + return event.dataTransfer.types.includes("Files"); +} + +function resetDrag() { + document.body.classList.remove("dragging"); +} + +document.addEventListener("dragenter", (event) => { + if (!isFile(event)) return; + + event.preventDefault(); + document.body.classList.add("dragging"); +}); + +document.addEventListener("dragover", (event) => { + if (!isFile(event)) return; + + event.preventDefault(); + event.dataTransfer.dropEffect = "copy"; +}); + +document.addEventListener("dragleave", () => { + resetDrag(); +}); + +document.addEventListener("drop", (event) => { + resetDrag(); + if (!isFile(event)) return; + + event.preventDefault(); + + const file = event.dataTransfer.files[0]; + if (!file) return; + + const transfer = new DataTransfer(); + transfer.items.add(file); + fileInput.files = transfer.files; + + document.getElementById("type-file").checked = true; + fileInput.dispatchEvent(new Event("change", { bubbles: true })); +}); + +document.addEventListener("dragend", resetDrag); diff --git a/web/static/js/pow-worker.js b/web/static/js/pow-worker.js new file mode 100644 index 0000000..d834a67 --- /dev/null +++ b/web/static/js/pow-worker.js @@ -0,0 +1,32 @@ +function hasLeadingZeroBits(bytes, requiredBits) { + const whole = Math.floor(requiredBits / 8); + const remaining = requiredBits % 8; + for (let i = 0; i < whole; i++) { + if (bytes[i] !== 0) return false; + } + return remaining === 0 || bytes[whole] >>> (8 - remaining) === 0; +} + +self.onmessage = async ({ data }) => { + const { challenge, difficulty, startNonce = 0 } = data; + if (difficulty < 0 || difficulty > 256 || !Number.isInteger(difficulty)) { + throw new Error("Invalid difficulty"); + } + console.log(`[PoW] Difficulty: ${difficulty}, Starting Nonce: ${startNonce}, Challenge: ${challenge}`) + const startTime = performance.now(); + const encoder = new TextEncoder(); + for (let nonce = startNonce; ; nonce++) { + const input = encoder.encode(`${challenge}${nonce}`); + const digest = new Uint8Array(await crypto.subtle.digest("SHA-256", input)); + if (hasLeadingZeroBits(digest, difficulty)) { + const hashHex = Array.from(digest).map((b) => b.toString(16).padStart(2, "0")).join(""); + const elapsed = performance.now() - startTime; + const attempts = nonce - startNonce + 1; + console.log(`[PoW] took ${elapsed} ms to solve challenge`) + console.log(`[PoW] ${(attempts / (elapsed / 1000)).toFixed(0)} hashes/s`) + console.log(`[PoW] Result: ${hashHex}, Nonce: ${nonce}`) + self.postMessage({ nonce: nonce, hash: hashHex, }); + return; + } + } +}; \ No newline at end of file diff --git a/web/static/js/report.js b/web/static/js/report.js new file mode 100644 index 0000000..f85b76f --- /dev/null +++ b/web/static/js/report.js @@ -0,0 +1,17 @@ +const worker = new Worker("/js/pow-worker.js"); +const reportForm = document.getElementById("report-form"); +const submitBtn = document.getElementById("submit-btn"); +const powLabel = document.getElementById("pow-label"); +const challenge = reportForm.dataset; +submitBtn.disabled = true; +worker.onmessage = ({ data }) => { + submitBtn.disabled = false; + powLabel.style.display = "none"; + submitBtn.classList.remove("loading"); + document.getElementById("pow-result").value = data.hash; + document.getElementById("pow-nonce").value = data.nonce; +} +worker.postMessage({ + challenge: reportForm.dataset.challengeData, + difficulty: Number.parseInt(reportForm.dataset.challengeDifficulty, 10), +}) \ No newline at end of file diff --git a/web/templates/faq.html b/web/templates/faq.html new file mode 100644 index 0000000..670bb39 --- /dev/null +++ b/web/templates/faq.html @@ -0,0 +1,69 @@ + + + + + + faq | minibin + + {{if .Qt}} + + {{end}} + + + {{template "site-header"}} +
+

frequently asked questions

+

how long are uploads/files kept for?

+

+ minibin will store them for as long as their set expiry, unless they + violate the TOS or have not been accessed in a long time. +

+

are uploads modified in any way?

+

+ no, all uploads are exactly the same as what you uploaded. uploads are + not compressed, transformed, or modified in any way, not even exif data. +

+

+ be wary of any metadata included in the files you are uploading, + especially photos from a phone as they may contain GPS data. +

+ {{if .NormalizeMIMETypes}} +

why are my html/svg/pdf uploads not being rendered?

+

they are being normalized for security.

+ {{end}} +

api usage

+

how do i upload via the api?

+

+ send a POST request to /upload. for files, use multipart + form data with a field named file. for pastes, send the + text with Content-Type: text/plain. +

+

+ to add an expiry, append ?expiry={value}.
supported + values are: + {{range $i, $expiry := .Expiries}}{{if + $i}},{{end}}{{$expiry.Label}}{{end}}. omitting an expiry will use the first expiry listed. +

+

+ you can also specify if you would prefer a long or short upload id, just + append
?idlength=short to get a shorter id (10 characters), + otherwise it defaults to long (16 character) +

+

uploading the output of a command

+ cat super-cool-text.txt | curl -T - {{.Host}}/upload +

upload a file via curl

+ curl -F "file=@very-cool-image.png" {{.Host}}/upload +

getting upload info

+

+ you can retrieve an upload's metadata by simply appending /info to the end of an upload, like /{id}/info. + it returns all stored metadata except for the original filename. +

+
+ + diff --git a/web/templates/header.html b/web/templates/header.html new file mode 100644 index 0000000..9e56c66 --- /dev/null +++ b/web/templates/header.html @@ -0,0 +1,12 @@ +{{define "site-header"}} + +{{end}} diff --git a/web/templates/home.html b/web/templates/home.html new file mode 100644 index 0000000..0d76ea6 --- /dev/null +++ b/web/templates/home.html @@ -0,0 +1,73 @@ + + + + + + minibin + + + {{if .Qt}} + + {{end}} + + + + + + + {{template "site-header"}} +
+

simple file and paste hosting service

+
+ + + + +
+
+ + + + + +
+ + max {{.FileMaxSize}} +
+
+
+
+
+ + + + + +
+ + max {{.PasteMaxSize}} +
+
+
+
+
+ + diff --git a/web/templates/privacy.html b/web/templates/privacy.html new file mode 100644 index 0000000..bb5ca9a --- /dev/null +++ b/web/templates/privacy.html @@ -0,0 +1,47 @@ + + + + + + privacy | minibin + + {{if .}} + + {{end}} + + + {{template "site-header"}} +
+

privacy policy

+

what we store

+

when you upload a file or paste, we store:

+ +

+ this information is used to serve uploads, check expiry, and allow + deletion of uploads. +

+ +

who can access uploads

+

+ anyone with the id of an upload can access and share it. minibin's + operator can also access stored uploads. avoid uploading anything + private. +

+

changes to this policy

+

+ this policy may change as minibin changes. updates will be posted on + this page. +

+
+ + diff --git a/web/templates/report.html b/web/templates/report.html new file mode 100644 index 0000000..2b8704b --- /dev/null +++ b/web/templates/report.html @@ -0,0 +1,49 @@ + + + + + + report | minibin + + + {{if .Qt}} + + {{end}} + + + {{template "site-header"}} + +
+ +
+ + + + + + + +
+ + computing proof of work +
+
+
+ + diff --git a/web/templates/result.html b/web/templates/result.html new file mode 100644 index 0000000..8be0b08 --- /dev/null +++ b/web/templates/result.html @@ -0,0 +1,23 @@ + + + + + + {{.Title}} | minibin + + {{if .Qt}} + + {{end}} + + + {{template "site-header"}} +
+

{{.Title}}

+

{{.Message}}

+
+ + diff --git a/web/templates/tos.html b/web/templates/tos.html new file mode 100644 index 0000000..9eff901 --- /dev/null +++ b/web/templates/tos.html @@ -0,0 +1,53 @@ + + + + + + tos | minibin + + {{if .}} + + {{end}} + + + {{template "site-header"}} +
+

terms of service

+

by using minibin, you agree to these terms.

+

acceptable use

+

+ you are responsible for what you upload and share. only upload content + that you own or are allowed to share. +

+

prohibited content

+

do not upload or share:

+ +

storage and expiry

+

+ uploads have an expiry based on the option selected when uploading. + indefinite means there is no scheduled expiry. +

+

+ uploads may be removed earlier for breaking these terms, maintenance or + storage limits. ensure you keep a copy of anything important. +

+ +

deleting uploads

+

+ keep the delete token provided after uploading. anyone with that token + is able to delete the upload, so keep it private. +

+

changes to these terms

+

these terms may change, updates with be posted on this page.

+
+ + diff --git a/web/templates/upload.html b/web/templates/upload.html new file mode 100644 index 0000000..15ef924 --- /dev/null +++ b/web/templates/upload.html @@ -0,0 +1,105 @@ + + + + + + {{.ID}} | minibin + + {{if .Qt}} + + {{end}} + + + + {{template "site-header"}} +
+
+ {{if hasPrefix .MIMEType "image/"}} + + {{else if hasPrefix .MIMEType "video/"}} + + {{else if hasPrefix .MIMEType "audio/"}} + + {{else}} +

{{.Filename}}

+

{{.ID}}{{.FileExtension}}

+ {{end}} +
+ +
+ upload metadata + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ +