mirror of
https://github.com/tiennm99/tiennm99bot.git
synced 2026-10-14 00:17:01 +00:00
feat: initialize wheelofnames API
This commit is contained in:
1 parent
194caf17eb
commit
3f5ed700bb
41 files changed
+5031
No files matched your search
@@ -0,0 +1,50 @@
|
||||
import {buildServer} from '../src/server.js';
|
||||
|
||||
const config = {
|
||||
apiToken: 'smoke-token',
|
||||
host: '127.0.0.1',
|
||||
maxConcurrentRenders: 1,
|
||||
maxOptionChars: 40,
|
||||
maxOptions: 32,
|
||||
port: 0,
|
||||
requiresApiToken: true,
|
||||
renderTimeoutMs: 30000,
|
||||
};
|
||||
|
||||
const app = await buildServer({config, warmRemotionBundle: true});
|
||||
|
||||
try {
|
||||
const response = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/api/gif',
|
||||
headers: {
|
||||
authorization: 'Bearer smoke-token',
|
||||
},
|
||||
payload: {
|
||||
durationMs: 3000,
|
||||
fps: 12,
|
||||
holdMs: 500,
|
||||
options: ['alice', 'bob', 'carol', 'dave'],
|
||||
size: 384,
|
||||
theme: 'classic',
|
||||
winnerIndex: 2,
|
||||
},
|
||||
});
|
||||
|
||||
if (response.statusCode !== 200) {
|
||||
throw new Error(`Expected 200, got ${response.statusCode}: ${response.body}`);
|
||||
}
|
||||
|
||||
const magic = response.rawPayload.subarray(0, 6).toString();
|
||||
if (magic !== 'GIF89a') {
|
||||
throw new Error(`Expected GIF89a header, got ${magic}`);
|
||||
}
|
||||
|
||||
if (response.headers['x-wheel-winner-index'] !== '2') {
|
||||
throw new Error(`Expected winner index 2, got ${response.headers['x-wheel-winner-index']}`);
|
||||
}
|
||||
|
||||
console.log(`api-smoke: ${response.rawPayload.byteLength} bytes`);
|
||||
} finally {
|
||||
await app.close();
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import {ensureBrowser} from '@remotion/renderer';
|
||||
|
||||
const status = await ensureBrowser({logLevel: 'warn'});
|
||||
|
||||
if (status.type === 'no-browser' || status.type === 'version-mismatch') {
|
||||
throw new Error(`Unable to prepare Remotion browser, status: ${status.type}`);
|
||||
}
|
||||
|
||||
console.log(`browser: ${status.type}`);
|
||||
@@ -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`);
|
||||
}
|
||||
Reference in new issue
Block a user