diff options
author | mat <github@matdoes.dev> | 2022-07-02 16:12:23 -0500 |
---|---|---|
committer | mat <github@matdoes.dev> | 2022-07-02 16:12:23 -0500 |
commit | 4c0649fcf401bf291377a6ab42541b4b567922de (patch) | |
tree | ff43fe9df5d2da554e197791c259fd758fcb2caa | |
parent | f6504b6d78547052f5686409724ded181e3d1ded (diff) | |
download | skyblock-api-4c0649fcf401bf291377a6ab42541b4b567922de.tar.gz skyblock-api-4c0649fcf401bf291377a6ab42541b4b567922de.tar.bz2 skyblock-api-4c0649fcf401bf291377a6ab42541b4b567922de.zip |
don't transfer lore
-rw-r--r-- | src/database.ts | 41 | ||||
-rw-r--r-- | src/hypixel.ts | 2 | ||||
-rw-r--r-- | src/index.ts | 2 |
3 files changed, 39 insertions, 6 deletions
diff --git a/src/database.ts b/src/database.ts index d513256..66edeff 100644 --- a/src/database.ts +++ b/src/database.ts @@ -144,12 +144,31 @@ export interface SimpleAuctionSchema { /** The lore of the item. */ lore: string } +/** Same as SimpleAuctionSchema except without lore. */ +export interface SimplerAuctionSchema { + coins: number + /** + * The timestamp as **seconds** since epoch. It's in seconds instead of ms + * since we don't need to be super exact and so it's shorter. + */ + ts: number + /** Whether the auction was successfully bought or simply expired. */ + s: boolean + bin: boolean +} + export interface ItemAuctionsSchema { /** The id of the item */ id: string sbId: string auctions: SimpleAuctionSchema[] } +export interface SimplerItemAuctionsSchema { + /** The id of the item */ + id: string + sbId: string + auctions: SimplerAuctionSchema[] +} export interface ItemAuctionsSchemaBson { /** The id of the item */ _id: string @@ -1129,6 +1148,17 @@ function toItemAuctionsSchema(i: ItemAuctionsSchemaBson): ItemAuctionsSchema { }), } } +function toSimplerItemAuctionsSchema(i: ItemAuctionsSchema): SimplerItemAuctionsSchema { + return { + id: i.id, + sbId: i.sbId, + auctions: i.auctions.map((a: any) => { + if ('lore' in a) + delete a.lore + return a + }), + } +} function toItemAuctionsSchemaBson(i: ItemAuctionsSchema): ItemAuctionsSchemaBson { return { @@ -1148,18 +1178,21 @@ function toItemAuctionsSchemaBson(i: ItemAuctionsSchema): ItemAuctionsSchemaBson } /** Fetch all the Item Auctions for the item ids in the given array. */ -export async function fetchItemsAuctions(itemIds: string[]): Promise<ItemAuctionsSchema[]> { +export async function fetchItemsAuctions<Lore extends boolean = false>(itemIds: string[], lore: Lore): Promise<(Lore extends true ? ItemAuctionsSchema : SimplerItemAuctionsSchema)[]> { const auctions = await itemAuctionsCollection?.find({ _id: { $in: itemIds } }).sort('oldestDate', -1).toArray() - return auctions.map(toItemAuctionsSchema) + let a = auctions.map(toItemAuctionsSchema) + if (!lore) + return a.map(toSimplerItemAuctionsSchema) as any + return a } /** Fetch all the Item Auctions for the item ids in the given array. */ -export async function fetchPaginatedItemsAuctions(skip: number, limit: number): Promise<ItemAuctionsSchema[]> { +export async function fetchPaginatedItemsAuctions(skip: number, limit: number): Promise<SimplerItemAuctionsSchema[]> { const auctions = await itemAuctionsCollection?.find({}).sort('oldestDate', -1).skip(skip).limit(limit).toArray() - return auctions.map(toItemAuctionsSchema) + return auctions.map(toItemAuctionsSchema).map(toSimplerItemAuctionsSchema) } export async function updateItemAuction(auction: ItemAuctionsSchema) { diff --git a/src/hypixel.ts b/src/hypixel.ts index 42a219d..4b26d53 100644 --- a/src/hypixel.ts +++ b/src/hypixel.ts @@ -380,7 +380,7 @@ export async function periodicallyFetchRecentlyEndedAuctions() { } let updatedDatabaseAuctionItems: Map<string, ItemAuctionsSchema> = new Map() - const itemsAuctions = await fetchItemsAuctions(Array.from(newAuctionItemIds)) + const itemsAuctions = await fetchItemsAuctions(Array.from(newAuctionItemIds), true) for (const itemAuctions of itemsAuctions) { updatedDatabaseAuctionItems.set(itemAuctions.id, itemAuctions) } diff --git a/src/index.ts b/src/index.ts index 857fd88..9a14d0b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -176,7 +176,7 @@ app.get('/auctionprices', async (req, res) => { try { res .json( - itemIds ? await fetchItemsAuctions(itemIds) : await fetchPaginatedItemsAuctions(0, 100) + itemIds ? await fetchItemsAuctions(itemIds, false) : await fetchPaginatedItemsAuctions(0, 100) ) } catch (err) { console.error(err) |