diff options
Diffstat (limited to 'build')
-rw-r--r-- | build/cleaners/skyblock/stats.js | 4 | ||||
-rw-r--r-- | build/database.js | 18 | ||||
-rw-r--r-- | build/index.js | 3 |
3 files changed, 23 insertions, 2 deletions
diff --git a/build/cleaners/skyblock/stats.js b/build/cleaners/skyblock/stats.js index 80686c1..09941a4 100644 --- a/build/cleaners/skyblock/stats.js +++ b/build/cleaners/skyblock/stats.js @@ -1,11 +1,12 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.cleanProfileStats = void 0; +exports.cleanProfileStats = exports.categorizeStat = void 0; const statCategories = { 'deaths': ['deaths_', 'deaths'], 'kills': ['kills_', 'kills'], 'fishing': ['items_fished_', 'items_fished'], 'auctions': ['auctions_'], + 'collection': ['collection_'], 'races': ['_best_time'], 'misc': null // everything else goes here }; @@ -52,6 +53,7 @@ function categorizeStat(statNameRaw) { name: statNameRaw }; } +exports.categorizeStat = categorizeStat; function cleanProfileStats(data) { var _a; // TODO: add type for statsRaw (probably in hypixelApi.ts since its coming from there) diff --git a/build/database.js b/build/database.js index 1edb990..a813a78 100644 --- a/build/database.js +++ b/build/database.js @@ -25,12 +25,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.updateDatabaseMember = exports.fetchMemberLeaderboard = void 0; +exports.updateDatabaseMember = exports.fetchMemberLeaderboard = exports.fetchAllMemberLeaderboardAttributes = exports.fetchAllLeaderboardsCategoriezed = void 0; const constants = __importStar(require("./constants")); const cached = __importStar(require("./hypixelCached")); const mongodb_1 = require("mongodb"); const node_cache_1 = __importDefault(require("node-cache")); const util_1 = require("./util"); +const stats_1 = require("./cleaners/skyblock/stats"); // don't update the user for 3 minutes const recentlyUpdated = new node_cache_1.default({ stdTTL: 60 * 3, @@ -73,6 +74,20 @@ function getMemberLeaderboardAttributes(member) { visited_zones: member.visited_zones.length, }; } +async function fetchAllLeaderboardsCategoriezed() { + const memberLeaderboardAttributes = await fetchAllMemberLeaderboardAttributes(); + const categorizedLeaderboards = []; + for (const leaderboard of memberLeaderboardAttributes) { + const { category, name } = stats_1.categorizeStat(leaderboard); + categorizedLeaderboards.push({ + category, + name, + id: leaderboard + }); + } + return categorizedLeaderboards; +} +exports.fetchAllLeaderboardsCategoriezed = fetchAllLeaderboardsCategoriezed; /** Fetch the names of all the leaderboards */ async function fetchAllMemberLeaderboardAttributes() { return [ @@ -86,6 +101,7 @@ async function fetchAllMemberLeaderboardAttributes() { 'visited_zones', ]; } +exports.fetchAllMemberLeaderboardAttributes = fetchAllMemberLeaderboardAttributes; async function fetchMemberLeaderboardRaw(name) { if (cachedRawLeaderboards.has(name)) return cachedRawLeaderboards.get(name); diff --git a/build/index.js b/build/index.js index 52e711c..0d8bd70 100644 --- a/build/index.js +++ b/build/index.js @@ -28,4 +28,7 @@ app.get('/player/:user/:profile', async (req, res) => { app.get('/leaderboard/:name', async (req, res) => { res.json(await database_1.fetchMemberLeaderboard(req.params.name)); }); +app.get('/leaderboards', async (req, res) => { + res.json(await database_1.fetchAllLeaderboardsCategoriezed()); +}); app.listen(8080, () => console.log('App started :)')); |