feat: initialize wheelofnames API

This commit is contained in:
tiennm99 committed 2026-07-06 22:20:48 +07:00
1 parent 194caf17eb
commit 3f5ed700bb
41 files changed
+5031

No files matched your search

+55
View File
@@ -0,0 +1,55 @@
import {mkdir, writeFile} from 'node:fs/promises';
import path from 'node:path';
import {renderWheelGif} from '../src/render/render-gif.js';
const smoke = process.argv.includes('--smoke');
const fixturesDir = path.join(process.cwd(), 'fixtures');
/** @type {{name: string, request: import('../src/schemas/wheel-request.js').WheelRenderRequest}[]} */
const fixtures = [
{
name: 'smoke',
request: {
options: ['alpha', 'beta', 'gamma', 'delta'],
winnerIndex: 1,
durationMs: smoke ? 3000 : 6500,
holdMs: smoke ? 500 : 1200,
fps: 12,
size: smoke ? 384 : 512,
theme: 'classic',
},
},
{
name: 'vietnamese',
request: {
options: ['khong dau', 'co dau', 'banh mi', 'ca phe sua da', 'pho bo', 'goi cuon', 'ha noi', 'sai gon'],
winnerIndex: 3,
durationMs: 6500,
holdMs: 1200,
fps: 15,
size: 512,
theme: 'festival',
},
},
{
name: 'sixteen-options',
request: {
options: Array.from({length: 16}, (_, index) => `option ${index + 1}`),
winnerIndex: 9,
durationMs: 6500,
holdMs: 1200,
fps: 15,
size: 512,
theme: 'classic',
},
},
];
await mkdir(fixturesDir, {recursive: true});
for (const fixture of smoke ? fixtures.slice(0, 1) : fixtures) {
const result = await renderWheelGif(fixture.request, {timeoutInMilliseconds: 30000});
const output = path.join(fixturesDir, `${fixture.name}.gif`);
await writeFile(output, result.buffer);
console.log(`${fixture.name}: ${output} ${result.byteLength} bytes ${result.durationMs}ms`);
}