gitflarePublicPartly agent-ready50
cf-r2-drop
Drag-and-drop file sharing on Cloudflare R2: multipart uploads, expiring share links, previews, download counts, lifecycle expiry.
- LicenseApache-2.0
- LanguageTypeScript
- Last landed
0e4544fOct 20, 2026
Serve the share page from the extensionless asset path
0e4544fexport const SECURITY_HEADERS: Record<string, string> = { "x-content-type-options": "nosniff", "referrer-policy": "no-referrer", "x-frame-options": "SAMEORIGIN", "permissions-policy": "camera=(), microphone=(), geolocation=()", "content-security-policy": "default-src 'self'; img-src 'self' data: blob:; style-src 'self' 'unsafe-inline'; frame-ancestors 'self'; object-src 'self'",};export function withSecurity(res: Response): Response { const h = new Headers(res.headers); for (const [k, v] of Object.entries(SECURITY_HEADERS)) if (!h.has(k)) h.set(k, v); return new Response(res.body, { status: res.status, statusText: res.statusText, headers: h, webSocket: (res as any).webSocket });}export function errorResponse(status: number, code: string, message: string): Response { return Response.json({ error: { code, message } }, { status });}/** Strip path separators, control chars and quotes; cap length. */export function safeFilename(name: string | null | undefined): string { const base = (name ?? "").split(/[\\/]/).pop() ?? ""; const clean = base.replace(/[\x00-\x1f\x7f"\\;]/g, "_").replace(/^\.+/, "").trim().slice(0, 200); return clean || "file";}export function contentDisposition(kind: "inline" | "attachment", name: string): string { const ascii = name.replace(/[^\x20-\x7e]/g, "_"); return `${kind}; filename="${ascii}"; filename*=UTF-8''${encodeURIComponent(name)}`;}export function log(event: string, data: Record<string, unknown> = {}): void { console.log(JSON.stringify({ event, ts: new Date().toISOString(), ...data }));}