diff --git a/frontend/src/lib/gif.test.ts b/frontend/src/lib/gif.test.ts index 724c9e0c..6f65f9f2 100644 --- a/frontend/src/lib/gif.test.ts +++ b/frontend/src/lib/gif.test.ts @@ -1,5 +1,11 @@ import { describe, expect, it } from "vitest"; -import { estimateGif, GIF_MAX_BYTES, GIF_PREVIEW_MAX_BYTES, gifVerdict } from "./gif"; +import { + estimateGif, + gifEstimateText, + GIF_MAX_BYTES, + GIF_PREVIEW_MAX_BYTES, + gifVerdict, +} from "./gif"; const MB = 1024 * 1024; @@ -34,9 +40,17 @@ describe("gifVerdict", () => { }); it("warns past the server's cap, then past the link preview's", () => { - expect(gifVerdict(10, { hi: GIF_MAX_BYTES + 1 })).toBe("may_fail"); + expect(gifVerdict(10, { hi: GIF_MAX_BYTES + 0.6 * MB })).toBe("may_fail"); expect(gifVerdict(10, { hi: GIF_MAX_BYTES })).toBe("no_preview"); - expect(gifVerdict(10, { hi: GIF_PREVIEW_MAX_BYTES + 1 })).toBe("no_preview"); + expect(gifVerdict(10, { hi: GIF_PREVIEW_MAX_BYTES + 0.6 * MB })).toBe("no_preview"); expect(gifVerdict(10, { hi: GIF_PREVIEW_MAX_BYTES })).toBe("ok"); }); + + it("judges the size the reader is shown: a high end shown as 30 MB is not past 30 MB", () => { + // 30 s at 480 lands a hair over 30 MiB, and reads "about 12–30 MB". + const hi = GIF_MAX_BYTES + 0.4 * MB; + expect(gifEstimateText({ lo: 12 * MB, hi }, "en").hi).toBe("30"); + expect(gifVerdict(30, { hi })).toBe("no_preview"); + expect(gifVerdict(10, { hi: GIF_PREVIEW_MAX_BYTES + 0.4 * MB })).toBe("ok"); + }); }); diff --git a/frontend/src/lib/gif.ts b/frontend/src/lib/gif.ts index e7a25d4a..2c55bafe 100644 --- a/frontend/src/lib/gif.ts +++ b/frontend/src/lib/gif.ts @@ -54,7 +54,10 @@ export type GifVerdict = "too_long" | "may_fail" | "no_preview" | "ok"; export function gifVerdict(seconds: number, est: { hi: number }): GifVerdict { if (seconds > GIF_MAX_S + 0.0005) return "too_long"; - if (est.hi > GIF_MAX_BYTES) return "may_fail"; - if (est.hi > GIF_PREVIEW_MAX_BYTES) return "no_preview"; + // Judged on the high end as shown (whole megabytes): "about 12–30 MB" beside "it may pass 30 MB" + // would contradict itself, and the estimate is no finer than that anyway. + const hi = Math.round(est.hi / MB) * MB; + if (hi > GIF_MAX_BYTES) return "may_fail"; + if (hi > GIF_PREVIEW_MAX_BYTES) return "no_preview"; return "ok"; }