diff options
-rw-r--r-- | src/cleaners/skyblock/stats.ts | 2 | ||||
-rw-r--r-- | src/hypixel.ts | 8 | ||||
-rw-r--r-- | src/hypixelApi.ts | 5 | ||||
-rw-r--r-- | src/hypixelCached.ts | 9 | ||||
-rw-r--r-- | src/index.ts | 10 | ||||
-rw-r--r-- | src/mojang.ts | 4 | ||||
-rw-r--r-- | src/util.ts | 4 |
7 files changed, 29 insertions, 13 deletions
diff --git a/src/cleaners/skyblock/stats.ts b/src/cleaners/skyblock/stats.ts index 07d9133..c4ff545 100644 --- a/src/cleaners/skyblock/stats.ts +++ b/src/cleaners/skyblock/stats.ts @@ -61,7 +61,7 @@ export interface CleanProfileStats { } } -export function cleanProfileStats(statsRaw): CleanProfileStats { +export function cleanProfileStats(statsRaw: any): CleanProfileStats { // TODO: add type for statsRaw (probably in hypixelApi.ts since its coming from there) const stats: CleanProfileStats = {} for (let statNameRaw in statsRaw) { diff --git a/src/hypixel.ts b/src/hypixel.ts index 105e627..0d3e9ea 100644 --- a/src/hypixel.ts +++ b/src/hypixel.ts @@ -1,7 +1,9 @@ -import { CleanMinion, cleanMinions, combineMinionArrays } from './cleaners/skyblock/minions' -import { CleanProfileStats, cleanProfileStats } from './cleaners/skyblock/stats' +/** + * Fetch the clean Hypixel API + */ + import { CleanPlayer, cleanPlayerResponse } from './cleaners/player' -import { chooseApiKey, HypixelPlayerStatsSkyBlockProfiles, HypixelResponse, sendApiRequest } from './hypixelApi' +import { chooseApiKey, HypixelResponse, sendApiRequest } from './hypixelApi' import * as cached from './hypixelCached' import { CleanMemberProfile } from './cleaners/skyblock/member' import { cleanSkyblockProfileResponse, CleanProfile, CleanBasicProfile } from './cleaners/skyblock/profile' diff --git a/src/hypixelApi.ts b/src/hypixelApi.ts index e91d4f5..cb8f0e0 100644 --- a/src/hypixelApi.ts +++ b/src/hypixelApi.ts @@ -1,3 +1,6 @@ +/** + * Fetch the raw Hypixel API + */ import fetch from 'node-fetch' import { jsonToQuery, shuffle } from './util' import { Agent } from 'https' @@ -10,7 +13,7 @@ const httpsAgent = new Agent({ /* Lower level code related to the Hypixel api */ -const apiKeys = process.env.keys.split(' ') +const apiKeys = process.env.hypixel_keys.split(' ') interface KeyUsage { remaining: number diff --git a/src/hypixelCached.ts b/src/hypixelCached.ts index 7f0305e..74b1366 100644 --- a/src/hypixelCached.ts +++ b/src/hypixelCached.ts @@ -1,3 +1,7 @@ +/** + * Fetch the clean and cached Hypixel API + */ + import NodeCache from 'node-cache' import * as mojang from './mojang' import * as hypixel from './hypixel' @@ -5,11 +9,6 @@ import { CleanPlayer } from './cleaners/player' import { undashUuid } from './util' import { CleanProfile, CleanFullProfile, CleanBasicProfile } from './cleaners/skyblock/profile' -/** -Hypixel... but with caching -All the caching in this project is done here! -*/ - // cache usernames for 4 hours const usernameCache = new NodeCache({ diff --git a/src/index.ts b/src/index.ts index af5095b..4ceda01 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,9 +1,15 @@ import express from 'express' import { fetchMemberProfile, fetchUser } from './hypixel' -import { fetchProfile } from './hypixelCached' const app = express() +app.use((req, res, next) => { + if (process.env.key && req.headers.key !== process.env.key) + // if a key is set in process.env and the header doesn't match return an error + // TODO: make this have a status code + return res.json({ error: 'Key in header must match key in env' }) + next() +}) app.get('/', async(req, res) => { res.json({ ok: true }) @@ -24,4 +30,4 @@ app.get('/player/:user/:profile', async(req, res) => { ) }) -app.listen(8080, () => console.log('App started :)'))
\ No newline at end of file +app.listen(8080, () => console.log('App started :)')) diff --git a/src/mojang.ts b/src/mojang.ts index 746f674..4de7717 100644 --- a/src/mojang.ts +++ b/src/mojang.ts @@ -1,3 +1,7 @@ +/** + * Fetch the Mojang username API through api.ashcon.app + */ + import fetch from 'node-fetch' import { Agent } from 'https' diff --git a/src/util.ts b/src/util.ts index 80067ff..e9fa145 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,4 +1,6 @@ -/* Utility functions (not related to Hypixel) */ +/** + * Random utility functions that are not related to Hypixel + */ export function undashUuid(uuid: string): string { return uuid.replace(/-/g, '') |