aboutsummaryrefslogtreecommitdiff
path: root/launcher/modplatform/modrinth/ModrinthAPI.h
blob: 44a362c852f310d47bad4fb028e86f6b59b7c842 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#pragma once

#include "modplatform/ModAPI.h"

#include <QDebug>

class ModrinthAPI : public ModAPI {
   public:
    inline QString getModSearchURL(int offset, QString query, QString sort, ModLoaderType modLoader, QString version) const override 
    { 
        if(!validateModLoader(modLoader)){
            qWarning() << "Modrinth only have Forge and Fabric-compatible mods!";
            return "";
        }

        return QString("https://api.modrinth.com/v2/search?"
                "offset=%1&"   "limit=25&"   "query=%2&"   "index=%3&"
                "facets=[[\"categories:%4\"],[\"versions:%5\"],[\"project_type:mod\"]]")
                  .arg(offset)
                  .arg(query)
                  .arg(sort)
                  .arg(getModLoaderString(modLoader))
                  .arg(version);
    };

    inline QString getVersionsURL(const QString& addonId) const override
    {
        return QString("https://api.modrinth.com/v2/project/%1/version").arg(addonId);
    };

    inline QString getAuthorURL(const QString& name) const override { return "https://modrinth.com/user/" + name; };

   private:
    inline bool validateModLoader(ModLoaderType modLoader) const{
        return modLoader == Any || modLoader == Forge || modLoader == Fabric;
    }

    inline QString getModLoaderString(ModLoaderType modLoader) const{
        switch(modLoader){
        case Any:
            return "fabric, forge";
        case Forge:
            return "forge";
        case Fabric:
            return "fabric";
        default:
            return "";
        }
    }
};