Update to Modrinth API V2

This commit is contained in:
timoreo 2022-01-31 17:18:11 +01:00
parent efc44c56a6
commit aa2c27bf69
No known key found for this signature in database
GPG Key ID: 121A72C3512BA288
3 changed files with 8 additions and 8 deletions

View File

@ -10,7 +10,7 @@
void Modrinth::loadIndexedPack(Modrinth::IndexedPack & pack, QJsonObject & obj)
{
pack.addonId = Json::requireString(obj, "mod_id");
pack.addonId = Json::requireString(obj, "project_id");
pack.name = Json::requireString(obj, "title");
pack.websiteUrl = Json::ensureString(obj, "page_url", "");
pack.description = Json::ensureString(obj, "description", "");
@ -20,7 +20,7 @@ void Modrinth::loadIndexedPack(Modrinth::IndexedPack & pack, QJsonObject & obj)
Modrinth::ModpackAuthor modAuthor;
modAuthor.name = Json::requireString(obj, "author");
modAuthor.url = Json::requireString(obj, "author_url");
modAuthor.url = "https://modrinth.com/user/"+modAuthor.name;
pack.author = modAuthor;
}
@ -33,7 +33,7 @@ void Modrinth::loadIndexedPackVersions(Modrinth::IndexedPack & pack, QJsonArray
for(auto versionIter: arr) {
auto obj = versionIter.toObject();
Modrinth::IndexedVersion file;
file.addonId = Json::requireString(obj,"mod_id") ;
file.addonId = Json::requireString(obj,"project_id") ;
file.fileId = Json::requireString(obj, "id");
file.date = Json::requireString(obj, "date_published");
auto versionArray = Json::requireArray(obj, "game_versions");

View File

@ -157,7 +157,7 @@ void ListModel::fetchMore(const QModelIndex& parent)
}
performPaginatedSearch();
}
const char* sorts[4]{"relevance","downloads","updated","newest"};
const char* sorts[5]{"relevance","downloads","follows","updated","newest"};
void ListModel::performPaginatedSearch()
{
@ -166,12 +166,12 @@ void ListModel::performPaginatedSearch()
bool hasFabric = !((MinecraftInstance *)((ModrinthPage *)parent())->m_instance)->getPackProfile()->getComponentVersion("net.fabricmc.fabric-loader").isEmpty();
auto netJob = new NetJob("Modrinth::Search", APPLICATION->network());
auto searchUrl = QString(
"https://api.modrinth.com/api/v1/mod?"
"https://api.modrinth.com/v2/search?"
"offset=%1&"
"limit=25&"
"query=%2&"
"index=%3&"
"filters=categories=\"%4\" AND versions=\"%5\""
"facets=[[\"categories:%4\"],[\"versions:%5\"],[\"project_type:mod\"]]"
)
.arg(nextSearchOffset)
.arg(currentSearchTerm)

View File

@ -27,6 +27,7 @@ ModrinthPage::ModrinthPage(ModDownloadDialog *dialog, BaseInstance *instance)
// index is used to set the sorting with the modrinth api
ui->sortByBox->addItem(tr("Sort by Relevence"));
ui->sortByBox->addItem(tr("Sort by Downloads"));
ui->sortByBox->addItem(tr("Sort by Follows"));
ui->sortByBox->addItem(tr("Sort by last updated"));
ui->sortByBox->addItem(tr("Sort by newest"));
@ -99,8 +100,7 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second)
auto netJob = new NetJob(QString("Modrinth::ModVersions(%1)").arg(current.name), APPLICATION->network());
std::shared_ptr<QByteArray> response = std::make_shared<QByteArray>();
QString addonId = current.addonId;
addonId.remove(0,6);
netJob->addNetAction(Net::Download::makeByteArray(QString("https://api.modrinth.com/api/v1/mod/%1/version").arg(addonId), response.get()));
netJob->addNetAction(Net::Download::makeByteArray(QString("https://api.modrinth.com/v2/project/%1/version").arg(addonId), response.get()));
QObject::connect(netJob, &NetJob::succeeded, this, [this, response, netJob]
{