Merge pull request #661 from flowln/wow_curseforge_is_being_uncompetitive_im_so_surprised
This commit is contained in:
		@@ -585,6 +585,7 @@ void InstanceImportTask::processMultiMC()
 | 
			
		||||
void InstanceImportTask::processModrinth()
 | 
			
		||||
{
 | 
			
		||||
    std::vector<Modrinth::File> files;
 | 
			
		||||
    std::vector<Modrinth::File> non_whitelisted_files;
 | 
			
		||||
    QString minecraftVersion, fabricVersion, quiltVersion, forgeVersion;
 | 
			
		||||
    try {
 | 
			
		||||
        QString indexPath = FS::PathCombine(m_stagingPath, "modrinth.index.json");
 | 
			
		||||
@@ -641,13 +642,38 @@ void InstanceImportTask::processModrinth()
 | 
			
		||||
                file.hashAlgorithm = hashAlgorithm;
 | 
			
		||||
                // Do not use requireUrl, which uses StrictMode, instead use QUrl's default TolerantMode
 | 
			
		||||
                // (as Modrinth seems to incorrectly handle spaces)
 | 
			
		||||
 | 
			
		||||
                file.download = Json::requireString(Json::ensureArray(modInfo, "downloads").first(), "Download URL for " + file.path);
 | 
			
		||||
                if (!file.download.isValid() || !Modrinth::validateDownloadUrl(file.download)) {
 | 
			
		||||
                    throw JSONValidationError("Download URL for " + file.path + " is not a correctly formatted URL");
 | 
			
		||||
 | 
			
		||||
                if (!file.download.isValid()) {
 | 
			
		||||
                    qDebug() << QString("Download URL (%1) for %2 is not a correctly formatted URL").arg(file.download.toString(), file.path);
 | 
			
		||||
                    throw JSONValidationError(tr("Download URL for %1 is not a correctly formatted URL").arg(file.path));
 | 
			
		||||
                }
 | 
			
		||||
                else if (!Modrinth::validateDownloadUrl(file.download)) {
 | 
			
		||||
                    qDebug() << QString("Download URL (%1) for %2 is from a non-whitelisted by Modrinth domain").arg(file.download.toString(), file.path);
 | 
			
		||||
                    non_whitelisted_files.push_back(file);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                files.push_back(file);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (!non_whitelisted_files.empty()) {
 | 
			
		||||
                QString text;
 | 
			
		||||
                for (const auto& file : non_whitelisted_files) {
 | 
			
		||||
                    text += tr("Filepath: %1<br>URL: <a href='%2'>%2</a><br>").arg(file.path, file.download.toString());
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                auto message_dialog = new ScrollMessageBox(m_parent, tr("Non-whitelisted mods found"),
 | 
			
		||||
                                                           tr("The following mods have URLs that are not whitelisted by Modrinth.\n"
 | 
			
		||||
                                                              "Proceed with caution!"),
 | 
			
		||||
                                                           text);
 | 
			
		||||
                message_dialog->setModal(true);
 | 
			
		||||
                if (message_dialog->exec() == QDialog::Rejected) {
 | 
			
		||||
                    emitFailed("Aborted");
 | 
			
		||||
                    return;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            auto dependencies = Json::requireObject(obj, "dependencies", "modrinth.index.json");
 | 
			
		||||
            for (auto it = dependencies.begin(), end = dependencies.end(); it != end; ++it) {
 | 
			
		||||
                QString name = it.key();
 | 
			
		||||
 
 | 
			
		||||
@@ -42,6 +42,8 @@
 | 
			
		||||
#include "minecraft/MinecraftInstance.h"
 | 
			
		||||
#include "minecraft/PackProfile.h"
 | 
			
		||||
 | 
			
		||||
#include <QSet>
 | 
			
		||||
 | 
			
		||||
static ModrinthAPI api;
 | 
			
		||||
 | 
			
		||||
namespace Modrinth {
 | 
			
		||||
@@ -95,19 +97,15 @@ void loadIndexedVersions(Modpack& pack, QJsonDocument& doc)
 | 
			
		||||
 | 
			
		||||
auto validateDownloadUrl(QUrl url) -> bool
 | 
			
		||||
{
 | 
			
		||||
    auto domain = url.host();
 | 
			
		||||
    if(domain == "cdn.modrinth.com")
 | 
			
		||||
        return true;
 | 
			
		||||
    if(domain == "edge.forgecdn.net")
 | 
			
		||||
        return true;
 | 
			
		||||
    if(domain == "media.forgecdn.net")
 | 
			
		||||
        return true;
 | 
			
		||||
    if(domain == "github.com")
 | 
			
		||||
        return true;
 | 
			
		||||
    if(domain == "raw.githubusercontent.com")
 | 
			
		||||
        return true;
 | 
			
		||||
    static QSet<QString> domainWhitelist{
 | 
			
		||||
        "cdn.modrinth.com",
 | 
			
		||||
        "github.com",
 | 
			
		||||
        "raw.githubusercontent.com",
 | 
			
		||||
        "gitlab.com"
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    return false;
 | 
			
		||||
    auto domain = url.host();
 | 
			
		||||
    return domainWhitelist.contains(domain);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
auto loadIndexedVersion(QJsonObject &obj) -> ModpackVersion
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user