From 9a4e501be9c52f183b618499648b654cfe0efab8 Mon Sep 17 00:00:00 2001 From: dev Date: Wed, 29 Apr 2026 11:31:37 +0000 Subject: [PATCH] fix: jp2a requires --key=value arg format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit jp2a 1.3.x does not accept space-separated long option args. Added _argFormat: 'equals' to jp2a schema so buildArgs emits --key=value for value flags. Also mirrors chafa's width/height → --size=WxH combining in runJp2a. Co-Authored-By: Claude Sonnet 4.6 --- server/__tests__/converters.spec.js | 4 ++-- server/lib/converters.js | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/server/__tests__/converters.spec.js b/server/__tests__/converters.spec.js index 6d6578f..508a03a 100644 --- a/server/__tests__/converters.spec.js +++ b/server/__tests__/converters.spec.js @@ -97,12 +97,12 @@ describe('buildArgs', () => { it('accepts jp2a RGB weight values', () => { expect(buildArgs('jp2a', { red: '0.5', green: '0.3', blue: '0.2' })).toEqual([ - '--red', '0.5', '--green', '0.3', '--blue', '0.2', + '--red=0.5', '--green=0.3', '--blue=0.2', ]) }) it('accepts jp2a edge-threshold', () => { - expect(buildArgs('jp2a', { 'edge-threshold': '0.4' })).toEqual(['--edge-threshold', '0.4']) + expect(buildArgs('jp2a', { 'edge-threshold': '0.4' })).toEqual(['--edge-threshold=0.4']) }) it('accepts valid img2txt format values', () => { diff --git a/server/lib/converters.js b/server/lib/converters.js index f5b5654..eec64b2 100644 --- a/server/lib/converters.js +++ b/server/lib/converters.js @@ -22,6 +22,8 @@ export const SCHEMAS = { format: { type: 'value', valid: ['symbols', 'utf8'] }, }, jp2a: { + _argFormat: 'equals', + size: { type: 'value' }, width: { type: 'value' }, height: { type: 'value' }, chars: { type: 'value' }, @@ -60,6 +62,7 @@ export function buildArgs(tool, flags) { const schema = SCHEMAS[tool] if (!schema) throw new Error(`Unknown tool: ${tool}`) + const equals = schema._argFormat === 'equals' const args = [] for (const [key, value] of Object.entries(flags)) { const def = schema[key] @@ -69,6 +72,8 @@ export function buildArgs(tool, flags) { } if (def.type === 'bool') { if (value) args.push(`--${key}`) + } else if (equals) { + args.push(`--${key}=${String(value)}`) } else { args.push(`--${key}`, String(value)) } @@ -87,7 +92,12 @@ export async function runChafa(imagePath, flags) { } export async function runJp2a(imagePath, flags) { - const args = buildArgs('jp2a', flags) + const { width, height, ...rest } = flags + const processed = { ...rest } + if (width && height) processed.size = `${width}x${height}` + else if (width) processed.size = `${width}x` + else if (height) processed.size = `x${height}` + const args = buildArgs('jp2a', processed) return execa('jp2a', [...args, imagePath], { timeout: TIMEOUT }) }