truncate logs for mclo.gs upload to fit 25k line limit

Signed-off-by: maskers <97827489+mskrss@users.noreply.github.com>
(cherry picked from commit 014fc142915ec4a0f96b3082f76d4d32ce7596aa)
This commit is contained in:
maskers 2024-08-20 21:53:05 +03:00 committed by github-actions[bot]
parent b2c75dde95
commit 15887c2d92

View File

@ -49,6 +49,27 @@
#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" },
@ -98,6 +119,7 @@ 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());