Pastebin limits: 5 MB per paste, 10 per IP and 1000 site-wide per 24 h

Creations are logged in SQLite (IP as an HMAC with a per-install key, kept
24 h), so limits survive restarts and deleting a paste doesn't refund it.
The site-wide cap also bounds storage (~5 GB worst case), replacing the
live-storage cap. Adds an Open file button to the paste page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
neil 2026-11-01 23:51:19 -08:00
parent 792d48553c
commit f4232ef9b5
3 changed files with 50 additions and 36 deletions

View file

@ -1,8 +1,8 @@
// Pastebin: /paste to create, /paste/<id> to view. Pastes expire 24 h after creation.
// Pastes made in this browser are remembered locally (with their delete tokens).
import { el, store, copyText, downloadText, toast, timeLeft, formatBytes } from '../ui.js';
import { el, store, copyText, downloadText, openTextFile, toast, timeLeft, formatBytes } from '../ui.js';
const MAX_BYTES = 1024 * 1024;
const MAX_BYTES = 5 * 1024 * 1024; // keep in step with app/tools/paste.py
function mine() {
const now = Date.now() / 1000;
@ -54,7 +54,7 @@ function renderCreate(root, ctx, timers) {
const btn = el('button.btn.primary', { onclick: submit }, 'Create paste');
const updateInfo = () => {
const n = new Blob([ta.value]).size;
info.textContent = `${formatBytes(n)} of 1 MB · expires 24 h after creation`;
info.textContent = `${formatBytes(n)} of 5 MB · expires 24 h after creation`;
info.classList.toggle('error-text', n > MAX_BYTES);
};
ta.addEventListener('input', () => {
@ -65,9 +65,17 @@ function renderCreate(root, ctx, timers) {
if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) submit();
});
async function openFile() {
const f = await openTextFile();
if (!f) return;
if (f.text.includes('\u0000')) return toast(`${f.name} looks like a binary file; only text can be pasted`, 'error');
ta.value = f.text;
ta.dispatchEvent(new Event('input'));
}
async function submit() {
if (!ta.value.trim()) return toast('Nothing to paste', 'error');
if (new Blob([ta.value]).size > MAX_BYTES) return toast('Paste is larger than 1 MB', 'error');
if (new Blob([ta.value]).size > MAX_BYTES) return toast('Paste is larger than 5 MB', 'error');
btn.disabled = true;
const p = await createPaste(ta.value);
btn.disabled = false;
@ -102,8 +110,9 @@ function renderCreate(root, ctx, timers) {
root.append(
el('div.tool.paste-tool', {},
el('div.toolbar', {}, el('strong', {}, 'New paste'), el('span.spacer'), info, btn),
el('div.paste-body', {}, ta, el('div.hint.muted.small', {}, 'Ctrl+Enter to create. Anyone with the link can read it until it expires. Don\'t paste secrets.'), list),
el('div.toolbar', {}, el('strong', {}, 'New paste'), el('span.spacer'), info,
el('button.btn', { onclick: openFile, title: 'Load a text file (up to 5 MB)' }, 'Open file'), btn),
el('div.paste-body', {}, ta, el('div.hint.muted.small', {}, 'Ctrl+Enter to create. Anyone with the link can read it until it expires. Don\'t paste secrets. Limit: 10 pastes per person per day.'), list),
),
);
ta.focus();