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,
|
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
|
let data: unknown
|
||||||
try {
|
try {
|
||||||
data = JSON.parse(stdout)
|
data = JSON.parse(stdout)
|
||||||
} catch {
|
} catch {
|
||||||
data = stdout || stderr || '(no output)'
|
const output = (stdout || '').trim()
|
||||||
|
const err = (stderr || '').trim()
|
||||||
|
data = { output: output || err || '(no output)' }
|
||||||
}
|
}
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
@@ -78,7 +80,7 @@ export async function POST(request: NextRequest) {
|
|||||||
|
|
||||||
let data: unknown
|
let data: unknown
|
||||||
if (error.stdout) {
|
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({
|
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[] {
|
function loadHistory(): QueryHistoryEntry[] {
|
||||||
if (typeof window === 'undefined') return []
|
if (typeof window === 'undefined') return []
|
||||||
try {
|
try {
|
||||||
@@ -505,10 +509,12 @@ export function QueryConsole() {
|
|||||||
{response.status} {response.statusText}
|
{response.status} {response.statusText}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<pre
|
<pre className={styles.responsePre}>
|
||||||
className={styles.responsePre}
|
{isPlainOutput(response.data)
|
||||||
dangerouslySetInnerHTML={{ __html: syntaxHighlight(JSON.stringify(response.data, null, 2)) }}
|
? (response.data as { output: string }).output
|
||||||
/>
|
: <span dangerouslySetInnerHTML={{ __html: syntaxHighlight(JSON.stringify(response.data, null, 2)) }} />
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user