aboutsummaryrefslogtreecommitdiff
path: root/src/index.ts
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-05-17 17:43:30 +0000
committermat <github@matdoes.dev>2022-05-17 17:43:30 +0000
commit5101e436bd2acfb6efdffe5c8c723511ab735153 (patch)
tree014d8a95693017e1e89cb254a45896422a650bbb /src/index.ts
parented72217fd73eca1de929f915056e13be9d4085f9 (diff)
downloadskyblock-api-5101e436bd2acfb6efdffe5c8c723511ab735153.tar.gz
skyblock-api-5101e436bd2acfb6efdffe5c8c723511ab735153.tar.bz2
skyblock-api-5101e436bd2acfb6efdffe5c8c723511ab735153.zip
improve auctions api
Diffstat (limited to 'src/index.ts')
-rw-r--r--src/index.ts34
1 files changed, 28 insertions, 6 deletions
diff --git a/src/index.ts b/src/index.ts
index 59e7761..1dcb523 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,5 +1,5 @@
-import { createSession, fetchAccountFromDiscord, fetchAllLeaderboardsCategorized, fetchLeaderboard, fetchMemberLeaderboardSpots, fetchSession, finishedCachingRawLeaderboards, leaderboardUpdateMemberQueue, leaderboardUpdateProfileQueue, updateAccount, deleteSession, fetchPaginatedItemsAuctions } from './database.js'
-import { fetchElection, fetchItemList, fetchMemberProfile, fetchUser } from './hypixel.js'
+import { createSession, fetchAccountFromDiscord, fetchAllLeaderboardsCategorized, fetchLeaderboard, fetchMemberLeaderboardSpots, fetchSession, finishedCachingRawLeaderboards, leaderboardUpdateMemberQueue, leaderboardUpdateProfileQueue, updateAccount, deleteSession, fetchPaginatedItemsAuctions, fetchItemsAuctions } from './database.js'
+import { fetchAuctionUncached, fetchElection, fetchItemList, fetchMemberProfile, fetchUser } from './hypixel.js'
import rateLimit from 'express-rate-limit'
import * as constants from './constants.js'
import * as discord from './discord.js'
@@ -155,9 +155,11 @@ app.get('/election', async (req, res) => {
app.get('/items', async (req, res) => {
try {
- res.json(
- await fetchItemList()
- )
+ res
+ .setHeader('Cache-Control', 'public, max-age=600')
+ .json(
+ await fetchItemList()
+ )
} catch (err) {
console.error(err)
res.json({ ok: false })
@@ -166,11 +168,17 @@ app.get('/items', async (req, res) => {
app.get('/auctionprices', async (req, res) => {
+ const itemIds = typeof req.query.items === 'string' ? req.query.items.split(',') : null
+ if (itemIds && itemIds.length > 100)
+ return res.json({
+ ok: false,
+ error: 'More than 100 items in the items query parameter.'
+ })
try {
res
.setHeader('Cache-Control', 'public, max-age=600')
.json(
- await fetchPaginatedItemsAuctions(0, 100)
+ itemIds ? await fetchItemsAuctions(itemIds) : await fetchPaginatedItemsAuctions(0, 100)
)
} catch (err) {
console.error(err)
@@ -178,6 +186,20 @@ app.get('/auctionprices', async (req, res) => {
}
})
+app.get('/auction/:uuid', async (req, res) => {
+ console.log('fetching auction', req.params.uuid)
+ const auction = await fetchAuctionUncached(req.params.uuid)
+ console.log('fetched auction', req.params.uuid)
+ try {
+ res
+ // .setHeader('Cache-Control', 'public, max-age=600')
+ .json(auction)
+ } catch (err) {
+ console.error(err)
+ res.json({ ok: false })
+ }
+})
+
app.post('/accounts/createsession', async (req, res) => {
try {
const { code } = req.body