mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-24 13:54:57 +00:00
fix(dbal): render CLI plain text output properly instead of escaped JSON
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -57,12 +57,14 @@ export async function POST(request: NextRequest) {
|
||||
env: env as NodeJS.ProcessEnv,
|
||||
})
|
||||
|
||||
// Try to parse stdout as JSON
|
||||
// Try to parse stdout as JSON, otherwise return as structured text
|
||||
let data: unknown
|
||||
try {
|
||||
data = JSON.parse(stdout)
|
||||
} catch {
|
||||
data = stdout || stderr || '(no output)'
|
||||
const output = (stdout || '').trim()
|
||||
const err = (stderr || '').trim()
|
||||
data = { output: output || err || '(no output)' }
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
@@ -78,7 +80,7 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
let data: unknown
|
||||
if (error.stdout) {
|
||||
try { data = JSON.parse(error.stdout) } catch { data = error.stdout }
|
||||
try { data = JSON.parse(error.stdout) } catch { data = { output: error.stdout.trim() } }
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
|
||||
@@ -135,6 +135,10 @@ function syntaxHighlight(json: string): string {
|
||||
)
|
||||
}
|
||||
|
||||
function isPlainOutput(data: unknown): boolean {
|
||||
return typeof data === 'object' && data !== null && 'output' in data && typeof (data as { output: unknown }).output === 'string'
|
||||
}
|
||||
|
||||
function loadHistory(): QueryHistoryEntry[] {
|
||||
if (typeof window === 'undefined') return []
|
||||
try {
|
||||
@@ -505,10 +509,12 @@ export function QueryConsole() {
|
||||
{response.status} {response.statusText}
|
||||
</span>
|
||||
</div>
|
||||
<pre
|
||||
className={styles.responsePre}
|
||||
dangerouslySetInnerHTML={{ __html: syntaxHighlight(JSON.stringify(response.data, null, 2)) }}
|
||||
/>
|
||||
<pre className={styles.responsePre}>
|
||||
{isPlainOutput(response.data)
|
||||
? (response.data as { output: string }).output
|
||||
: <span dangerouslySetInnerHTML={{ __html: syntaxHighlight(JSON.stringify(response.data, null, 2)) }} />
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user