diff options
Diffstat (limited to 'build/index.js')
-rw-r--r-- | build/index.js | 74 |
1 files changed, 24 insertions, 50 deletions
diff --git a/build/index.js b/build/index.js index 8bb2040..8521a1c 100644 --- a/build/index.js +++ b/build/index.js @@ -1,51 +1,25 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.debug = void 0; -const database_1 = require("./database"); -const hypixel_1 = require("./hypixel"); -const express_rate_limit_1 = __importDefault(require("express-rate-limit")); -const constants = __importStar(require("./constants")); -const discord = __importStar(require("./discord")); -const express_1 = __importDefault(require("express")); -const app = express_1.default(); -exports.debug = false; +import { createSession, fetchAccountFromDiscord, fetchAllLeaderboardsCategorized, fetchLeaderboard, fetchMemberLeaderboardSpots, fetchSession, finishedCachingRawLeaderboards, leaderboardUpdateMemberQueue, leaderboardUpdateProfileQueue, updateAccount } from './database.js'; +import { fetchMemberProfile, fetchUser } from './hypixel.js'; +import rateLimit from 'express-rate-limit'; +import * as constants from './constants.js'; +import * as discord from './discord.js'; +import express from 'express'; +const app = express(); +export const debug = false; const mainSiteUrl = 'https://skyblock.matdoes.dev'; // 200 requests over 5 minutes -const limiter = express_rate_limit_1.default({ +const limiter = rateLimit({ windowMs: 60 * 1000 * 5, max: 200, skip: (req) => { return req.headers.key === process.env.key; }, keyGenerator: (req) => { - var _a; - return ((_a = req.headers['cf-connecting-ip']) !== null && _a !== void 0 ? _a : req.ip).toString(); + return (req.headers['cf-connecting-ip'] ?? req.ip).toString(); } }); app.use(limiter); -app.use(express_1.default.json()); +app.use(express.json()); app.use((req, res, next) => { res.setHeader('Access-Control-Allow-Origin', '*'); next(); @@ -56,15 +30,15 @@ app.get('/', async (req, res) => { res.json({ ok: true, uptimeHours: (currentTime - startTime) / 1000 / 60 / 60, - finishedCachingRawLeaderboards: database_1.finishedCachingRawLeaderboards, - leaderboardUpdateMemberQueueSize: database_1.leaderboardUpdateMemberQueue.size, - leaderboardUpdateProfileQueueSize: database_1.leaderboardUpdateProfileQueue.size, + finishedCachingRawLeaderboards, + leaderboardUpdateMemberQueueSize: leaderboardUpdateMemberQueue.size, + leaderboardUpdateProfileQueueSize: leaderboardUpdateProfileQueue.size, // key: getKeyUsage() }); }); app.get('/player/:user', async (req, res) => { try { - const user = await hypixel_1.fetchUser({ user: req.params.user }, [req.query.basic === 'true' ? undefined : 'profiles', 'player'], req.query.customization === 'true'); + const user = await fetchUser({ user: req.params.user }, [req.query.basic === 'true' ? undefined : 'profiles', 'player'], req.query.customization === 'true'); if (user) res.json(user); else @@ -77,7 +51,7 @@ app.get('/player/:user', async (req, res) => { }); app.get('/discord/:id', async (req, res) => { try { - res.json(await database_1.fetchAccountFromDiscord(req.params.id)); + res.json(await fetchAccountFromDiscord(req.params.id)); } catch (err) { console.error(err); @@ -86,7 +60,7 @@ app.get('/discord/:id', async (req, res) => { }); app.get('/player/:user/:profile', async (req, res) => { try { - const profile = await hypixel_1.fetchMemberProfile(req.params.user, req.params.profile, req.query.customization === 'true'); + const profile = await fetchMemberProfile(req.params.user, req.params.profile, req.query.customization === 'true'); if (profile) res.json(profile); else @@ -99,7 +73,7 @@ app.get('/player/:user/:profile', async (req, res) => { }); app.get('/player/:user/:profile/leaderboards', async (req, res) => { try { - res.json(await database_1.fetchMemberLeaderboardSpots(req.params.user, req.params.profile)); + res.json(await fetchMemberLeaderboardSpots(req.params.user, req.params.profile)); } catch (err) { console.error(err); @@ -108,7 +82,7 @@ app.get('/player/:user/:profile/leaderboards', async (req, res) => { }); app.get('/leaderboard/:name', async (req, res) => { try { - res.json(await database_1.fetchLeaderboard(req.params.name)); + res.json(await fetchLeaderboard(req.params.name)); } catch (err) { console.error(err); @@ -117,7 +91,7 @@ app.get('/leaderboard/:name', async (req, res) => { }); app.get('/leaderboards', async (req, res) => { try { - res.json(await database_1.fetchAllLeaderboardsCategorized()); + res.json(await fetchAllLeaderboardsCategorized()); } catch (err) { console.error(err); @@ -146,7 +120,7 @@ app.post('/accounts/createsession', async (req, res) => { // access token is invalid :( return res.json({ ok: false }); const userData = await discord.getUser(accessToken); - const sessionId = await database_1.createSession(refreshToken, userData); + const sessionId = await createSession(refreshToken, userData); res.json({ ok: true, session_id: sessionId }); } catch (err) { @@ -156,10 +130,10 @@ app.post('/accounts/createsession', async (req, res) => { app.post('/accounts/session', async (req, res) => { try { const { uuid } = req.body; - const session = await database_1.fetchSession(uuid); + const session = await fetchSession(uuid); if (!session) return res.json({ ok: false }); - const account = await database_1.fetchAccountFromDiscord(session.discord_user.id); + const account = await fetchAccountFromDiscord(session.discord_user.id); res.json({ session, account }); } catch (err) { @@ -172,7 +146,7 @@ app.post('/accounts/update', async (req, res) => { if (req.headers.key !== process.env.key) return console.log('bad key!'); try { - await database_1.updateAccount(req.body.discordId, req.body); + await updateAccount(req.body.discordId, req.body); res.json({ ok: true }); } catch (err) { |