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
0e4544fimport { describe, it, expect } from "vitest";import { encodeQR, rsEncode } from "../src/lib/qr";import { expiredKeys } from "../src/lib/cleanup";import { safeFilename, errorResponse } from "../src/lib/http"; describe("qr", () => { it("rs ecc matches known vector", () => { expect(rsEncode([32, 91, 11, 120, 209, 114, 220, 77, 67, 64, 236, 17, 236, 17, 236, 17], 10)) .toEqual([196, 35, 39, 119, 235, 215, 231, 226, 93, 23]); }); it("sizes by version", () => { expect(encodeQR("hi").length).toBe(21); expect(encodeQR("x".repeat(20)).length).toBe(25); expect(encodeQR("x".repeat(150)).length).toBe(49); expect(() => encodeQR("x".repeat(300))).toThrow(); }); it("has finder patterns and dark module", () => { const m = encodeQR("https://x.test/s/abc"); const n = m.length; for (const [r, c] of [[0, 0], [0, n - 7], [n - 7, 0]]) { expect(m[r][c]).toBe(true); expect(m[r + 3][c + 3]).toBe(true); expect(m[r + 1][c + 1]).toBe(false); } expect(m[n - 8][8]).toBe(true); });});describe("cleanup", () => { it("selects only expired", () => { expect(expiredKeys([ { key: "a", customMetadata: { expiresAt: "10" } }, { key: "b", customMetadata: { expiresAt: "999" } }, { key: "c" }, ], 100)).toEqual(["a"]); });});describe("http", () => { it("safe filenames", () => { expect(safeFilename("../../etc/pa\"ss\r\nwd")).toBe("pa_ss__wd"); expect(safeFilename("")).toBe("file"); }); it("error shape", async () => { expect(await errorResponse(404, "x", "y").json()).toEqual({ error: { code: "x", message: "y" } }); });});