Hotfix for batched-up chunked responses

This commit is contained in:
cmdr2 2022-09-24 22:29:31 +05:30
parent 37cf9eb587
commit 688659b815
2 changed files with 15 additions and 1 deletions

View File

@ -210,7 +210,7 @@
</div>
</body>
<script src="media/main.js?v=3"></script>
<script src="media/main.js?v=4"></script>
<script>
async function init() {
await loadModifiers()

View File

@ -366,6 +366,20 @@ async function doMakeImage(reqBody, batchCount) {
res = undefined
progressBar.style.display = 'none'
} else {
if (finalJSON !== undefined && finalJSON.indexOf('}{') !== -1) {
// hack for a middleman buffering all the streaming updates, and unleashing them
// on the poor browser in one shot.
// this results in having to parse JSON like {"step": 1}{"step": 2}...{"status": "succeeded"..}
// which is obviously invalid.
// So we need to just extract the last {} section, starting from "status" to the end of the response
let lastChunkIdx = finalJSON.lastIndexOf('}{')
if (lastChunkIdx !== -1) {
let remaining = finalJSON.substring(lastChunkIdx)
finalJSON = remaining.substring(1)
}
}
res = JSON.parse(finalJSON)
progressBar.style.display = 'none'