fix(imaging): make avatar and badge images resilient to upstream outages
- Add persistent disk cache for rendered avatars/badges (storage/imaging) so repeats never touch the flaky local renderer and cached renders survive upstream downtime - Serve cache-first with stale-on-error; cut primary/fallback timeouts from 10s/6s to 4s/4s so failing images cannot stall pages - Avatar proxy now returns a graceful 200 silhouette instead of 502 when no renderer can produce a figure, so no broken-image glyphs appear - Badge endpoint becomes a caching proxy trying configured CDN, public Habbo CDN and local /swf copy in order, and drops the fragile IP rate limit that could blank badge streams - Route all site badge images (profile, me, badges, apply pages) through the cached proxy instead of hot-linking images.habbo.com
This commit is contained in:
1 parent
c3ff497050
commit
8a66db4ed7
12 files changed
+458
-58
No files matched your search
@@ -0,0 +1,57 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
avatarCacheDir,
|
||||
imagingCacheKey,
|
||||
readImagingCache,
|
||||
writeImagingCache,
|
||||
} from "./imager-cache";
|
||||
|
||||
const TEST_KEY = imagingCacheKey("test-render");
|
||||
const TEST_DIR = () => `${avatarCacheDir()}/unit`;
|
||||
|
||||
beforeEach(() => {
|
||||
// Isolate every run from the runtime cache and from prior runs.
|
||||
vi.stubEnv(
|
||||
"IMAGING_CACHE_ROOT",
|
||||
`${process.cwd()}/storage/imaging/test-unit-${process.pid}-${Date.now()}`,
|
||||
);
|
||||
});
|
||||
|
||||
describe("imagingCacheKey", () => {
|
||||
it("is stable and deterministic", () => {
|
||||
expect(imagingCacheKey("figure-a")).toBe(imagingCacheKey("figure-a"));
|
||||
expect(imagingCacheKey("figure-a")).not.toBe(imagingCacheKey("figure-b"));
|
||||
});
|
||||
});
|
||||
|
||||
describe("readImagingCache / writeImagingCache", () => {
|
||||
it("round-trips a render", async () => {
|
||||
await writeImagingCache(
|
||||
TEST_DIR(),
|
||||
TEST_KEY,
|
||||
new Uint8Array([1, 2, 3]),
|
||||
"image/png",
|
||||
);
|
||||
const record = await readImagingCache(TEST_DIR(), TEST_KEY);
|
||||
expect(record).not.toBeNull();
|
||||
expect(record?.contentType).toBe("image/png");
|
||||
expect([...(record?.body ?? [])]).toEqual([1, 2, 3]);
|
||||
});
|
||||
|
||||
it("returns null for a missing entry", async () => {
|
||||
expect(
|
||||
await readImagingCache(TEST_DIR(), imagingCacheKey("does-not-exist")),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("tolerates a torn write as a cache miss", async () => {
|
||||
const key = imagingCacheKey("torn-write");
|
||||
await writeImagingCache(
|
||||
TEST_DIR(),
|
||||
key,
|
||||
new Uint8Array([7, 7, 7]),
|
||||
"image/gif",
|
||||
);
|
||||
expect(await readImagingCache(TEST_DIR(), key)).not.toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user