add a warning about the log being too large
Signed-off-by: maskers <97827489+mskrss@users.noreply.github.com> (cherry picked from commit cf914526bf5330600f3cadb9f4baddb5144af21f)
This commit is contained in:
parent
db35f47105
commit
0cb5ac7a06
@ -49,29 +49,6 @@
|
|||||||
|
|
||||||
#include "net/Logging.h"
|
#include "net/Logging.h"
|
||||||
|
|
||||||
constexpr int MaxMclogsLines = 25000;
|
|
||||||
constexpr int InitialMclogsLines = 10000;
|
|
||||||
constexpr int FinalMclogsLines = 14900;
|
|
||||||
|
|
||||||
QString truncateLogForMclogs(const QString& logContent)
|
|
||||||
{
|
|
||||||
QStringList lines = logContent.split("\n");
|
|
||||||
if (lines.size() > MaxMclogsLines) {
|
|
||||||
QString truncatedLog = lines.mid(0, InitialMclogsLines).join("\n");
|
|
||||||
truncatedLog +=
|
|
||||||
"\n\n\n\n\n\n\n\n\n\n"
|
|
||||||
"------------------------------------------------------------\n"
|
|
||||||
"--------------------- Log truncated by ---------------------\n"
|
|
||||||
"---------------------- Prism Launcher ----------------------\n"
|
|
||||||
"----- Middle portion omitted to fit mclo.gs size limits ----\n"
|
|
||||||
"------------------------------------------------------------\n"
|
|
||||||
"\n\n\n\n\n\n\n\n\n\n";
|
|
||||||
truncatedLog += lines.mid(lines.size() - FinalMclogsLines, FinalMclogsLines).join("\n");
|
|
||||||
return truncatedLog;
|
|
||||||
}
|
|
||||||
return logContent;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::array<PasteUpload::PasteTypeInfo, 4> PasteUpload::PasteTypes = { { { "0x0.st", "https://0x0.st", "" },
|
std::array<PasteUpload::PasteTypeInfo, 4> PasteUpload::PasteTypes = { { { "0x0.st", "https://0x0.st", "" },
|
||||||
{ "hastebin", "https://hst.sh", "/documents" },
|
{ "hastebin", "https://hst.sh", "/documents" },
|
||||||
{ "paste.gg", "https://paste.gg", "/api/v1/pastes" },
|
{ "paste.gg", "https://paste.gg", "/api/v1/pastes" },
|
||||||
@ -121,7 +98,6 @@ void PasteUpload::executeTask()
|
|||||||
}
|
}
|
||||||
case Mclogs: {
|
case Mclogs: {
|
||||||
QUrlQuery postData;
|
QUrlQuery postData;
|
||||||
m_text = truncateLogForMclogs(m_text).toUtf8();
|
|
||||||
postData.addQueryItem("content", m_text);
|
postData.addQueryItem("content", m_text);
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||||
rep = APPLICATION->network()->post(request, postData.toString().toUtf8());
|
rep = APPLICATION->network()->post(request, postData.toString().toUtf8());
|
||||||
|
@ -51,11 +51,35 @@
|
|||||||
#include <settings/SettingsObject.h>
|
#include <settings/SettingsObject.h>
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
|
|
||||||
|
constexpr int MaxMclogsLines = 25000;
|
||||||
|
constexpr int InitialMclogsLines = 10000;
|
||||||
|
constexpr int FinalMclogsLines = 14900;
|
||||||
|
|
||||||
|
QString truncateLogForMclogs(const QString& logContent)
|
||||||
|
{
|
||||||
|
QStringList lines = logContent.split("\n");
|
||||||
|
if (lines.size() > MaxMclogsLines) {
|
||||||
|
QString truncatedLog = lines.mid(0, InitialMclogsLines).join("\n");
|
||||||
|
truncatedLog +=
|
||||||
|
"\n\n\n\n\n\n\n\n\n\n"
|
||||||
|
"------------------------------------------------------------\n"
|
||||||
|
"--------------------- Log truncated by ---------------------\n"
|
||||||
|
"---------------------- Prism Launcher ----------------------\n"
|
||||||
|
"----- Middle portion omitted to fit mclo.gs size limits ----\n"
|
||||||
|
"------------------------------------------------------------\n"
|
||||||
|
"\n\n\n\n\n\n\n\n\n\n";
|
||||||
|
truncatedLog += lines.mid(lines.size() - FinalMclogsLines, FinalMclogsLines).join("\n");
|
||||||
|
return truncatedLog;
|
||||||
|
}
|
||||||
|
return logContent;
|
||||||
|
}
|
||||||
|
|
||||||
std::optional<QString> GuiUtil::uploadPaste(const QString& name, const QString& text, QWidget* parentWidget)
|
std::optional<QString> GuiUtil::uploadPaste(const QString& name, const QString& text, QWidget* parentWidget)
|
||||||
{
|
{
|
||||||
ProgressDialog dialog(parentWidget);
|
ProgressDialog dialog(parentWidget);
|
||||||
auto pasteTypeSetting = static_cast<PasteUpload::PasteType>(APPLICATION->settings()->get("PastebinType").toInt());
|
auto pasteTypeSetting = static_cast<PasteUpload::PasteType>(APPLICATION->settings()->get("PastebinType").toInt());
|
||||||
auto pasteCustomAPIBaseSetting = APPLICATION->settings()->get("PastebinCustomAPIBase").toString();
|
auto pasteCustomAPIBaseSetting = APPLICATION->settings()->get("PastebinCustomAPIBase").toString();
|
||||||
|
bool shouldTruncate = false;
|
||||||
|
|
||||||
{
|
{
|
||||||
QUrl baseUrl;
|
QUrl baseUrl;
|
||||||
@ -75,10 +99,35 @@ std::optional<QString> GuiUtil::uploadPaste(const QString& name, const QString&
|
|||||||
|
|
||||||
if (response != QMessageBox::Yes)
|
if (response != QMessageBox::Yes)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
if (baseUrl.toString() == "https://api.mclo.gs" && text.count("\n") > MaxMclogsLines) {
|
||||||
|
auto truncateResponse =
|
||||||
|
CustomMessageBox::selectable(parentWidget, QObject::tr("Confirm Truncate"),
|
||||||
|
QObject::tr("The log exceeds mclo.gs' limit: %1 lines (max %2).\n"
|
||||||
|
"Prism can keep the first %3 and last %4 lines, trimming the middle.\n\n"
|
||||||
|
"If you choose 'No', mclo.gs will only keep the first %2 lines, cutting off "
|
||||||
|
"potentially useful info like crashes at the end.\n\n"
|
||||||
|
"Proceed with Prism's truncation?")
|
||||||
|
.arg(text.count("\n"))
|
||||||
|
.arg(MaxMclogsLines)
|
||||||
|
.arg(InitialMclogsLines)
|
||||||
|
.arg(FinalMclogsLines),
|
||||||
|
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
|
||||||
|
->exec();
|
||||||
|
|
||||||
|
if (truncateResponse == QMessageBox::Yes)
|
||||||
|
shouldTruncate = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<PasteUpload> paste(new PasteUpload(parentWidget, text, pasteCustomAPIBaseSetting, pasteTypeSetting));
|
QString textToUpload;
|
||||||
|
if (shouldTruncate)
|
||||||
|
textToUpload = truncateLogForMclogs(text);
|
||||||
|
else
|
||||||
|
textToUpload = text;
|
||||||
|
|
||||||
|
std::unique_ptr<PasteUpload> paste(new PasteUpload(parentWidget, textToUpload, pasteCustomAPIBaseSetting, pasteTypeSetting));
|
||||||
|
|
||||||
dialog.execWithTask(paste.get());
|
dialog.execWithTask(paste.get());
|
||||||
if (!paste->wasSuccessful()) {
|
if (!paste->wasSuccessful()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user