Skip to content

gitflarePublicPartly agent-ready50

cf-r2-drop

Drag-and-drop file sharing on Cloudflare R2: multipart uploads, expiring share links, previews, download counts, lifecycle expiry.

Serve the share page from the extensionless asset path0e4544f
JavaScript21 lines2.0 KB
export const $ = (s, r = document) => r.querySelector(s);export function h(tag, attrs = {}, ...kids) {  const e = document.createElement(tag);  for (const [k, v] of Object.entries(attrs)) {    if (k.startsWith("on")) e.addEventListener(k.slice(2), v); else if (v === true) e.setAttribute(k, ""); else if (v !== false && v != null) e.setAttribute(k, v);  }  e.append(...kids.flat().filter((x) => x != null)); return e;}export const icon = (d) => { const t = document.createElement("template");  t.innerHTML = `<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="${d}"/></svg>`; return t.content.firstChild; };export const ICONS = { copy: "M9 9h11v11H9zM5 15V5h10", x: "M6 6l12 12M18 6 6 18", pause: "M8 5v14M16 5v14", play: "M7 5l12 7-12 7z", retry: "M4 12a8 8 0 1 0 3-6M4 4v5h5", dl: "M12 4v12m0 0-5-5m5 5 5-5M5 20h14" };const KEY = "r2drop.links";export const loadLinks = () => { try { return JSON.parse(localStorage.getItem(KEY)) || []; } catch { return []; } };export const saveLinks = (l) => localStorage.setItem(KEY, JSON.stringify(l));export function rememberLink(l) { const all = loadLinks().filter((x) => x.fileId !== l.fileId && x.token !== l.token); all.unshift(l); saveLinks(all.slice(0, 200)); }export function forgetLink(token) { saveLinks(loadLinks().filter((x) => x.token !== token)); }export async function copyText(t) {  try { await navigator.clipboard.writeText(t); return true; } catch { return false; }}export const header = (cur) => `<header class="top"><a class="brand" href="/"><svg width="24" height="24" viewBox="0 0 32 32" aria-hidden="true"><rect width="32" height="32" rx="8" fill="var(--accent)"/><path d="M16 22V9m0 0-6 6m6-6 6 6M9 24h14" fill="none" stroke="var(--on-accent)" stroke-width="3" stroke-linecap="round"/></svg>cf-r2-drop</a><nav aria-label="Main"><a href="/"${cur === "/" ? ' aria-current="page"' : ""}>Send</a><a href="/my.html"${cur === "my" ? ' aria-current="page"' : ""}>My links</a></nav></header>`;