mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2026-07-04 20:36:58 +03:00
Use an owning QByteArray in ByteArraySink
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
(cherry picked from commit 316121ba8f)
This commit is contained in:
parent
d4e5c0f95b
commit
4e4990bf8d
66 changed files with 367 additions and 365 deletions
|
|
@ -15,7 +15,7 @@
|
|||
#include "net/ApiUpload.h"
|
||||
#include "net/NetJob.h"
|
||||
|
||||
Task::Ptr FlameAPI::matchFingerprints(const QList<uint>& fingerprints, QByteArray* response)
|
||||
std::pair<Task::Ptr, QByteArray*> FlameAPI::matchFingerprints(const QList<uint>& fingerprints)
|
||||
{
|
||||
auto netJob = makeShared<NetJob>(QString("Flame::MatchFingerprints"), APPLICATION->network());
|
||||
|
||||
|
|
@ -29,10 +29,10 @@ Task::Ptr FlameAPI::matchFingerprints(const QList<uint>& fingerprints, QByteArra
|
|||
|
||||
QJsonDocument body(body_obj);
|
||||
auto body_raw = body.toJson();
|
||||
auto [action, response] = Net::ApiUpload::makeByteArray(QString(BuildConfig.FLAME_BASE_URL + "/fingerprints"), body_raw);
|
||||
netJob->addNetAction(action);
|
||||
|
||||
netJob->addNetAction(Net::ApiUpload::makeByteArray(QString(BuildConfig.FLAME_BASE_URL + "/fingerprints"), response, body_raw));
|
||||
|
||||
return netJob;
|
||||
return { netJob, response };
|
||||
}
|
||||
|
||||
QString FlameAPI::getModFileChangelog(int modId, int fileId)
|
||||
|
|
@ -41,11 +41,10 @@ QString FlameAPI::getModFileChangelog(int modId, int fileId)
|
|||
QString changelog;
|
||||
|
||||
auto netJob = makeShared<NetJob>(QString("Flame::FileChangelog"), APPLICATION->network());
|
||||
auto response = std::make_shared<QByteArray>();
|
||||
netJob->addNetAction(Net::ApiDownload::makeByteArray(
|
||||
auto [action, response] = Net::ApiDownload::makeByteArray(
|
||||
QString(BuildConfig.FLAME_BASE_URL + "/mods/%1/files/%2/changelog")
|
||||
.arg(QString::fromStdString(std::to_string(modId)), QString::fromStdString(std::to_string(fileId))),
|
||||
response.get()));
|
||||
.arg(QString::fromStdString(std::to_string(modId)), QString::fromStdString(std::to_string(fileId))));
|
||||
netJob->addNetAction(action);
|
||||
|
||||
QObject::connect(netJob.get(), &NetJob::succeeded, [&netJob, response, &changelog] {
|
||||
QJsonParseError parse_error{};
|
||||
|
|
@ -76,9 +75,9 @@ QString FlameAPI::getModDescription(int modId)
|
|||
QString description;
|
||||
|
||||
auto netJob = makeShared<NetJob>(QString("Flame::ModDescription"), APPLICATION->network());
|
||||
auto response = std::make_shared<QByteArray>();
|
||||
netJob->addNetAction(Net::ApiDownload::makeByteArray(
|
||||
QString(BuildConfig.FLAME_BASE_URL + "/mods/%1/description").arg(QString::number(modId)), response.get()));
|
||||
auto [action, response] =
|
||||
Net::ApiDownload::makeByteArray(QString(BuildConfig.FLAME_BASE_URL + "/mods/%1/description").arg(QString::number(modId)));
|
||||
netJob->addNetAction(action);
|
||||
|
||||
QObject::connect(netJob.get(), &NetJob::succeeded, [&netJob, response, &description] {
|
||||
QJsonParseError parse_error{};
|
||||
|
|
@ -103,7 +102,7 @@ QString FlameAPI::getModDescription(int modId)
|
|||
return description;
|
||||
}
|
||||
|
||||
Task::Ptr FlameAPI::getProjects(QStringList addonIds, QByteArray* response) const
|
||||
std::pair<Task::Ptr, QByteArray*> FlameAPI::getProjects(QStringList addonIds) const
|
||||
{
|
||||
auto netJob = makeShared<NetJob>(QString("Flame::GetProjects"), APPLICATION->network());
|
||||
|
||||
|
|
@ -117,15 +116,15 @@ Task::Ptr FlameAPI::getProjects(QStringList addonIds, QByteArray* response) cons
|
|||
|
||||
QJsonDocument body(body_obj);
|
||||
auto body_raw = body.toJson();
|
||||
|
||||
netJob->addNetAction(Net::ApiUpload::makeByteArray(QString(BuildConfig.FLAME_BASE_URL + "/mods"), response, body_raw));
|
||||
auto [action, response] = Net::ApiUpload::makeByteArray(QString(BuildConfig.FLAME_BASE_URL + "/mods"), body_raw);
|
||||
netJob->addNetAction(action);
|
||||
|
||||
QObject::connect(netJob.get(), &NetJob::failed, [body_raw] { qDebug() << body_raw; });
|
||||
|
||||
return netJob;
|
||||
return { netJob, response };
|
||||
}
|
||||
|
||||
Task::Ptr FlameAPI::getFiles(const QStringList& fileIds, QByteArray* response) const
|
||||
std::pair<Task::Ptr, QByteArray*> FlameAPI::getFiles(const QStringList& fileIds) const
|
||||
{
|
||||
auto netJob = makeShared<NetJob>(QString("Flame::GetFiles"), APPLICATION->network());
|
||||
|
||||
|
|
@ -140,22 +139,24 @@ Task::Ptr FlameAPI::getFiles(const QStringList& fileIds, QByteArray* response) c
|
|||
QJsonDocument body(body_obj);
|
||||
auto body_raw = body.toJson();
|
||||
|
||||
netJob->addNetAction(Net::ApiUpload::makeByteArray(QString(BuildConfig.FLAME_BASE_URL + "/mods/files"), response, body_raw));
|
||||
auto [action, response] = Net::ApiUpload::makeByteArray(QString(BuildConfig.FLAME_BASE_URL + "/mods/files"), body_raw);
|
||||
netJob->addNetAction(action);
|
||||
|
||||
QObject::connect(netJob.get(), &NetJob::failed, [body_raw] { qDebug() << body_raw; });
|
||||
|
||||
return netJob;
|
||||
return { netJob, response };
|
||||
}
|
||||
|
||||
Task::Ptr FlameAPI::getFile(const QString& addonId, const QString& fileId, QByteArray* response) const
|
||||
std::pair<Task::Ptr, QByteArray*> FlameAPI::getFile(const QString& addonId, const QString& fileId) const
|
||||
{
|
||||
auto netJob = makeShared<NetJob>(QString("Flame::GetFile"), APPLICATION->network());
|
||||
netJob->addNetAction(
|
||||
Net::ApiDownload::makeByteArray(QUrl(QString(BuildConfig.FLAME_BASE_URL + "/mods/%1/files/%2").arg(addonId, fileId)), response));
|
||||
auto [action, response] =
|
||||
Net::ApiDownload::makeByteArray(QUrl(QString(BuildConfig.FLAME_BASE_URL + "/mods/%1/files/%2").arg(addonId, fileId)));
|
||||
netJob->addNetAction(action);
|
||||
|
||||
QObject::connect(netJob.get(), &NetJob::failed, [addonId, fileId] { qDebug() << "Flame API file failure" << addonId << fileId; });
|
||||
|
||||
return netJob;
|
||||
return { netJob, response };
|
||||
}
|
||||
|
||||
QList<ResourceAPI::SortingMethod> FlameAPI::getSortingMethods() const
|
||||
|
|
@ -171,25 +172,26 @@ QList<ResourceAPI::SortingMethod> FlameAPI::getSortingMethods() const
|
|||
{ 8, "GameVersion", QObject::tr("Sort by Game Version") } };
|
||||
}
|
||||
|
||||
Task::Ptr FlameAPI::getCategories(QByteArray* response, ModPlatform::ResourceType type)
|
||||
std::pair<Task::Ptr, QByteArray*> FlameAPI::getCategories(ModPlatform::ResourceType type)
|
||||
{
|
||||
auto netJob = makeShared<NetJob>(QString("Flame::GetCategories"), APPLICATION->network());
|
||||
netJob->addNetAction(Net::ApiDownload::makeByteArray(
|
||||
QUrl(QString(BuildConfig.FLAME_BASE_URL + "/categories?gameId=432&classId=%1").arg(getClassId(type))), response));
|
||||
auto [action, response] = Net::ApiDownload::makeByteArray(
|
||||
QUrl(QString(BuildConfig.FLAME_BASE_URL + "/categories?gameId=432&classId=%1").arg(getClassId(type))));
|
||||
netJob->addNetAction(action);
|
||||
QObject::connect(netJob.get(), &Task::failed, [](QString msg) { qDebug() << "Flame failed to get categories:" << msg; });
|
||||
return netJob;
|
||||
return { netJob, response };
|
||||
}
|
||||
|
||||
Task::Ptr FlameAPI::getModCategories(QByteArray* response)
|
||||
std::pair<Task::Ptr, QByteArray*> FlameAPI::getModCategories()
|
||||
{
|
||||
return getCategories(response, ModPlatform::ResourceType::Mod);
|
||||
return getCategories(ModPlatform::ResourceType::Mod);
|
||||
}
|
||||
|
||||
QList<ModPlatform::Category> FlameAPI::loadModCategories(QByteArray* response)
|
||||
QList<ModPlatform::Category> FlameAPI::loadModCategories(const QByteArray& response)
|
||||
{
|
||||
QList<ModPlatform::Category> categories;
|
||||
QJsonParseError parse_error{};
|
||||
QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
|
||||
QJsonDocument doc = QJsonDocument::fromJson(response, &parse_error);
|
||||
if (parse_error.error != QJsonParseError::NoError) {
|
||||
qWarning() << "Error while parsing JSON response from categories at" << parse_error.offset
|
||||
<< "reason:" << parse_error.errorString();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue