Edit Modpack
+Modpack details
+
Copy Build
Mods
+Here, you can install mods from modrinth, or mods you've downloaded from somewhere else. +
Note you will need to install a mod loader before using a mod. +
From 66d76c8302cfec0e52178a7202d98e03d7e67113 Mon Sep 17 00:00:00 2001 From: Henry Gross-Hellsen <6283258+cowpod@users.noreply.github.com> Date: Fri, 15 Nov 2024 14:45:18 -0800 Subject: [PATCH] api/index.php/mod: filter in db instead of php, add /loader endpoint, index.php: new description/titles/labels, index.php/modloaders: dynamic/js ui, filter out beta neoforge, add filesize to loaders, loader filenames reflect the type --- api/index.php | 45 +- ...ge-fabric.php => add-modloader-fabric.php} | 33 +- functions/add-modloader.php | 21 +- index.php | 138 ++++-- resources/js/page_modloaders.js | 406 +++++++++++------- 5 files changed, 410 insertions(+), 233 deletions(-) rename functions/{package-fabric.php => add-modloader-fabric.php} (71%) diff --git a/api/index.php b/api/index.php index 5fe34d9..ba677c5 100644 --- a/api/index.php +++ b/api/index.php @@ -79,17 +79,52 @@ $mcversion=$_GET['mcversion']; } if (!empty($loadertype) && !empty($mcversion)) { - $modq = $db->query("SELECT * FROM mods WHERE loadertype='{$loadertype}' AND ('{$mcversion}' LIKE mcversion || '%' OR mcversion LIKE '{$mcversion}' || '%')"); + $modq = $db->query("SELECT * FROM mods WHERE type='mod' AND loadertype='{$loadertype}' AND ('{$mcversion}' LIKE mcversion || '%' OR mcversion LIKE '{$mcversion}' || '%')"); } elseif (!empty($loadertype)) { - $modq = $db->query("SELECT * FROM mods WHERE loadertype='{$loadertype}'"); + $modq = $db->query("SELECT * FROM mods WHERE type='mod' AND loadertype='{$loadertype}'"); } elseif (!empty($mcversion)) { - $modq = $db->query("SELECT * FROM mods WHERE '{$mcversion}' LIKE mcversion || '%'"); + $modq = $db->query("SELECT * FROM mods WHERE type='mod' AND '{$mcversion}' LIKE mcversion || '%'"); } else { - $modq = $db->query("SELECT * FROM mods"); + $modq = $db->query("SELECT * FROM mods WHERE type='mod'"); + } + if ($modq) { + foreach ($modq as $mod) { + $filesize = isset($mod['filesize']) ? $mod['filesize'] : 0; + $modentry = [ + 'id'=>$mod['id'], + 'pretty_name'=>$mod['pretty_name'], + 'name'=>$mod['name'], + 'version'=>$mod['version'], + 'mcversion'=>$mod['mcversion'], + 'md5'=>$mod['md5'], + 'url'=>$mod['url'], + 'filesize'=>$filesize + ]; + + array_push($modslist, $modentry); + } + } + echo json_encode($modslist, JSON_UNESCAPED_SLASHES); +} +else if (preg_match("/api\/loader$/", $url)) { + $modslist=[]; + if (!empty($_GET['loadertype']) && ctype_alnum($_GET['loadertype'])) { + $loadertype=$_GET['loadertype']; + } + if (!empty($_GET['mcversion']) && preg_match('/^[a-zA-Z0-9\-\.]+$/', $_GET['mcversion'])) { + $mcversion=$_GET['mcversion']; + } + if (!empty($loadertype) && !empty($mcversion)) { + $modq = $db->query("SELECT * FROM mods WHERE type='forge' AND loadertype='{$loadertype}' AND ('{$mcversion}' LIKE mcversion || '%' OR mcversion LIKE '{$mcversion}' || '%')"); + } elseif (!empty($loadertype)) { + $modq = $db->query("SELECT * FROM mods WHERE type='forge' AND loadertype='{$loadertype}'"); + } elseif (!empty($mcversion)) { + $modq = $db->query("SELECT * FROM mods WHERE type='forge' AND '{$mcversion}' LIKE mcversion || '%'"); + } else { + $modq = $db->query("SELECT * FROM mods WHERE type='forge'"); } if ($modq) { foreach ($modq as $mod) { - if ($mod['type']!='mod') continue; $filesize = isset($mod['filesize']) ? $mod['filesize'] : 0; $modentry = [ 'id'=>$mod['id'], diff --git a/functions/package-fabric.php b/functions/add-modloader-fabric.php similarity index 71% rename from functions/package-fabric.php rename to functions/add-modloader-fabric.php index 34d1cf2..3fbed09 100644 --- a/functions/package-fabric.php +++ b/functions/add-modloader-fabric.php @@ -18,8 +18,12 @@ exit(); } +global $db; require_once("db.php"); -$db=new Db; +if (!isset($db)){ + $db=new Db; + $db->connect(); +} if (file_put_contents("../forges/modpack-".$version."/version.json", file_get_contents("https://meta.fabricmc.net/v2/versions/loader/".$mcversion."/".urlencode($version)."/profile/json"))) { $zip = new ZipArchive(); @@ -36,21 +40,34 @@ unlink("../forges/modpack-".$version."/version.json"); rmdir("../forges/modpack-".$version); $md5 = md5_file("../forges/fabric-".$version.".zip"); + $file_size=filesize("../forges/fabric-".$version.".zip"); $url = "http://".$config['host'].$config['dir']."forges/fabric-".urlencode($version).".zip"; - - $db->connect(); - $res = $db->execute("INSERT INTO `mods` (`name`,`pretty_name`,`md5`,`url`,`link`,`author`,`description`,`version`,`mcversion`,`filename`,`type`,`loadertype`) VALUES ('fabric','Fabric (alpha)','".$md5."','".$url."','https://fabricmc.net/','FabricMC Team', 'Fabric is a lightweight, experimental modding toolchain for Minecraft.', '".$version."','".$mcversion."','fabric-".$version.".zip','forge', 'fabric')"); - $db->disconnect(); - + $res = $db->execute("INSERT INTO `mods` (`name`,`pretty_name`,`md5`,`url`,`link`,`author`,`description`,`version`,`mcversion`,`filename`,`filesize`,`type`,`loadertype`) VALUES ( + 'fabric', + 'Fabric (alpha)', + '{$md5}', + '{$url}', + 'https://fabricmc.net/', + 'FabricMC Team', + 'Fabric is a lightweight, experimental modding toolchain for Minecraft.', + '{$version}', + '{$mcversion}', + 'fabric-{$version}.zip', + '{$file_size}', + 'forge', + 'fabric' + )"); if ($res) { - echo '{"status":"succ","message":"Mod has been saved."}'; + echo '{"status":"succ","message":"Loader has been saved.", "id": '.$db->insert_id().'}'; } else { - echo '{"status":"error","message":"Mod could not be added to database"}'; + echo '{"status":"error","message":"Loader could not be added to database"}'; } + } else { echo '{"status":"error","message":"File download failed."}'; unlink("../forges/modpack-".$version."/version.json"); rmdir("../forges/modpack-".$version); } +$db->disconnect(); exit(); \ No newline at end of file diff --git a/functions/add-modloader.php b/functions/add-modloader.php index 466c0be..bb32c1b 100644 --- a/functions/add-modloader.php +++ b/functions/add-modloader.php @@ -48,7 +48,7 @@ if (file_put_contents("../forges/modpack-".$version."/modpack.jar", file_get_contents($download_link))) { $zip = new ZipArchive(); - if ($zip->open("../forges/forge-".$version.".zip", ZIPARCHIVE::CREATE) !== true) { + if ($zip->open("../forges/".$type."-".$version.".zip", ZIPARCHIVE::CREATE) !== true) { echo '{"status":"error","message":"Could not open archive"}'; exit(); } @@ -60,10 +60,9 @@ $zip->close(); unlink("../forges/modpack-".$version."/modpack.jar"); rmdir("../forges/modpack-".$version); - $md5 = md5_file("../forges/forge-".$version.".zip"); - $filesize=filesize("../forges/forge-".$version.".zip"); - $url = "http://".$config['host'].$config['dir']."forges/forge-".$version.".zip"; - + $md5 = md5_file("../forges/".$type."-".$version.".zip"); + $file_size = filesize("../forges/".$type."-".$version.".zip"); + $url = "http://".$config['host'].$config['dir']."forges/".$type."-".$version.".zip"; $res = $db->execute(" INSERT INTO `mods` (`name`,`pretty_name`,`md5`,`url`,`link`,`author`,`description`,`version`,`mcversion`,`filename`,`filesize`,`type`,`loadertype`) VALUES ( @@ -76,23 +75,21 @@ '".$type_descriptions[$type]."', '".$version."', '".$mcversion."', - 'forge-".$version.".zip', - ".$filesize.", + '".$type."-".$version.".zip', + ".$file_size.", 'forge', '".$type."' ) "); - $id=$db->insert_id(); - if ($res) { - echo '{"status":"succ","message":"Mod has been saved.", "id":"'.$id.'"}'; + echo '{"status":"succ","message":"Loader has been saved.", "id":"'.$db->insert_id().'"}'; } else { - echo '{"status":"error","message":"Mod could not be added to database"}'; + echo '{"status":"error","message":"Loader could not be added to database"}'; } } else { echo '{"status":"error","message":"File download failed."}'; unlink("../forges/modpack-".$version."/modpack.jar"); rmdir("../forges/modpack-".$version); } - +$db->disconnect(); exit(); \ No newline at end of file diff --git a/index.php b/index.php index a67584d..c00b257 100644 --- a/index.php +++ b/index.php @@ -792,6 +792,7 @@ function uri($uri) { $_GET['name'] = $modpack['name']; ?> +
+