Skip to content

Commit

Permalink
api/index.php: provide endpoint to get list of mods
Browse files Browse the repository at this point in the history
  • Loading branch information
cowpod committed Nov 13, 2024
1 parent aa6462a commit e86c04d
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,49 @@
}
}
}
if (preg_match("/api\/mod$/", $url)) {
$modslist=[];
$modq = $db->query("SELECT * FROM mods");
if ($modq) {
foreach ($modq as $mod) {
$filesize = isset($mod['filesize']) ? $mod['filesize'] : 0;
$modentry = [
'pretty_name'=>$mod['pretty_name'],
'name'=>$mod['name'],
'version'=>$mod['version'],
'mcversion'=>$mod['mcversion'],
'md5'=>$mod['md5'],
'url'=>$mod['url'],
'filesize'=>$filesize
];

if (preg_match("/api\/modpack$/", $url)) { // modpacks
array_push($modslist,$modentry);
}
}
echo json_encode($modslist, JSON_UNESCAPED_SLASHES);
}
else if (preg_match("/api\/mod\/([\w\-\.]+)$/", $url, $matches)) {
$modslist=[];
$modq = $db->query("SELECT * FROM mods WHERE name='{$matches[1]}'");
if ($modq) {
foreach ($modq as $mod) {
$filesize = isset($mod['filesize']) ? $mod['filesize'] : 0;
$modentry = [
'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\/modpack$/", $url)) { // modpacks
// $modpacksq = $db->query("SELECT * FROM `modpacks`");
$modpacksq = $db->query("
SELECT M.*,
Expand Down

0 comments on commit e86c04d

Please sign in to comment.