mirror of
https://github.com/skidoodle/safebin.git
synced 2026-04-28 03:07:41 +02:00
feat: initial release
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
:root {
|
||||
--bg: #0d1117;
|
||||
--fg: #adbac7;
|
||||
--accent: #4493f8;
|
||||
--border: #30363d;
|
||||
--success: #3fb950;
|
||||
--header-white: #f0f6fc;
|
||||
}
|
||||
|
||||
body {
|
||||
background: var(--bg);
|
||||
color: var(--fg);
|
||||
font-family: -apple-system, system-ui, sans-serif;
|
||||
margin: 0;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.container {
|
||||
width: 100%;
|
||||
max-width: 600px;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.header {
|
||||
margin-bottom: 30px;
|
||||
border-left: 3px solid var(--accent);
|
||||
padding-left: 16px;
|
||||
}
|
||||
|
||||
.upload-area {
|
||||
border: 2px dashed var(--border);
|
||||
border-radius: 12px;
|
||||
padding: 60px 20px;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
background: #161b22;
|
||||
transition: 0.2s;
|
||||
}
|
||||
|
||||
.upload-area:hover,
|
||||
.upload-area.dragover {
|
||||
border-color: var(--accent);
|
||||
background: #1c2128;
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
height: 6px;
|
||||
background: var(--border);
|
||||
border-radius: 10px;
|
||||
margin: 25px 0;
|
||||
overflow: hidden;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.progress-fill {
|
||||
height: 100%;
|
||||
background: var(--accent);
|
||||
width: 0%;
|
||||
transition: width 0.3s;
|
||||
}
|
||||
|
||||
.copy-box {
|
||||
display: flex;
|
||||
margin-top: 20px;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
input[type="text"] {
|
||||
flex: 1;
|
||||
background: #0d1117;
|
||||
border: 1px solid var(--border);
|
||||
color: var(--success);
|
||||
padding: 12px;
|
||||
border-radius: 6px;
|
||||
font-family: monospace;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
button {
|
||||
background: var(--accent);
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 10px 20px;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.reset-btn {
|
||||
background: transparent;
|
||||
color: var(--fg);
|
||||
text-decoration: underline;
|
||||
margin-top: 20px;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.dim {
|
||||
color: #768390;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.error-text {
|
||||
color: #f85149;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
const $ = (id) => document.getElementById(id);
|
||||
const dropZone = $("drop-zone");
|
||||
const fileInput = $("file-input");
|
||||
|
||||
if (dropZone) {
|
||||
dropZone.onclick = () => {
|
||||
if ($("idle-state").style.display !== "none") fileInput.click();
|
||||
};
|
||||
|
||||
fileInput.onchange = () => {
|
||||
if (fileInput.files[0]) handleUpload(fileInput.files[0]);
|
||||
};
|
||||
|
||||
["dragenter", "dragover"].forEach((n) =>
|
||||
dropZone.addEventListener(n, (e) => {
|
||||
e.preventDefault();
|
||||
dropZone.classList.add("dragover");
|
||||
}),
|
||||
);
|
||||
|
||||
["dragleave", "drop"].forEach((n) =>
|
||||
dropZone.addEventListener(n, (e) => {
|
||||
e.preventDefault();
|
||||
dropZone.classList.remove("dragover");
|
||||
}),
|
||||
);
|
||||
|
||||
dropZone.addEventListener("drop", (e) => {
|
||||
e.preventDefault();
|
||||
if (e.dataTransfer.files.length) handleUpload(e.dataTransfer.files[0]);
|
||||
});
|
||||
}
|
||||
|
||||
async function handleUpload(file) {
|
||||
$("idle-state").style.display = "none";
|
||||
$("busy-state").style.display = "block";
|
||||
|
||||
const uploadID = Math.random().toString(36).substring(2, 15);
|
||||
const chunkSize = 1024 * 1024 * 8;
|
||||
const total = Math.ceil(file.size / chunkSize);
|
||||
|
||||
try {
|
||||
for (let i = 0; i < total; i++) {
|
||||
const fd = new FormData();
|
||||
fd.append("upload_id", uploadID);
|
||||
fd.append("index", i);
|
||||
fd.append("chunk", file.slice(i * chunkSize, (i + 1) * chunkSize));
|
||||
const res = await fetch("/upload/chunk", { method: "POST", body: fd });
|
||||
if (!res.ok) throw new Error();
|
||||
$("p-fill").style.width = ((i + 1) / total) * 100 + "%";
|
||||
}
|
||||
|
||||
const finalFd = new FormData();
|
||||
finalFd.append("upload_id", uploadID);
|
||||
finalFd.append("filename", file.name);
|
||||
finalFd.append("total", total);
|
||||
|
||||
const res = await fetch("/upload/finish", {
|
||||
method: "POST",
|
||||
body: finalFd,
|
||||
headers: { "X-Requested-With": "XMLHttpRequest" },
|
||||
});
|
||||
|
||||
$("busy-state").style.display = "none";
|
||||
$("result-state").innerHTML = await res.text();
|
||||
} catch (e) {
|
||||
$("busy-state").style.display = "none";
|
||||
$("result-state").innerHTML = `<div class="error-text">Upload Failed</div><button class="reset-btn" onclick="resetUI()">Try again</button>`;
|
||||
}
|
||||
}
|
||||
|
||||
function copyToClipboard(btn) {
|
||||
const input = $("share-url");
|
||||
input.select();
|
||||
const fullUrl = window.location.protocol + "//" + input.value;
|
||||
navigator.clipboard.writeText(fullUrl);
|
||||
btn.innerText = "Copied!";
|
||||
setTimeout(() => (btn.innerText = "Copy"), 2000);
|
||||
}
|
||||
|
||||
function resetUI() {
|
||||
location.reload();
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
{{define "base"}}
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>safebin</title>
|
||||
<link rel="stylesheet" href="/static/css/style.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<header class="header">
|
||||
<h2 style="margin: 0; color: var(--header-white)">safebin</h2>
|
||||
<div class="dim">Encrypted Temporary File Storage</div>
|
||||
</header>
|
||||
|
||||
{{template "content" .}}
|
||||
|
||||
<section style="margin-top: 40px; padding-top: 24px; border-top: 1px solid var(--border)">
|
||||
<div class="dim" style="text-transform: uppercase; font-size: 11px; font-weight: 700; letter-spacing: 1px">CLI Usage</div>
|
||||
<pre style="background: #161b22; padding: 16px; border-radius: 8px; font-size: 13px; overflow-x: auto; border: 1px solid var(--border)">
|
||||
curl -F file=@yourfile {{.Host}}</pre
|
||||
>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<input type="file" id="file-input" style="display: none" />
|
||||
<script src="/static/js/app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
{{end}}
|
||||
@@ -0,0 +1,18 @@
|
||||
{{define "content"}}
|
||||
<main class="upload-area" id="drop-zone">
|
||||
<div id="idle-state">
|
||||
<div style="font-size: 32px; color: var(--accent)">↑</div>
|
||||
<div style="font-weight: 500; color: var(--header-white)">Click or drag to upload</div>
|
||||
<div class="dim">Max size: {{.MaxMB}}MB</div>
|
||||
</div>
|
||||
|
||||
<div id="busy-state" style="display: none">
|
||||
<div id="status-msg" style="font-weight: 500">Uploading...</div>
|
||||
<div class="progress-bar" id="p-bar-container" style="display: block">
|
||||
<div class="progress-fill" id="p-fill"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="result-state"></div>
|
||||
</main>
|
||||
{{end}}
|
||||
Reference in New Issue
Block a user