From cbbae78f3855761800db95c67179b3e349984e4d Mon Sep 17 00:00:00 2001 From: Lncvrt Date: Sat, 4 Oct 2025 13:23:41 -0700 Subject: [PATCH] Add launcher categories --- database.sql | 71 ++++++++++++++++++++++++++++++++-- database/launcher/versions.php | 16 +++++++- 2 files changed, 82 insertions(+), 5 deletions(-) diff --git a/database.sql b/database.sql index a29d8fa..e4f32a3 100644 --- a/database.sql +++ b/database.sql @@ -3,7 +3,7 @@ -- https://www.phpmyadmin.net/ -- -- Host: 127.0.0.1:3306 --- Generation Time: Sep 12, 2025 at 07:45 PM +-- Generation Time: Oct 04, 2025 at 10:18 PM -- Server version: 11.8.3-MariaDB-ubu2404 -- PHP Version: 8.1.33 @@ -51,6 +51,17 @@ CREATE TABLE `chats` ( -- -------------------------------------------------------- +-- +-- Table structure for table `launchercategories` +-- + +CREATE TABLE `launchercategories` ( + `id` int(11) NOT NULL, + `name` text NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; + +-- -------------------------------------------------------- + -- -- Table structure for table `launcherversions` -- @@ -63,7 +74,8 @@ CREATE TABLE `launcherversions` ( `downloadUrls` text NOT NULL, `platforms` text NOT NULL, `executables` text NOT NULL, - `hidden` tinyint(1) NOT NULL DEFAULT 1 + `hidden` tinyint(1) NOT NULL DEFAULT 1, + `category` int(11) NOT NULL DEFAULT 0 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=COMPRESSED; -- -------------------------------------------------------- @@ -86,6 +98,21 @@ CREATE TABLE `marketplaceicons` ( -- -------------------------------------------------------- +-- +-- Table structure for table `presets` +-- + +CREATE TABLE `presets` ( + `id` int(11) NOT NULL, + `uuid` text DEFAULT NULL, + `userId` int(11) NOT NULL, + `data` longtext NOT NULL, + `timestamp` bigint(20) NOT NULL, + `name` text NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=COMPRESSED; + +-- -------------------------------------------------------- + -- -- Table structure for table `userposts` -- @@ -139,11 +166,18 @@ ALTER TABLE `chats` ADD PRIMARY KEY (`id`), ADD KEY `fk_userId` (`userId`); +-- +-- Indexes for table `launchercategories` +-- +ALTER TABLE `launchercategories` + ADD PRIMARY KEY (`id`); + -- -- Indexes for table `launcherversions` -- ALTER TABLE `launcherversions` - ADD PRIMARY KEY (`id`); + ADD PRIMARY KEY (`id`), + ADD KEY `fk_category` (`category`); -- -- Indexes for table `marketplaceicons` @@ -152,6 +186,13 @@ ALTER TABLE `marketplaceicons` ADD PRIMARY KEY (`id`), ADD KEY `fk_userId` (`userId`); +-- +-- Indexes for table `presets` +-- +ALTER TABLE `presets` + ADD PRIMARY KEY (`id`), + ADD KEY `fk_userId` (`userId`); + -- -- Indexes for table `userposts` -- @@ -181,6 +222,12 @@ ALTER TABLE `chatroom_reports` ALTER TABLE `chats` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT; +-- +-- AUTO_INCREMENT for table `launchercategories` +-- +ALTER TABLE `launchercategories` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT; + -- -- AUTO_INCREMENT for table `launcherversions` -- @@ -193,6 +240,12 @@ ALTER TABLE `launcherversions` ALTER TABLE `marketplaceicons` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT; +-- +-- AUTO_INCREMENT for table `presets` +-- +ALTER TABLE `presets` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT; + -- -- AUTO_INCREMENT for table `userposts` -- @@ -222,12 +275,24 @@ ALTER TABLE `chatroom_reports` ALTER TABLE `chats` ADD CONSTRAINT `fk_userId` FOREIGN KEY (`userId`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE; +-- +-- Constraints for table `launcherversions` +-- +ALTER TABLE `launcherversions` + ADD CONSTRAINT `fk_category` FOREIGN KEY (`category`) REFERENCES `launchercategories` (`id`) ON DELETE CASCADE ON UPDATE CASCADE; + -- -- Constraints for table `marketplaceicons` -- ALTER TABLE `marketplaceicons` ADD CONSTRAINT `fk_marketplaceicons_userId` FOREIGN KEY (`userId`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE; +-- +-- Constraints for table `presets` +-- +ALTER TABLE `presets` + ADD CONSTRAINT `fk_presets_userId` FOREIGN KEY (`userId`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE; + -- -- Constraints for table `userposts` -- diff --git a/database/launcher/versions.php b/database/launcher/versions.php index a3407af..68af966 100755 --- a/database/launcher/versions.php +++ b/database/launcher/versions.php @@ -6,8 +6,20 @@ $conn = newConnection(); $stmt = $conn->prepare("SELECT * FROM launcherversions WHERE hidden = 0 ORDER BY id DESC"); $stmt->execute(); -$result = $stmt->get_result(); +$result_versions = $stmt->get_result(); +$versions = array_map(fn($row) => ['id' => $row['id'], 'version' => $row['version'], 'releaseDate' => $row['releaseDate'], 'displayName' => empty($row['displayName']) ? $row['version'] : $row['displayName'], 'platforms' => json_decode($row['platforms']), 'downloadUrls' => json_decode($row['downloadUrls']), 'executables' => json_decode($row['executables'])], $result_versions->fetch_all(MYSQLI_ASSOC)); -echo json_encode(array_map(fn($row) => ['id' => $row['id'], 'version' => $row['version'], 'releaseDate' => $row['releaseDate'], 'displayName' => empty($row['displayName']) ? $row['version'] : $row['displayName'], 'platforms' => json_decode($row['platforms']), 'downloadUrls' => json_decode($row['downloadUrls']), 'executables' => json_decode($row['executables'])], $result->fetch_all(MYSQLI_ASSOC))); +$stmt = $conn->prepare("SELECT * FROM launchercategories ORDER BY id DESC"); +$stmt->execute(); + +$result_categories = $stmt->get_result(); +$rows = $result_categories->fetch_all(MYSQLI_ASSOC); + +$categories = []; +foreach ($rows as $row) { + $categories[$row['id']] = $row['name']; +} + +echo json_encode(["version" => $versions, "categories" => $categories]); $conn->close(); \ No newline at end of file