Files
poli0981andClaude Opus 5.5 a3bfe04b40 Compact catalog packs, binary cache, themed scrollbars; bump to 4.2.0 (#103) [skip-discuss]
- Catalog packs: the build emits /data/pack/manifest-v1.json plus
  content-hashed deflate-raw packs (columns + dictionaries); the site and
  the apps read them (about 264 KB on a first visit instead of about 520 KB
  of JSON). Descriptions live in their own packs and load on demand (a game
  page: its chunk; a search: all of them).
- The IndexedDB cache is stored as compressed bytes by a small binary
  persister (replaces @tanstack/query-async-storage-persister); fflate is
  the lazy fallback where the browser has no Compression Streams.
- The readable /data/*.json goes only to apps 4.0-4.1.1 (Tauri Origin);
  everyone else gets a 410 with links to the repository
  (worker/legacy-data.ts, five positive run_worker_first entries).
- /img: exact width strings only, fallback originals and missing images
  kept at the edge for a day, failed background puts are logged.
- Themed scrollbars and a "Hide scrollbars" setting (Settings and the
  display menu); chart cards no longer block their list scrollbars.
- Policies (LEGAL_VERSION 2026-10-03): data reuse goes through the
  repository. Docs, changelog and version 4.2.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 19:19:42 +07:00

87 lines
3.5 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from 'vitest'
import { handleLegacyData, TAURI_ORIGINS } from './legacy-data'
const ORIGIN = 'https://freeitchgames.win'
const INDEX = JSON.stringify({ total_games: 1 })
function assets() {
return {
fetch: vi.fn(async (req: Request) => {
const { pathname } = new URL(req.url)
if (pathname !== '/data/index.json') return new Response(null, { status: 404 })
if (req.headers.get('if-none-match') === '"abc"') return new Response(null, { status: 304, headers: { etag: '"abc"' } })
return new Response(INDEX, {
headers: {
'content-type': 'application/json',
'cache-control': 'public, max-age=60, stale-while-revalidate=600',
'access-control-allow-origin': '*',
etag: '"abc"',
},
})
}),
}
}
function request(path: string, init: RequestInit & { origin?: string } = {}) {
const headers = new Headers(init.headers)
if (init.origin) headers.set('origin', init.origin)
return new Request(new URL(path, ORIGIN), { method: init.method, headers })
}
beforeEach(() => {
vi.restoreAllMocks()
vi.spyOn(console, 'info').mockImplementation(() => {})
})
describe('handleLegacyData', () => {
it('answers browsers and other sites with 410 and a link to the repository', async () => {
for (const origin of [undefined, 'https://example.com', 'null']) {
const a = assets()
const res = await handleLegacyData(request('/data/game_info_001.json', { origin }), a)
expect(res.status).toBe(410)
expect(res.headers.get('access-control-allow-origin')).toBe('*')
expect(res.headers.get('vary')).toContain('Origin')
expect(res.headers.get('cache-control')).toBe('no-store')
expect(await res.json()).toMatchObject({
error: 'gone',
data: 'https://github.com/poli0981/free-games-itchio-list/tree/main/data_game',
})
expect(a.fetch).not.toHaveBeenCalled()
}
})
it('passes the file through for the apps, with their headers and Vary: Origin', async () => {
for (const origin of TAURI_ORIGINS) {
const res = await handleLegacyData(request('/data/index.json', { origin }), assets())
expect(res.status).toBe(200)
expect(await res.text()).toBe(INDEX)
expect(res.headers.get('access-control-allow-origin')).toBe('*')
expect(res.headers.get('cache-control')).toBe('public, max-age=60, stale-while-revalidate=600')
expect(res.headers.get('vary')).toContain('Origin')
}
})
it('keeps revalidation working for the apps', async () => {
const res = await handleLegacyData(
request('/data/index.json', { origin: 'http://tauri.localhost', headers: { 'if-none-match': '"abc"' } }),
assets(),
)
expect(res.status).toBe(304)
})
it('answers a missing file with a JSON 404 the apps can read', async () => {
const res = await handleLegacyData(request('/data/game_info_999.json', { origin: 'tauri://localhost' }), assets())
expect(res.status).toBe(404)
expect(res.headers.get('access-control-allow-origin')).toBe('*')
expect(await res.json()).toEqual({ error: 'not_found' })
})
it('allows only GET and HEAD', async () => {
const post = await handleLegacyData(request('/data/index.json', { method: 'POST', origin: 'tauri://localhost' }), assets())
expect(post.status).toBe(405)
expect(post.headers.get('allow')).toBe('GET, HEAD')
const head = await handleLegacyData(request('/data/index.json', { method: 'HEAD' }), assets())
expect(head.status).toBe(410)
})
})