mirror of
https://git.bits.team/Bits/mod-manager.git
synced 2025-06-30 17:19:43 -04:00
Added downloading mods from Modrinth
This commit is contained in:
44
src/util/minecraft_utils.ts
Normal file
44
src/util/minecraft_utils.ts
Normal file
@ -0,0 +1,44 @@
|
||||
import {readdirSync} from "fs";
|
||||
import path from "path";
|
||||
import axios from "axios";
|
||||
|
||||
export default class MinecraftUtils {
|
||||
static async getCurrentMinecraftVersion(): Promise<string> {
|
||||
// Get installed versions as strings
|
||||
const installedVersions: Array<string> = readdirSync(this.getVersionsFolderPath(), {withFileTypes: true})
|
||||
.filter(entry => entry.isDirectory())
|
||||
.map(entry => entry.name);
|
||||
|
||||
// Get a list of Minecraft Versions
|
||||
const response = await axios.get("https://meta.fabricmc.net/v2/versions/game");
|
||||
const data = await response.data;
|
||||
|
||||
const minecraftVersions: Array<string> = [];
|
||||
for (const ele of data) {
|
||||
minecraftVersions.push(ele.version);
|
||||
}
|
||||
|
||||
// Find the latest version that is currently installed
|
||||
let index = Number.MAX_VALUE;
|
||||
for (let version of installedVersions) {
|
||||
let currentIndex = minecraftVersions.indexOf(version);
|
||||
|
||||
// If this version, is newer than the previous newest, save it's index
|
||||
if (currentIndex < index) {
|
||||
index = currentIndex;
|
||||
}
|
||||
}
|
||||
|
||||
const latestVersion = minecraftVersions[index];
|
||||
if (latestVersion == undefined) {
|
||||
throw new Error("There are no Minecraft versions available in this server. Is this a valid server installation?");
|
||||
}
|
||||
|
||||
return latestVersion;
|
||||
}
|
||||
|
||||
static getVersionsFolderPath(): string {
|
||||
return path.join("versions")
|
||||
}
|
||||
}
|
||||
|
5
src/util/util.ts
Normal file
5
src/util/util.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export default class Util {
|
||||
static isArrayEmpty(array: Array<any> | undefined): boolean {
|
||||
return array === undefined || array.length == 0;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user