Skip to content

Instantly share code, notes, and snippets.

@DEVTomatoCake
Created March 28, 2023 17:00
Show Gist options
  • Save DEVTomatoCake/f1611ea19e0eb027159b6498c9597f2c to your computer and use it in GitHub Desktop.
Save DEVTomatoCake/f1611ea19e0eb027159b6498c9597f2c to your computer and use it in GitHub Desktop.
(Bad) script to quickly find outdated Minecraft mods in your mod folder from Modrinth
const fs = require("fs")
const crypto = require("crypto")
const mods = fs.readdirSync(process.env.APPDATA + "\\.minecraft\\mods")
const projects = []
const found = {}
let i = 0
mods.forEach(async mod => {
const hash = crypto.createHash("sha1")
hash.update(fs.readFileSync(process.env.APPDATA + "\\.minecraft\\mods\\" + mod))
const hashHex = hash.digest("hex")
const res = await fetch("https://api.modrinth.com/v2/version_file/" + hashHex + "?algorithm=sha1", {
headers: {
"User-Agent": "TomatoCake Modrinth-Update-Checker"
}
})
i++
if (res.status == 404) return console.log("Mod " + mod + " (" + hashHex + ") ist nicht auf Modrinth")
if (!res.ok) return console.log(res.status, await res.text())
const json = await res.json()
found[json.project_id] = {
hash: hashHex,
mod
}
projects.push(json.project_id)
if (mods.length == i) {
const projectsres = await fetch("https://api.modrinth.com/v2/projects?ids=" + JSON.stringify(projects), {
headers: {
"User-Agent": "TomatoCake Modrinth-Update-Checker"
}
})
const projectsjson = await projectsres.json()
const versions = []
projectsjson.forEach(project => {
project.versions.slice(project.versions.length - 3).forEach(version => versions.push(version))
})
const versionsres = await fetch("https://api.modrinth.com/v2/versions?ids=" + JSON.stringify(versions), {
headers: {
"User-Agent": "TomatoCake Modrinth-Update-Checker"
}
})
const versionsjson = await versionsres.json()
const filtered = versionsjson
.filter(version => version.loaders.includes("fabric") && version.game_versions.includes("1.19.4") && version.files.find(f => f.filename.endsWith(".jar")).hashes.sha1 != found[version.project_id].hash)
const unique = [...new Map(filtered.map(item => [item.project_id, item])).values()]
unique.forEach(version => {
console.log(
"Version für " + found[version.project_id].mod + " (" + projectsjson.find(pro => pro.id == version.project_id).title + ") gefunden: " +
version.files.find(f => f.filename.endsWith(".jar")).filename + " " + version.files.find(f => f.filename.endsWith(".jar")).url
)
})
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment