Merge pull request #2753 from TheKodeToad/modrinth-hashes-parse-fix

This commit is contained in:
timoreo 2024-08-25 13:34:54 +02:00 committed by GitHub
commit 70a0a71f10
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -346,23 +346,8 @@ bool ModrinthCreationTask::parseManifest(const QString& index_path,
} }
QJsonObject hashes = Json::requireObject(modInfo, "hashes"); QJsonObject hashes = Json::requireObject(modInfo, "hashes");
QString hash; file.hash = QByteArray::fromHex(Json::requireString(hashes, "sha512").toLatin1());
QCryptographicHash::Algorithm hashAlgorithm; file.hashAlgorithm = QCryptographicHash::Sha512;
hash = Json::ensureString(hashes, "sha512");
hashAlgorithm = QCryptographicHash::Sha512;
if (hash.isEmpty()) {
hash = Json::ensureString(hashes, "sha256");
hashAlgorithm = QCryptographicHash::Sha256;
if (hash.isEmpty()) {
hash = Json::ensureString(hashes, "sha1");
hashAlgorithm = QCryptographicHash::Sha1;
if (hash.isEmpty()) {
throw JSONValidationError("No hash found for: " + file.path);
}
}
}
file.hash = QByteArray::fromHex(hash.toLatin1());
file.hashAlgorithm = hashAlgorithm;
// Do not use requireUrl, which uses StrictMode, instead use QUrl's default TolerantMode // Do not use requireUrl, which uses StrictMode, instead use QUrl's default TolerantMode
// (as Modrinth seems to incorrectly handle spaces) // (as Modrinth seems to incorrectly handle spaces)