Skip to content

Commit

Permalink
Fix server, apply what was done in #3946
Browse files Browse the repository at this point in the history
  • Loading branch information
arturi committed Aug 21, 2022
1 parent 7f040b0 commit a1b9641
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions examples/transloadit/server.cjs
Expand Up @@ -25,8 +25,8 @@ function onrequest (req, res) {

function onbody (body) {
const fields = qs.parse(body)
console.log({ fields })
const assemblies = JSON.parse(fields.uppyResult)
const result = JSON.parse(fields.uppyResult)
const assemblies = result[0].transloadit

res.setHeader('content-type', 'text/html')
res.write(Header())
Expand Down Expand Up @@ -77,9 +77,33 @@ function FormFields (fields) {

function Field ([name, value]) {
if (name === 'transloadit') return ''
let isValueJSON = false
if (value.startsWith('{') || value.startsWith('[')) {
try {
value = JSON.stringify(
JSON.parse(value),
null,
2
)
isValueJSON = true
} catch {
// Nothing
}
}

const prettyValue = isValueJSON ? `
<details open>
<code>
<pre style="max-width: 100%; max-height: 400px; white-space: pre-wrap; overflow: auto;">${e(value)}</pre>
</code>
</details>
` : e(value)

return `
<dt>${e(name)}</dt>
<dd>${e(value)}</dd>
<dd>
${prettyValue}
</dd>
`
}
}
Expand Down

0 comments on commit a1b9641

Please sign in to comment.