fix: don't use shared_ptr for a background task T_T
Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
parent
c4316e81e6
commit
001bbef9ee
@ -75,8 +75,8 @@ class ModAPI {
|
|||||||
virtual void searchMods(CallerType* caller, SearchArgs&& args) const = 0;
|
virtual void searchMods(CallerType* caller, SearchArgs&& args) const = 0;
|
||||||
virtual void getModInfo(CallerType* caller, ModPlatform::IndexedPack& pack) = 0;
|
virtual void getModInfo(CallerType* caller, ModPlatform::IndexedPack& pack) = 0;
|
||||||
|
|
||||||
virtual auto getProject(QString addonId, QByteArray* response) const -> NetJob::Ptr = 0;
|
virtual auto getProject(QString addonId, QByteArray* response) const -> NetJob* = 0;
|
||||||
virtual auto getProjects(QStringList addonIds, QByteArray* response) const -> NetJob::Ptr = 0;
|
virtual auto getProjects(QStringList addonIds, QByteArray* response) const -> NetJob* = 0;
|
||||||
|
|
||||||
|
|
||||||
struct VersionSearchArgs {
|
struct VersionSearchArgs {
|
||||||
|
@ -124,7 +124,7 @@ auto FlameAPI::getLatestVersion(VersionSearchArgs&& args) -> ModPlatform::Indexe
|
|||||||
return ver;
|
return ver;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FlameAPI::getProjects(QStringList addonIds, QByteArray* response) const -> NetJob::Ptr
|
auto FlameAPI::getProjects(QStringList addonIds, QByteArray* response) const -> NetJob*
|
||||||
{
|
{
|
||||||
auto* netJob = new NetJob(QString("Flame::GetProjects"), APPLICATION->network());
|
auto* netJob = new NetJob(QString("Flame::GetProjects"), APPLICATION->network());
|
||||||
|
|
||||||
@ -141,7 +141,7 @@ auto FlameAPI::getProjects(QStringList addonIds, QByteArray* response) const ->
|
|||||||
|
|
||||||
netJob->addNetAction(Net::Upload::makeByteArray(QString("https://api.curseforge.com/v1/mods"), response, body_raw));
|
netJob->addNetAction(Net::Upload::makeByteArray(QString("https://api.curseforge.com/v1/mods"), response, body_raw));
|
||||||
|
|
||||||
QObject::connect(netJob, &NetJob::finished, [response] { delete response; });
|
QObject::connect(netJob, &NetJob::finished, [response, netJob] { delete response; netJob->deleteLater(); });
|
||||||
QObject::connect(netJob, &NetJob::failed, [body_raw] { qDebug() << body_raw; });
|
QObject::connect(netJob, &NetJob::failed, [body_raw] { qDebug() << body_raw; });
|
||||||
|
|
||||||
return netJob;
|
return netJob;
|
||||||
|
@ -10,7 +10,7 @@ class FlameAPI : public NetworkModAPI {
|
|||||||
|
|
||||||
auto getLatestVersion(VersionSearchArgs&& args) -> ModPlatform::IndexedVersion;
|
auto getLatestVersion(VersionSearchArgs&& args) -> ModPlatform::IndexedVersion;
|
||||||
|
|
||||||
auto getProjects(QStringList addonIds, QByteArray* response) const -> NetJob::Ptr override;
|
auto getProjects(QStringList addonIds, QByteArray* response) const -> NetJob* override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline auto getSortFieldInt(QString sortString) const -> int
|
inline auto getSortFieldInt(QString sortString) const -> int
|
||||||
|
@ -36,7 +36,7 @@ void NetworkModAPI::getModInfo(CallerType* caller, ModPlatform::IndexedPack& pac
|
|||||||
auto response = new QByteArray();
|
auto response = new QByteArray();
|
||||||
auto job = getProject(pack.addonId.toString(), response);
|
auto job = getProject(pack.addonId.toString(), response);
|
||||||
|
|
||||||
QObject::connect(job.get(), &NetJob::succeeded, caller, [caller, &pack, response] {
|
QObject::connect(job, &NetJob::succeeded, caller, [caller, &pack, response] {
|
||||||
QJsonParseError parse_error{};
|
QJsonParseError parse_error{};
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
|
QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
|
||||||
if (parse_error.error != QJsonParseError::NoError) {
|
if (parse_error.error != QJsonParseError::NoError) {
|
||||||
@ -80,7 +80,7 @@ void NetworkModAPI::getVersions(CallerType* caller, VersionSearchArgs&& args) co
|
|||||||
netJob->start();
|
netJob->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto NetworkModAPI::getProject(QString addonId, QByteArray* response) const -> NetJob::Ptr
|
auto NetworkModAPI::getProject(QString addonId, QByteArray* response) const -> NetJob*
|
||||||
{
|
{
|
||||||
auto netJob = new NetJob(QString("%1::GetProject").arg(addonId), APPLICATION->network());
|
auto netJob = new NetJob(QString("%1::GetProject").arg(addonId), APPLICATION->network());
|
||||||
auto searchUrl = getModInfoURL(addonId);
|
auto searchUrl = getModInfoURL(addonId);
|
||||||
|
@ -8,7 +8,7 @@ class NetworkModAPI : public ModAPI {
|
|||||||
void getModInfo(CallerType* caller, ModPlatform::IndexedPack& pack) override;
|
void getModInfo(CallerType* caller, ModPlatform::IndexedPack& pack) override;
|
||||||
void getVersions(CallerType* caller, VersionSearchArgs&& args) const override;
|
void getVersions(CallerType* caller, VersionSearchArgs&& args) const override;
|
||||||
|
|
||||||
auto getProject(QString addonId, QByteArray* response) const -> NetJob::Ptr override;
|
auto getProject(QString addonId, QByteArray* response) const -> NetJob* override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual auto getModSearchURL(SearchArgs& args) const -> QString = 0;
|
virtual auto getModSearchURL(SearchArgs& args) const -> QString = 0;
|
||||||
|
@ -95,14 +95,14 @@ auto ModrinthAPI::latestVersions(const QStringList& hashes,
|
|||||||
return netJob;
|
return netJob;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ModrinthAPI::getProjects(QStringList addonIds, QByteArray* response) const -> NetJob::Ptr
|
auto ModrinthAPI::getProjects(QStringList addonIds, QByteArray* response) const -> NetJob*
|
||||||
{
|
{
|
||||||
auto netJob = new NetJob(QString("Modrinth::GetProjects"), APPLICATION->network());
|
auto netJob = new NetJob(QString("Modrinth::GetProjects"), APPLICATION->network());
|
||||||
auto searchUrl = getMultipleModInfoURL(addonIds);
|
auto searchUrl = getMultipleModInfoURL(addonIds);
|
||||||
|
|
||||||
netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), response));
|
netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), response));
|
||||||
|
|
||||||
QObject::connect(netJob, &NetJob::finished, [response] { delete response; });
|
QObject::connect(netJob, &NetJob::finished, [response, netJob] { delete response; netJob->deleteLater(); });
|
||||||
|
|
||||||
return netJob;
|
return netJob;
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ class ModrinthAPI : public NetworkModAPI {
|
|||||||
ModLoaderTypes loaders,
|
ModLoaderTypes loaders,
|
||||||
QByteArray* response) -> NetJob::Ptr;
|
QByteArray* response) -> NetJob::Ptr;
|
||||||
|
|
||||||
auto getProjects(QStringList addonIds, QByteArray* response) const -> NetJob::Ptr override;
|
auto getProjects(QStringList addonIds, QByteArray* response) const -> NetJob* override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline auto getAuthorURL(const QString& name) const -> QString { return "https://modrinth.com/user/" + name; };
|
inline auto getAuthorURL(const QString& name) const -> QString { return "https://modrinth.com/user/" + name; };
|
||||||
|
Loading…
Reference in New Issue
Block a user