Commit c4b6877a authored by Soheil Armin's avatar Soheil Armin
Browse files

getting multiple json objects in one chunk

parent a5dd6f7e
......@@ -11,15 +11,24 @@ ColumnLayout {
Label {
Layout.fillWidth: true
text: "Building..."
visible: createImage.running
}
TextArea {
id: logs
ScrollView {
id: view
Layout.fillWidth: true
Layout.fillHeight: true
readOnly: true
}
TextArea {
id: logs
readOnly: true
verticalAlignment: TextEdit.AlignTop
wrapMode: TextEdit.WordWrap
}
ScrollBar.vertical: ScrollBar { }
ScrollBar.horizontal: ScrollBar { }
}
BuildParams {
id: buildParams
......@@ -31,11 +40,15 @@ ColumnLayout {
method: 'POST'
requestBody: buildParams.dockerfileTar
running: false
//onFinished: console.log("BUILD FINISHED")
//onResponseBodyChanged: console.log(JSON.stringify(responseBody))
//onError: console.log(httpStatusCode)
onDataChunk: function (data) {
logs.text += data.toString()
if(data.stream) {
logs.text += data.stream
}
else
{
logs.text += JSON.stringify(data)
}
logs.cursorPosition = logs.length-1
}
}
......
......@@ -36,8 +36,8 @@ void QHttpRequest::start()
req.setRawHeader(iter.key().toLatin1(),iter.value().toString().toLatin1());
auto reply = net.sendCustomRequest(req,
m_method.toLatin1(),
m_requestBody);
m_method.toLatin1(),
m_requestBody);
connect(reply,&QNetworkReply::finished,this,&QHttpRequest::processReply);
connect(reply,&QNetworkReply::readyRead,this,&QHttpRequest::processChunk);
......@@ -68,6 +68,7 @@ void QHttpRequest::processReply()
if (reply->error() != QNetworkReply::NoError)
emit error();
setProperty("running",false);
emit finished();
}
......@@ -77,8 +78,24 @@ void QHttpRequest::processChunk()
if (reply == nullptr)
return;
if (!reply->header(QNetworkRequest::ContentLengthHeader).isValid()) {
emit dataChunk(reply->readAll());
auto data = reply->readAll();
auto jsEngine = qjsEngine(this);
if (reply->header(QNetworkRequest::ContentTypeHeader).toString() == QStringLiteral("application/json") &&
jsEngine ) {
const auto jsonParts = QString(data).split(QStringLiteral("}\r\n"));
for(auto &&part: jsonParts) {
auto parse = jsEngine->evaluate("JSON.parse");
auto result = parse.call({part + "}"});
if(!result.isError())
emit dataChunk(result);
}
} else if (jsEngine) {
emit dataChunk(jsEngine->toScriptValue<QByteArray>(data));
}
}
}
......
......@@ -63,7 +63,7 @@ signals:
void headersChanged(const QVariantMap &headers);
void parametersChanged(const QVariantMap &parameters);
void requestBodyChanged(const QByteArray &requestBody);
void dataChunk(const QByteArray &data);
void dataChunk(QJSValue data);
void responseBodyChanged(const QJSValue &responseBody);
void networkErrorChanged(int networkError);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment