fix(shared): accept local asset paths in trace schema

This commit is contained in:
2026-08-10 09:12:31 +08:00
parent dfe49bad0c
commit 82caa9bb9c
2 changed files with 16 additions and 5 deletions
+12 -4
View File
@@ -165,10 +165,18 @@ describe('traceRequestSchema', () => {
}); });
}); });
it('rejects an invalid url', () => { it('accepts a local game asset path (not just http(s))', () => {
expect(traceRequestSchema.safeParse({ url: 'not-a-url' }).success).toBe( // The proxy resolves relative paths against the games root, so a bare
false, // path is a valid trace source.
); expect(
traceRequestSchema.safeParse({ url: 'poker/parts/assets/cards.png' })
.success,
).toBe(true);
});
it('rejects a missing or blank url', () => {
expect(traceRequestSchema.safeParse({}).success).toBe(false);
expect(traceRequestSchema.safeParse({ url: '' }).success).toBe(false);
}); });
it('rejects an unknown mode or format', () => { it('rejects an unknown mode or format', () => {
+4 -1
View File
@@ -59,7 +59,10 @@ export const traceFormatSchema = z.enum(['svg', 'shape']);
/** Query params for `GET /trace`. */ /** Query params for `GET /trace`. */
export const traceRequestSchema = z.object({ export const traceRequestSchema = z.object({
url: z.string().url('url must be a valid URL'), // The url may be an http(s) URL or a local game asset path relative to the
// games root (e.g. `poker/parts/assets/cards.png`); the proxy resolves both
// via `resolveAsset`. Only a non-empty string is validated here.
url: z.string().min(1, 'url is required'),
mode: traceModeSchema.default('alpha'), mode: traceModeSchema.default('alpha'),
threshold: z.coerce.number().int().min(0).max(255).default(128), threshold: z.coerce.number().int().min(0).max(255).default(128),
format: traceFormatSchema.default('shape'), format: traceFormatSchema.default('shape'),