Permalink
Browse files

SCRATCH actually serialize the uploaded text properly to json string

  • Loading branch information...
peterix committed Oct 9, 2017
1 parent eba8e61 commit 93b9415d91a71a65c68fa5541e998a513c79ef0f
Showing with 24 additions and 8 deletions.
  1. +24 −8 api/logic/net/PasteUpload.cpp
@@ -2,19 +2,30 @@
#include "Env.h"
#include <QDebug>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonDocument>
#include <QFile>
PasteUpload::PasteUpload(QWidget *window, QString text, QString key) : m_window(window)
{
m_key = key;
QByteArray temp;
temp = text.toUtf8();
temp.replace("\n", "\\n");
m_textSize = temp.size();
m_text = "{\"description\": \"MultiMC Log Upload\", \"sections\": [{\"contents\": \"" + temp + "\"}]}";
QByteArray jsonDocument(m_text);
m_json = jsonDocument;
qDebug() << m_json;
QJsonObject topLevelObj;
QJsonObject sectionObject;
sectionObject.insert("contents", text);
QJsonArray sectionArray;
sectionArray.append(sectionObject);
topLevelObj.insert("description", "MultiMC Log Upload");
topLevelObj.insert("sections", sectionArray);
QJsonDocument docOut;
docOut.setObject(topLevelObj);
m_json = docOut.toJson();
m_textSize = m_json.size();
qDebug() << "SENT" << m_json;
QFile out("/tmp/SENT.json");
out.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate);
out.write(m_json);
out.close();
}
PasteUpload::~PasteUpload()
@@ -57,10 +68,15 @@ void PasteUpload::downloadError(QNetworkReply::NetworkError error)
void PasteUpload::downloadFinished()
{
QByteArray data = m_reply->readAll();
qDebug() << "RECEIVED" << data;
QFile out("/tmp/RECEIVED.json");
out.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate);
out.write(data);
out.close();
// if the download succeeded
if (m_reply->error() == QNetworkReply::NetworkError::NoError)
{
QByteArray data = m_reply->readAll();
m_reply.reset();
QJsonParseError jsonError;
QJsonDocument doc = QJsonDocument::fromJson(data, &jsonError);

0 comments on commit 93b9415

Please sign in to comment.